diff --git a/src/CallHandler.js b/src/CallHandler.js index 268a599d8ef..bb46056d199 100644 --- a/src/CallHandler.js +++ b/src/CallHandler.js @@ -105,6 +105,15 @@ function _setCallListeners(call) { call.hangup(); _setCallState(undefined, call.roomId, "ended"); }); + call.on('send_event_error', function(err) { + if (err.name === "UnknownDeviceError") { + dis.dispatch({ + action: 'unknown_device_error', + err: err, + room: MatrixClientPeg.get().getRoom(call.roomId), + }); + } + }); call.on("hangup", function() { _setCallState(undefined, call.roomId, "ended"); }); diff --git a/src/Resend.js b/src/Resend.js index e2f0c5a1eeb..d06562780cf 100644 --- a/src/Resend.js +++ b/src/Resend.js @@ -20,9 +20,24 @@ var sdk = require('./index'); var Modal = require('./Modal'); module.exports = { + resendUnsentEvents: function(room) { + room.getPendingEvents().filter(function(ev) { + return ev.status === Matrix.EventStatus.NOT_SENT; + }).forEach(function(event) { + module.exports.resend(event); + }); + }, + cancelUnsentEvents: function(room) { + room.getPendingEvents().filter(function(ev) { + return ev.status === Matrix.EventStatus.NOT_SENT; + }).forEach(function(event) { + module.exports.removeFromQueue(event); + }); + }, resend: function(event) { + const room = MatrixClientPeg.get().getRoom(event.getRoomId()); MatrixClientPeg.get().resendEvent( - event, MatrixClientPeg.get().getRoom(event.getRoomId()) + event, room ).done(function(res) { dis.dispatch({ action: 'message_sent', @@ -33,16 +48,11 @@ module.exports = { // https://github.com/vector-im/riot-web/issues/3148 console.log('Resend got send failure: ' + err.name + '('+err+')'); if (err.name === "UnknownDeviceError") { - var UnknownDeviceDialog = sdk.getComponent("dialogs.UnknownDeviceDialog"); - Modal.createDialog(UnknownDeviceDialog, { - devices: err.devices, - room: MatrixClientPeg.get().getRoom(event.getRoomId()), - onFinished: (r) => { - // XXX: temporary logging to try to diagnose - // https://github.com/vector-im/riot-web/issues/3148 - console.log('UnknownDeviceDialog closed with '+r); - }, - }, "mx_Dialog_unknownDevice"); + dis.dispatch({ + action: 'unknown_device_error', + err: err, + room: room, + }); } dis.dispatch({ @@ -51,7 +61,6 @@ module.exports = { }); }); }, - removeFromQueue: function(event) { MatrixClientPeg.get().cancelPendingEvent(event); dis.dispatch({ diff --git a/src/UnknownDeviceErrorHandler.js b/src/UnknownDeviceErrorHandler.js new file mode 100644 index 00000000000..88f4f57fe4a --- /dev/null +++ b/src/UnknownDeviceErrorHandler.js @@ -0,0 +1,31 @@ +import dis from './dispatcher'; +import sdk from './index'; +import Modal from './Modal'; + +const onAction = function(payload) { + if (payload.action === 'unknown_device_error') { + var UnknownDeviceDialog = sdk.getComponent("dialogs.UnknownDeviceDialog"); + Modal.createDialog(UnknownDeviceDialog, { + devices: payload.err.devices, + room: payload.room, + onFinished: (r) => { + // XXX: temporary logging to try to diagnose + // https://github.com/vector-im/riot-web/issues/3148 + console.log('UnknownDeviceDialog closed with '+r); + }, + }, "mx_Dialog_unknownDevice"); + } +} + +let ref = null; + +export function startListening () { + ref = dis.register(onAction); +} + +export function stopListening () { + if (ref) { + dis.unregister(ref); + ref = null; + } +} diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 1a828cd3e17..35f6abb9c50 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -41,6 +41,7 @@ var Lifecycle = require('../../Lifecycle'); var PageTypes = require('../../PageTypes'); var createRoom = require("../../createRoom"); +import * as UDEHandler from '../../UnknownDeviceErrorHandler'; module.exports = React.createClass({ displayName: 'MatrixChat', @@ -239,6 +240,7 @@ module.exports = React.createClass({ componentDidMount: function() { this.dispatcherRef = dis.register(this.onAction); + UDEHandler.startListening(); this.focusComposer = false; window.addEventListener("focus", this.onFocus); @@ -285,6 +287,7 @@ module.exports = React.createClass({ componentWillUnmount: function() { Lifecycle.stopMatrixClient(); dis.unregister(this.dispatcherRef); + UDEHandler.stopListening(); window.removeEventListener("focus", this.onFocus); window.removeEventListener('resize', this.handleResize); }, diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index acdea38c69a..3d676a793d2 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -716,17 +716,11 @@ module.exports = React.createClass({ }, onResendAllClick: function() { - var eventsToResend = this._getUnsentMessages(this.state.room); - eventsToResend.forEach(function(event) { - Resend.resend(event); - }); + Resend.resendUnsentEvents(this.state.room); }, onCancelAllClick: function() { - var eventsToResend = this._getUnsentMessages(this.state.room); - eventsToResend.forEach(function(event) { - Resend.removeFromQueue(event); - }); + Resend.cancelUnsentEvents(this.state.room); }, onJoinButtonClicked: function(ev) { diff --git a/src/components/views/dialogs/UnknownDeviceDialog.js b/src/components/views/dialogs/UnknownDeviceDialog.js index 3bebb8fdda2..3581b9815e6 100644 --- a/src/components/views/dialogs/UnknownDeviceDialog.js +++ b/src/components/views/dialogs/UnknownDeviceDialog.js @@ -16,6 +16,7 @@ limitations under the License. import React from 'react'; import sdk from '../../../index'; +import dis from '../../../dispatcher'; import MatrixClientPeg from '../../../MatrixClientPeg'; import GeminiScrollbar from 'react-gemini-scrollbar'; @@ -85,7 +86,7 @@ UnknownDeviceList.propTypes = { export default React.createClass({ - displayName: 'UnknownEventDialog', + displayName: 'UnknownDeviceDialog', propTypes: { room: React.PropTypes.object.isRequired, @@ -125,14 +126,10 @@ export default React.createClass({ } else { warning = (
-

- This means there is no guarantee that the devices - belong to the users they claim to. -

We recommend you go through the verification process - for each device before continuing, but you can resend - the message without verifying if you prefer. + for each device to confirm they belong to their legitimate owner, + but you can resend the message without verifying if you prefer.

); @@ -151,8 +148,7 @@ export default React.createClass({ >

- This room contains unknown devices which have not been - verified. + This room contains devices that you haven't seen before.

{ warning } Unknown devices: @@ -160,6 +156,13 @@ export default React.createClass({
+