This commit is contained in:
Guilherme Gazzo 2017-11-30 18:16:54 -02:00
parent b37d85bce8
commit 7330517568
4 changed files with 39 additions and 53 deletions

View File

@ -6,7 +6,6 @@ import Icon from 'react-native-vector-icons/MaterialIcons';
import Slider from 'react-native-slider';
import Markdown from './Markdown';
const SUPPORTED_TYPES = ['video/webm'];
const styles = StyleSheet.create({
audioContainer: {
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 {
static propTypes = {
file: PropTypes.object.isRequired,
@ -90,25 +99,11 @@ export default class Audio extends React.PureComponent {
}
getCurrentTime() {
return this.formatTime(this.state.currentTime);
return formatTime(this.state.currentTime, this.state.duration);
}
getDuration() {
return this.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;
return formatTime(this.state.duration);
}
togglePlayPause() {

View File

@ -40,17 +40,15 @@ const styles = StyleSheet.create({
}
});
const onPress = (url) => {
Linking.openURL(url);
};
const Url = ({ url }) => {
if (!url) {
return null;
}
const onPress = () => {
Linking.openURL(url.url);
};
return (
<TouchableOpacity onPress={() => onPress()} style={styles.button}>
<TouchableOpacity onPress={() => onPress(url.url)} style={styles.button}>
<View style={styles.quoteSign} />
<Image
style={styles.image}

View File

@ -1,11 +1,13 @@
import React from 'react';
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 VideoPlayer from 'react-native-video-controls';
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({
container: {
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() {
this.setState({
@ -51,11 +50,10 @@ export default class Video extends React.PureComponent {
}
open() {
if (!this.isTypeSupported()) {
Linking.openURL(this.state.uri);
} else {
this.toggleModal();
if (isTypeSupported(this.props.file.video_type)) {
return this.toggleModal();
}
Linking.openURL(this.state.uri);
}
render() {

View File

@ -66,14 +66,7 @@ const RocketChat = {
const server = { id: reduxStore.getState().server.server };
if (ddpMessage.collection === 'stream-room-messages') {
return realm.write(() => {
const message = ddpMessage.fields.args[0];
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;
const message = this._buildMessage(ddpMessage.fields.args[0], server);
realm.create('messages', message, true);
});
}
@ -250,8 +243,7 @@ const RocketChat = {
},
_parseUrls(urls) {
urls = urls.filter(url => url.meta && !url.ignoreParse);
urls = urls.map((url, index) => {
return urls.filter(url => url.meta && !url.ignoreParse).map((url, index) => {
const tmp = {};
const { meta } = url;
tmp._id = index;
@ -265,9 +257,18 @@ const RocketChat = {
tmp.url = url.url;
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) {
return new Promise((resolve, reject) => {
Meteor.call('loadHistory', rid, end, 20, (err, data) => {
@ -278,16 +279,10 @@ const RocketChat = {
return reject(err);
}
if (data && data.messages.length) {
const { server } = reduxStore.getState().server;
const messages = data.messages.map(message => this._buildMessage(message, server));
realm.write(() => {
data.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;
messages.forEach((message) => {
realm.create('messages', message, true);
});
});