Merge pull request #721 from matrix-org/luke/fix-refactor-UnknownDeviceDialog

Show UDDialog on UDE during VoIP calls
pull/21833/head
David Baker 2017-03-02 13:13:45 +00:00 committed by GitHub
commit 95cff17698
7 changed files with 82 additions and 38 deletions

View File

@ -105,6 +105,15 @@ function _setCallListeners(call) {
call.hangup(); call.hangup();
_setCallState(undefined, call.roomId, "ended"); _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() { call.on("hangup", function() {
_setCallState(undefined, call.roomId, "ended"); _setCallState(undefined, call.roomId, "ended");
}); });

View File

@ -20,9 +20,24 @@ var sdk = require('./index');
var Modal = require('./Modal'); var Modal = require('./Modal');
module.exports = { 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) { resend: function(event) {
const room = MatrixClientPeg.get().getRoom(event.getRoomId());
MatrixClientPeg.get().resendEvent( MatrixClientPeg.get().resendEvent(
event, MatrixClientPeg.get().getRoom(event.getRoomId()) event, room
).done(function(res) { ).done(function(res) {
dis.dispatch({ dis.dispatch({
action: 'message_sent', action: 'message_sent',
@ -33,16 +48,11 @@ module.exports = {
// https://github.com/vector-im/riot-web/issues/3148 // https://github.com/vector-im/riot-web/issues/3148
console.log('Resend got send failure: ' + err.name + '('+err+')'); console.log('Resend got send failure: ' + err.name + '('+err+')');
if (err.name === "UnknownDeviceError") { if (err.name === "UnknownDeviceError") {
var UnknownDeviceDialog = sdk.getComponent("dialogs.UnknownDeviceDialog"); dis.dispatch({
Modal.createDialog(UnknownDeviceDialog, { action: 'unknown_device_error',
devices: err.devices, err: err,
room: MatrixClientPeg.get().getRoom(event.getRoomId()), room: 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");
} }
dis.dispatch({ dis.dispatch({
@ -51,7 +61,6 @@ module.exports = {
}); });
}); });
}, },
removeFromQueue: function(event) { removeFromQueue: function(event) {
MatrixClientPeg.get().cancelPendingEvent(event); MatrixClientPeg.get().cancelPendingEvent(event);
dis.dispatch({ dis.dispatch({

View File

@ -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;
}
}

View File

@ -41,6 +41,7 @@ var Lifecycle = require('../../Lifecycle');
var PageTypes = require('../../PageTypes'); var PageTypes = require('../../PageTypes');
var createRoom = require("../../createRoom"); var createRoom = require("../../createRoom");
import * as UDEHandler from '../../UnknownDeviceErrorHandler';
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'MatrixChat', displayName: 'MatrixChat',
@ -239,6 +240,7 @@ module.exports = React.createClass({
componentDidMount: function() { componentDidMount: function() {
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = dis.register(this.onAction);
UDEHandler.startListening();
this.focusComposer = false; this.focusComposer = false;
window.addEventListener("focus", this.onFocus); window.addEventListener("focus", this.onFocus);
@ -285,6 +287,7 @@ module.exports = React.createClass({
componentWillUnmount: function() { componentWillUnmount: function() {
Lifecycle.stopMatrixClient(); Lifecycle.stopMatrixClient();
dis.unregister(this.dispatcherRef); dis.unregister(this.dispatcherRef);
UDEHandler.stopListening();
window.removeEventListener("focus", this.onFocus); window.removeEventListener("focus", this.onFocus);
window.removeEventListener('resize', this.handleResize); window.removeEventListener('resize', this.handleResize);
}, },

View File

@ -716,17 +716,11 @@ module.exports = React.createClass({
}, },
onResendAllClick: function() { onResendAllClick: function() {
var eventsToResend = this._getUnsentMessages(this.state.room); Resend.resendUnsentEvents(this.state.room);
eventsToResend.forEach(function(event) {
Resend.resend(event);
});
}, },
onCancelAllClick: function() { onCancelAllClick: function() {
var eventsToResend = this._getUnsentMessages(this.state.room); Resend.cancelUnsentEvents(this.state.room);
eventsToResend.forEach(function(event) {
Resend.removeFromQueue(event);
});
}, },
onJoinButtonClicked: function(ev) { onJoinButtonClicked: function(ev) {

View File

@ -16,6 +16,7 @@ limitations under the License.
import React from 'react'; import React from 'react';
import sdk from '../../../index'; import sdk from '../../../index';
import dis from '../../../dispatcher';
import MatrixClientPeg from '../../../MatrixClientPeg'; import MatrixClientPeg from '../../../MatrixClientPeg';
import GeminiScrollbar from 'react-gemini-scrollbar'; import GeminiScrollbar from 'react-gemini-scrollbar';
@ -85,7 +86,7 @@ UnknownDeviceList.propTypes = {
export default React.createClass({ export default React.createClass({
displayName: 'UnknownEventDialog', displayName: 'UnknownDeviceDialog',
propTypes: { propTypes: {
room: React.PropTypes.object.isRequired, room: React.PropTypes.object.isRequired,
@ -125,14 +126,10 @@ export default React.createClass({
} else { } else {
warning = ( warning = (
<div> <div>
<p>
This means there is no guarantee that the devices
belong to the users they claim to.
</p>
<p> <p>
We recommend you go through the verification process We recommend you go through the verification process
for each device before continuing, but you can resend for each device to confirm they belong to their legitimate owner,
the message without verifying if you prefer. but you can resend the message without verifying if you prefer.
</p> </p>
</div> </div>
); );
@ -151,8 +148,7 @@ export default React.createClass({
> >
<GeminiScrollbar autoshow={false} className="mx_Dialog_content"> <GeminiScrollbar autoshow={false} className="mx_Dialog_content">
<h4> <h4>
This room contains unknown devices which have not been This room contains devices that you haven't seen before.
verified.
</h4> </h4>
{ warning } { warning }
Unknown devices: Unknown devices:
@ -160,6 +156,13 @@ export default React.createClass({
<UnknownDeviceList devices={this.props.devices} /> <UnknownDeviceList devices={this.props.devices} />
</GeminiScrollbar> </GeminiScrollbar>
<div className="mx_Dialog_buttons"> <div className="mx_Dialog_buttons">
<button className="mx_Dialog_primary" autoFocus={ true }
onClick={() => {
this.props.onFinished();
Resend.resendUnsentEvents(this.props.room);
}}>
Send anyway
</button>
<button className="mx_Dialog_primary" autoFocus={ true } <button className="mx_Dialog_primary" autoFocus={ true }
onClick={() => { onClick={() => {
// XXX: temporary logging to try to diagnose // XXX: temporary logging to try to diagnose

View File

@ -34,16 +34,11 @@ export function onSendMessageFailed(err, room) {
// https://github.com/vector-im/riot-web/issues/3148 // https://github.com/vector-im/riot-web/issues/3148
console.log('MessageComposer got send failure: ' + err.name + '('+err+')'); console.log('MessageComposer got send failure: ' + err.name + '('+err+')');
if (err.name === "UnknownDeviceError") { if (err.name === "UnknownDeviceError") {
const UnknownDeviceDialog = sdk.getComponent("dialogs.UnknownDeviceDialog"); dis.dispatch({
Modal.createDialog(UnknownDeviceDialog, { action: 'unknown_device_error',
devices: err.devices, err: err,
room: room, room: 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");
} }
dis.dispatch({ dis.dispatch({
action: 'message_send_failed', action: 'message_send_failed',