fix
This commit is contained in:
parent
b37d85bce8
commit
7330517568
|
@ -6,7 +6,6 @@ import Icon from 'react-native-vector-icons/MaterialIcons';
|
||||||
import Slider from 'react-native-slider';
|
import Slider from 'react-native-slider';
|
||||||
import Markdown from './Markdown';
|
import Markdown from './Markdown';
|
||||||
|
|
||||||
const SUPPORTED_TYPES = ['video/webm'];
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
audioContainer: {
|
audioContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
@ -51,6 +50,16 @@ const styles = StyleSheet.create({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const formatTime = (t = 0, duration = 0) => {
|
||||||
|
const time = Math.min(
|
||||||
|
Math.max(t, 0),
|
||||||
|
duration
|
||||||
|
);
|
||||||
|
const formattedMinutes = Math.floor(time / 60).toFixed(0).padStart(2, 0);
|
||||||
|
const formattedSeconds = Math.floor(time % 60).toFixed(0).padStart(2, 0);
|
||||||
|
return `${ formattedMinutes }:${ formattedSeconds }`;
|
||||||
|
};
|
||||||
|
|
||||||
export default class Audio extends React.PureComponent {
|
export default class Audio extends React.PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
file: PropTypes.object.isRequired,
|
file: PropTypes.object.isRequired,
|
||||||
|
@ -90,25 +99,11 @@ export default class Audio extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentTime() {
|
getCurrentTime() {
|
||||||
return this.formatTime(this.state.currentTime);
|
return formatTime(this.state.currentTime, this.state.duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDuration() {
|
getDuration() {
|
||||||
return this.formatTime(this.state.duration);
|
return formatTime(this.state.duration);
|
||||||
}
|
|
||||||
|
|
||||||
formatTime(time = 0) {
|
|
||||||
time = Math.min(
|
|
||||||
Math.max(time, 0),
|
|
||||||
this.state.duration
|
|
||||||
);
|
|
||||||
const formattedMinutes = Math.floor(time / 60).toFixed(0).padStart(2, 0);
|
|
||||||
const formattedSeconds = Math.floor(time % 60).toFixed(0).padStart(2, 0);
|
|
||||||
return `${ formattedMinutes }:${ formattedSeconds }`;
|
|
||||||
}
|
|
||||||
|
|
||||||
isTypeSupported() {
|
|
||||||
return SUPPORTED_TYPES.indexOf(this.props.file.audio_type) === -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
togglePlayPause() {
|
togglePlayPause() {
|
||||||
|
|
|
@ -40,17 +40,15 @@ const styles = StyleSheet.create({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const onPress = (url) => {
|
||||||
|
Linking.openURL(url);
|
||||||
|
};
|
||||||
const Url = ({ url }) => {
|
const Url = ({ url }) => {
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const onPress = () => {
|
|
||||||
Linking.openURL(url.url);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity onPress={() => onPress()} style={styles.button}>
|
<TouchableOpacity onPress={() => onPress(url.url)} style={styles.button}>
|
||||||
<View style={styles.quoteSign} />
|
<View style={styles.quoteSign} />
|
||||||
<Image
|
<Image
|
||||||
style={styles.image}
|
style={styles.image}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { View, StyleSheet, TouchableOpacity, Image, Linking } from 'react-native';
|
import { View, StyleSheet, TouchableOpacity, Image, Linking, Platform } from 'react-native';
|
||||||
import Modal from 'react-native-modal';
|
import Modal from 'react-native-modal';
|
||||||
import VideoPlayer from 'react-native-video-controls';
|
import VideoPlayer from 'react-native-video-controls';
|
||||||
import Markdown from './Markdown';
|
import Markdown from './Markdown';
|
||||||
|
|
||||||
const SUPPORTED_TYPES = ['video/webm'];
|
const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(Platform.OS === 'ios' ? [] : ['video/webm', 'video/3gp', 'video/mkv'])];
|
||||||
|
const isTypeSupported = type => SUPPORTED_TYPES.indexOf(type) !== -1;
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
@ -40,9 +42,6 @@ export default class Video extends React.PureComponent {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
isTypeSupported() {
|
|
||||||
return SUPPORTED_TYPES.indexOf(this.props.file.video_type) === -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleModal() {
|
toggleModal() {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -51,11 +50,10 @@ export default class Video extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
if (!this.isTypeSupported()) {
|
if (isTypeSupported(this.props.file.video_type)) {
|
||||||
Linking.openURL(this.state.uri);
|
return this.toggleModal();
|
||||||
} else {
|
|
||||||
this.toggleModal();
|
|
||||||
}
|
}
|
||||||
|
Linking.openURL(this.state.uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -66,14 +66,7 @@ const RocketChat = {
|
||||||
const server = { id: reduxStore.getState().server.server };
|
const server = { id: reduxStore.getState().server.server };
|
||||||
if (ddpMessage.collection === 'stream-room-messages') {
|
if (ddpMessage.collection === 'stream-room-messages') {
|
||||||
return realm.write(() => {
|
return realm.write(() => {
|
||||||
const message = ddpMessage.fields.args[0];
|
const message = this._buildMessage(ddpMessage.fields.args[0], server);
|
||||||
message.temp = false;
|
|
||||||
message._server = server;
|
|
||||||
message.attachments = message.attachments || [];
|
|
||||||
if (message.urls) {
|
|
||||||
message.urls = RocketChat._parseUrls(message.urls);
|
|
||||||
}
|
|
||||||
message.starred = message.starred && message.starred.length > 0;
|
|
||||||
realm.create('messages', message, true);
|
realm.create('messages', message, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -250,8 +243,7 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_parseUrls(urls) {
|
_parseUrls(urls) {
|
||||||
urls = urls.filter(url => url.meta && !url.ignoreParse);
|
return urls.filter(url => url.meta && !url.ignoreParse).map((url, index) => {
|
||||||
urls = urls.map((url, index) => {
|
|
||||||
const tmp = {};
|
const tmp = {};
|
||||||
const { meta } = url;
|
const { meta } = url;
|
||||||
tmp._id = index;
|
tmp._id = index;
|
||||||
|
@ -265,9 +257,18 @@ const RocketChat = {
|
||||||
tmp.url = url.url;
|
tmp.url = url.url;
|
||||||
return tmp;
|
return tmp;
|
||||||
});
|
});
|
||||||
return urls;
|
|
||||||
},
|
},
|
||||||
|
_buildMessage(message, server) {
|
||||||
|
server = server || reduxStore.getState().server.server;
|
||||||
|
message.temp = false;
|
||||||
|
message._server = { id: server };
|
||||||
|
message.attachments = message.attachments || [];
|
||||||
|
if (message.urls) {
|
||||||
|
message.urls = RocketChat._parseUrls(message.urls);
|
||||||
|
}
|
||||||
|
message.starred = !!message.starred;
|
||||||
|
return message;
|
||||||
|
},
|
||||||
loadMessagesForRoom(rid, end, cb) {
|
loadMessagesForRoom(rid, end, cb) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
Meteor.call('loadHistory', rid, end, 20, (err, data) => {
|
Meteor.call('loadHistory', rid, end, 20, (err, data) => {
|
||||||
|
@ -278,16 +279,10 @@ const RocketChat = {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
if (data && data.messages.length) {
|
if (data && data.messages.length) {
|
||||||
|
const { server } = reduxStore.getState().server;
|
||||||
|
const messages = data.messages.map(message => this._buildMessage(message, server));
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
data.messages.forEach((message) => {
|
messages.forEach((message) => {
|
||||||
message.temp = false;
|
|
||||||
message._server = { id: reduxStore.getState().server.server };
|
|
||||||
message.attachments = message.attachments || [];
|
|
||||||
if (message.urls) {
|
|
||||||
message.urls = RocketChat._parseUrls(message.urls);
|
|
||||||
}
|
|
||||||
// write('messages', message);
|
|
||||||
message.starred = !!message.starred;
|
|
||||||
realm.create('messages', message, true);
|
realm.create('messages', message, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue