Separate attachment types

This commit is contained in:
Diego Mello 2017-11-27 13:40:23 -02:00
parent e21fac2c70
commit 6b9d3684df
2 changed files with 28 additions and 11 deletions

View File

@ -33,7 +33,8 @@ const styles = StyleSheet.create({
@connect(state => ({
message: state.messages.message,
editing: state.messages.editing
editing: state.messages.editing,
server: state.server.server
}), dispatch => ({
actionsShow: actionMessage => dispatch(actionsShow(actionMessage))
}))
@ -44,7 +45,8 @@ export default class Message extends React.Component {
Message_TimeFormat: PropTypes.string.isRequired,
message: PropTypes.object.isRequired,
editing: PropTypes.bool,
actionsShow: PropTypes.func
actionsShow: PropTypes.func,
server: PropTypes.string
}
onLongPress() {
@ -57,11 +59,24 @@ export default class Message extends React.Component {
}
attachments() {
return this.props.item.attachments.length ? (
<Card
data={this.props.item.attachments[0]}
/>
) : null;
if (this.props.item.attachments.length === 0) {
return null;
}
const file = this.props.item.attachments[0];
if (file.image_type) {
return (
<Card
data={file}
/>
);
} else if (file.audio_type) {
return <Text>{`${ this.props.server }${ JSON.parse(JSON.stringify(file.audio_url)) }`}</Text>;
} else if (file.video_type) {
return <Text>{`${ this.props.server }${ JSON.parse(JSON.stringify(file.video_url)) }`}</Text>;
}
return <Text>Other type</Text>;
}
renderMessageContent() {

View File

@ -99,14 +99,16 @@ const attachment = {
name: 'attachment',
properties: {
description: { type: 'string', optional: true },
image_size: { type: 'int', optional: true },
image_type: { type: 'string', optional: true },
image_url: { type: 'string', optional: true },
audio_size: { type: 'int', optional: true },
audio_type: { type: 'string', optional: true },
audio_url: { type: 'string', optional: true },
video_size: { type: 'int', optional: true },
video_type: { type: 'string', optional: true },
video_url: { type: 'string', optional: true },
title: { type: 'string', optional: true },
title_link: { type: 'string', optional: true },
title_link_download: { type: 'bool', optional: true },
type: { type: 'string', optional: true }