From a9ed2e20cbfb6cd33a95c9bf5715fc903a93f6d5 Mon Sep 17 00:00:00 2001 From: Keyvan Fatehi Date: Sat, 18 Mar 2017 17:45:13 -0700 Subject: [PATCH] Confirm redactions with a dialog Closes #277 Closes #1805 Signed-off-by: Keyvan Fatehi --- .../views/context_menus/MessageContextMenu.js | 31 ++++++++++-------- src/components/views/elements/ImageView.js | 32 +++++++++++-------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index e56a3e2f..db416b8a 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -62,19 +62,24 @@ module.exports = React.createClass({ }, onRedactClick: function() { - MatrixClientPeg.get().redactEvent( - this.props.mxEvent.getRoomId(), this.props.mxEvent.getId() - ).done(function() { - // message should disappear by itself - }, function(e) { - var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - // display error message stating you couldn't delete this. - var code = e.errcode || e.statusCode; - Modal.createDialog(ErrorDialog, { - title: "Error", - description: "You cannot delete this message. (" + code + ")" - }); - }); + const ConfirmRedactDialog = sdk.getComponent("dialogs.ConfirmRedactDialog"); + Modal.createDialog(ConfirmRedactDialog, { + onFinished: (proceed) => { + if (!proceed) return; + + MatrixClientPeg.get().redactEvent( + this.props.mxEvent.getRoomId(), this.props.mxEvent.getId() + ).catch(function(e) { + var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + // display error message stating you couldn't delete this. + var code = e.errcode || e.statusCode; + Modal.createDialog(ErrorDialog, { + title: "Error", + description: "You cannot delete this message. (" + code + ")" + }); + }).done(); + }, + }, 'mx_Dialog_confirmredact'); if (this.props.onFinished) this.props.onFinished(); }, diff --git a/src/components/views/elements/ImageView.js b/src/components/views/elements/ImageView.js index 4a0c1663..42730aca 100644 --- a/src/components/views/elements/ImageView.js +++ b/src/components/views/elements/ImageView.js @@ -23,6 +23,8 @@ var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg'); var DateUtils = require('matrix-react-sdk/lib/DateUtils'); var filesize = require('filesize'); var AccessibleButton = require('matrix-react-sdk/lib/components/views/elements/AccessibleButton'); +const Modal = require('matrix-react-sdk/lib/Modal'); +const sdk = require('matrix-react-sdk'); module.exports = React.createClass({ displayName: 'ImageView', @@ -62,19 +64,23 @@ module.exports = React.createClass({ }, onRedactClick: function() { - var self = this; - MatrixClientPeg.get().redactEvent( - this.props.mxEvent.getRoomId(), this.props.mxEvent.getId() - ).done(function() { - if (self.props.onFinished) self.props.onFinished(); - }, function(e) { - var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - // display error message stating you couldn't delete this. - var code = e.errcode || e.statusCode; - Modal.createDialog(ErrorDialog, { - title: "Error", - description: "You cannot delete this image. (" + code + ")" - }); + const ConfirmRedactDialog = sdk.getComponent("dialogs.ConfirmRedactDialog"); + Modal.createDialog(ConfirmRedactDialog, { + onFinished: (proceed) => { + if (!proceed) return; + var self = this; + MatrixClientPeg.get().redactEvent( + this.props.mxEvent.getRoomId(), this.props.mxEvent.getId() + ).catch(function(e) { + var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + // display error message stating you couldn't delete this. + var code = e.errcode || e.statusCode; + Modal.createDialog(ErrorDialog, { + title: "Error", + description: "You cannot delete this image. (" + code + ")" + }); + }).done(); + } }); },