2017-12-13 15:00:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import ActionSheet from 'react-native-actionsheet';
|
|
|
|
|
|
|
|
import { errorActionsHide } from '../actions/messages';
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
2017-12-27 15:22:06 +00:00
|
|
|
import database from '../lib/realm';
|
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
|
|
|
|
|
|
|
@connect(
|
|
|
|
state => ({
|
|
|
|
actionMessage: state.messages.actionMessage
|
|
|
|
}),
|
|
|
|
dispatch => ({
|
|
|
|
errorActionsHide: () => dispatch(errorActionsHide())
|
|
|
|
})
|
|
|
|
)
|
2018-02-08 14:08:50 +00:00
|
|
|
export default class MessageErrorActions extends React.Component {
|
2017-12-13 15:00:26 +00:00
|
|
|
static propTypes = {
|
|
|
|
errorActionsHide: PropTypes.func.isRequired,
|
|
|
|
actionMessage: PropTypes.object
|
|
|
|
};
|
|
|
|
|
|
|
|
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-08-01 19:35:06 +00:00
|
|
|
if (this.actionSheet && this.actionSheet.show) {
|
|
|
|
this.actionSheet.show();
|
|
|
|
}
|
2017-12-13 15:00:26 +00:00
|
|
|
}
|
|
|
|
|
2018-05-18 17:55:08 +00:00
|
|
|
handleResend = protectedFunction(() => RocketChat.resendMessage(this.props.actionMessage._id));
|
2017-12-13 15:00:26 +00:00
|
|
|
|
2018-05-18 17:55:08 +00:00
|
|
|
handleDelete = protectedFunction(() => {
|
2017-12-27 15:22:06 +00:00
|
|
|
database.write(() => {
|
|
|
|
const msg = database.objects('messages').filtered('_id = $0', this.props.actionMessage._id);
|
|
|
|
database.delete(msg);
|
2017-12-13 15:00:26 +00:00
|
|
|
});
|
2018-05-18 17:55:08 +00:00
|
|
|
})
|
2017-12-13 15:00:26 +00:00
|
|
|
|
|
|
|
handleActionPress = (actionIndex) => {
|
|
|
|
switch (actionIndex) {
|
|
|
|
case this.RESEND_INDEX:
|
|
|
|
this.handleResend();
|
|
|
|
break;
|
|
|
|
case this.DELETE_INDEX:
|
|
|
|
this.handleDelete();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.props.errorActionsHide();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ActionSheet
|
2018-08-01 19:35:06 +00:00
|
|
|
ref={o => this.actionSheet = o}
|
2018-06-01 17:38:13 +00:00
|
|
|
title={I18n.t('Message_actions')}
|
2017-12-13 15:00:26 +00:00
|
|
|
options={this.options}
|
|
|
|
cancelButtonIndex={this.CANCEL_INDEX}
|
|
|
|
destructiveButtonIndex={this.DELETE_INDEX}
|
|
|
|
onPress={this.handleActionPress}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|