2017-12-13 15:00:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-01-30 12:11:02 +00:00
|
|
|
import ActionSheet from 'react-native-action-sheet';
|
2017-12-13 15:00:26 +00:00
|
|
|
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
2019-10-07 20:56:30 +00:00
|
|
|
import database from '../lib/database';
|
2018-05-18 17:55:08 +00:00
|
|
|
import protectedFunction from '../lib/methods/helpers/protectedFunction';
|
2018-06-01 17:38:13 +00:00
|
|
|
import I18n from '../i18n';
|
2017-12-13 15:00:26 +00:00
|
|
|
|
2019-08-20 19:24:22 +00:00
|
|
|
class MessageErrorActions extends React.Component {
|
2017-12-13 15:00:26 +00:00
|
|
|
static propTypes = {
|
2019-10-07 20:56:30 +00:00
|
|
|
actionsHide: PropTypes.func.isRequired,
|
|
|
|
message: PropTypes.object
|
2017-12-13 15:00:26 +00:00
|
|
|
};
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
2017-12-13 15:00:26 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.handleActionPress = this.handleActionPress.bind(this);
|
2018-06-01 17:38:13 +00:00
|
|
|
this.options = [I18n.t('Cancel'), I18n.t('Delete'), I18n.t('Resend')];
|
2017-12-13 15:00:26 +00:00
|
|
|
this.CANCEL_INDEX = 0;
|
|
|
|
this.DELETE_INDEX = 1;
|
|
|
|
this.RESEND_INDEX = 2;
|
2018-11-16 11:06:29 +00:00
|
|
|
setTimeout(() => {
|
2019-01-30 12:11:02 +00:00
|
|
|
this.showActionSheet();
|
2018-11-16 11:06:29 +00:00
|
|
|
});
|
2017-12-13 15:00:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-07 20:56:30 +00:00
|
|
|
handleResend = protectedFunction(async() => {
|
|
|
|
const { message } = this.props;
|
|
|
|
await RocketChat.resendMessage(message);
|
|
|
|
});
|
|
|
|
|
|
|
|
handleDelete = protectedFunction(async() => {
|
|
|
|
const { message } = this.props;
|
|
|
|
const db = database.active;
|
|
|
|
await db.action(async() => {
|
|
|
|
await message.destroyPermanently();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
2019-01-30 12:11:02 +00:00
|
|
|
showActionSheet = () => {
|
|
|
|
ActionSheet.showActionSheetWithOptions({
|
|
|
|
options: this.options,
|
|
|
|
cancelButtonIndex: this.CANCEL_INDEX,
|
|
|
|
destructiveButtonIndex: this.DELETE_INDEX,
|
|
|
|
title: I18n.t('Message_actions')
|
|
|
|
}, (actionIndex) => {
|
|
|
|
this.handleActionPress(actionIndex);
|
2017-12-13 15:00:26 +00:00
|
|
|
});
|
2019-01-30 12:11:02 +00:00
|
|
|
}
|
2017-12-13 15:00:26 +00:00
|
|
|
|
|
|
|
handleActionPress = (actionIndex) => {
|
2019-10-07 20:56:30 +00:00
|
|
|
const { actionsHide } = this.props;
|
2017-12-13 15:00:26 +00:00
|
|
|
switch (actionIndex) {
|
|
|
|
case this.RESEND_INDEX:
|
|
|
|
this.handleResend();
|
|
|
|
break;
|
|
|
|
case this.DELETE_INDEX:
|
|
|
|
this.handleDelete();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-10-07 20:56:30 +00:00
|
|
|
actionsHide();
|
2017-12-13 15:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2019-01-30 12:11:02 +00:00
|
|
|
null
|
2017-12-13 15:00:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-20 19:24:22 +00:00
|
|
|
|
2019-10-07 20:56:30 +00:00
|
|
|
export default MessageErrorActions;
|