From c0407c702bbe46a813a0b0d94727d1b054560cf2 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 14 Nov 2017 15:14:56 -0200 Subject: [PATCH] Delete action --- app/containers/message/index.js | 63 ++++++++++++++++++++++++++++----- app/lib/rocketchat.js | 3 ++ 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/app/containers/message/index.js b/app/containers/message/index.js index 2aa937d82..d6ff7cfaf 100644 --- a/app/containers/message/index.js +++ b/app/containers/message/index.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { View, StyleSheet, TouchableOpacity } from 'react-native'; +import { View, StyleSheet, TouchableOpacity, Text, Alert } from 'react-native'; import { emojify } from 'react-emojione'; import Markdown from 'react-native-easy-markdown'; import ActionSheet from 'react-native-actionsheet'; @@ -8,6 +8,7 @@ import ActionSheet from 'react-native-actionsheet'; import Card from './Card'; import User from './User'; import Avatar from '../Avatar'; +import RocketChat from '../../lib/rocketchat'; const title = 'Message actions'; const options = ['Cancel', 'Reply', 'Edit', 'Permalink', 'Copy', 'Quote', 'Star Message', 'Delete']; @@ -25,6 +26,10 @@ const styles = StyleSheet.create({ paddingBottom: 6, flexDirection: 'row', transform: [{ scaleY: -1 }] + }, + textInfo: { + fontStyle: 'italic', + color: '#a0a0a0' } }); @@ -41,6 +46,10 @@ export default class Message extends React.PureComponent { this.showActions = this.showActions.bind(this); } + isDeleted() { + return !this.props.item.msg; + } + attachments() { return this.props.item.attachments.length ? ( { - console.log(i); + handleDelete() { + Alert.alert( + 'Are you sure?', + 'You will not be able to recover this message!', + [ + { + text: 'Cancel', + style: 'cancel' + }, + { + text: 'Yes, delete it!', + style: 'destructive', + onPress: () => this.deleteMessage(this.props.item) + } + ], + { cancelable: false } + ); + } + + handleActionPress = (actionIndex) => { + if (actionIndex === 7) { + this.handleDelete(); + } else { + console.log(actionIndex, this.props.item); + } + } + + deleteMessage = message => RocketChat.deleteMessage(message); + + renderMessageContent() { + if (this.isDeleted()) { + return Message removed; + } + + const msg = emojify(this.props.item.msg, { output: 'unicode' }); + return ( + + {msg} + + ); } render() { @@ -65,11 +112,13 @@ export default class Message extends React.PureComponent { extraStyle.opacity = 0.3; } - const msg = emojify(item.msg, { output: 'unicode' }); const username = item.alias || item.u.username; return ( - this.showActions()}> + this.showActions()} + disabled={this.isDeleted()} + > {this.attachments()} - - {msg} - + {this.renderMessageContent(item)} this.ActionSheet = o} diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 70d394b54..8dea5943d 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -454,6 +454,9 @@ const RocketChat = { Meteor.disconnect(); AsyncStorage.removeItem(TOKEN_KEY); AsyncStorage.removeItem(`${ TOKEN_KEY }-${ server }`); + }, + deleteMessage(message) { + return call('deleteMessage', { _id: message._id }); } };