Merge pull request #3927 from matrix-org/bwindels/fixverifyowndevice

Fix verifying your own devices with to_device messages
This commit is contained in:
Bruno Windels 2020-01-24 11:24:33 +00:00 committed by GitHub
commit b66154330c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 27 deletions

View file

@ -93,7 +93,7 @@ export default class MKeyVerificationConclusion extends React.Component {
} }
if (title) { if (title) {
const subtitle = userLabelForEventRoom(request.otherUserId, mxEvent); const subtitle = userLabelForEventRoom(request.otherUserId, mxEvent.getRoomId());
const classes = classNames("mx_EventTile_bubble", "mx_KeyVerification", "mx_KeyVerification_icon", { const classes = classNames("mx_EventTile_bubble", "mx_KeyVerification", "mx_KeyVerification_icon", {
mx_KeyVerification_icon_verified: request.done, mx_KeyVerification_icon_verified: request.done,
}); });

View file

@ -85,7 +85,7 @@ export default class MKeyVerificationRequest extends React.Component {
if (userId === myUserId) { if (userId === myUserId) {
return _t("You accepted"); return _t("You accepted");
} else { } else {
return _t("%(name)s accepted", {name: getNameForEventRoom(userId, this.props.mxEvent)}); return _t("%(name)s accepted", {name: getNameForEventRoom(userId, this.props.mxEvent.getRoomId())});
} }
} }
@ -95,7 +95,7 @@ export default class MKeyVerificationRequest extends React.Component {
if (userId === myUserId) { if (userId === myUserId) {
return _t("You cancelled"); return _t("You cancelled");
} else { } else {
return _t("%(name)s cancelled", {name: getNameForEventRoom(userId, this.props.mxEvent)}); return _t("%(name)s cancelled", {name: getNameForEventRoom(userId, this.props.mxEvent.getRoomId())});
} }
} }
@ -128,10 +128,11 @@ export default class MKeyVerificationRequest extends React.Component {
} }
if (!request.initiatedByMe) { if (!request.initiatedByMe) {
const name = getNameForEventRoom(request.requestingUserId, mxEvent.getRoomId());
title = (<div className="mx_KeyVerification_title">{ title = (<div className="mx_KeyVerification_title">{
_t("%(name)s wants to verify", {name: getNameForEventRoom(request.requestingUserId, mxEvent)})}</div>); _t("%(name)s wants to verify", {name})}</div>);
subtitle = (<div className="mx_KeyVerification_subtitle">{ subtitle = (<div className="mx_KeyVerification_subtitle">{
userLabelForEventRoom(request.requestingUserId, mxEvent)}</div>); userLabelForEventRoom(request.requestingUserId, mxEvent.getRoomId())}</div>);
if (request.requested && !request.observeOnly) { if (request.requested && !request.observeOnly) {
stateNode = (<div className="mx_KeyVerification_buttons"> stateNode = (<div className="mx_KeyVerification_buttons">
<FormButton kind="danger" onClick={this._onRejectClicked} label={_t("Decline")} /> <FormButton kind="danger" onClick={this._onRejectClicked} label={_t("Decline")} />
@ -142,7 +143,7 @@ export default class MKeyVerificationRequest extends React.Component {
title = (<div className="mx_KeyVerification_title">{ title = (<div className="mx_KeyVerification_title">{
_t("You sent a verification request")}</div>); _t("You sent a verification request")}</div>);
subtitle = (<div className="mx_KeyVerification_subtitle">{ subtitle = (<div className="mx_KeyVerification_subtitle">{
userLabelForEventRoom(request.receivingUserId, mxEvent)}</div>); userLabelForEventRoom(request.receivingUserId, mxEvent.getRoomId())}</div>);
} }
if (title) { if (title) {

View file

@ -23,6 +23,7 @@ import {RIGHT_PANEL_PHASES} from "../../../stores/RightPanelStorePhases";
import {userLabelForEventRoom} from "../../../utils/KeyVerificationStateObserver"; import {userLabelForEventRoom} from "../../../utils/KeyVerificationStateObserver";
import dis from "../../../dispatcher"; import dis from "../../../dispatcher";
import ToastStore from "../../../stores/ToastStore"; import ToastStore from "../../../stores/ToastStore";
import Modal from "../../../Modal";
export default class VerificationRequestToast extends React.PureComponent { export default class VerificationRequestToast extends React.PureComponent {
constructor(props) { constructor(props) {
@ -65,22 +66,27 @@ export default class VerificationRequestToast extends React.PureComponent {
accept = async () => { accept = async () => {
ToastStore.sharedInstance().dismissToast(this.props.toastKey); ToastStore.sharedInstance().dismissToast(this.props.toastKey);
const {request} = this.props; const {request} = this.props;
const {event} = request;
// no room id for to_device requests // no room id for to_device requests
if (event.getRoomId()) {
dis.dispatch({
action: 'view_room',
room_id: event.getRoomId(),
should_peek: false,
});
}
try { try {
await request.accept(); if (request.channel.roomId) {
dis.dispatch({ dis.dispatch({
action: "set_right_panel_phase", action: 'view_room',
phase: RIGHT_PANEL_PHASES.EncryptionPanel, room_id: request.channel.roomId,
refireParams: {verificationRequest: request}, should_peek: false,
}); });
await request.accept();
dis.dispatch({
action: "set_right_panel_phase",
phase: RIGHT_PANEL_PHASES.EncryptionPanel,
refireParams: {verificationRequest: request},
});
} else if (request.channel.deviceId && request.verifier) {
// show to_device verifications in dialog still
const IncomingSasDialog = sdk.getComponent("views.dialogs.IncomingSasDialog");
Modal.createTrackedDialog('Incoming Verification', '', IncomingSasDialog, {
verifier: request.verifier,
}, null, /* priority = */ false, /* static = */ true);
}
} catch (err) { } catch (err) {
console.error(err.message); console.error(err.message);
} }
@ -89,13 +95,13 @@ export default class VerificationRequestToast extends React.PureComponent {
render() { render() {
const FormButton = sdk.getComponent("elements.FormButton"); const FormButton = sdk.getComponent("elements.FormButton");
const {request} = this.props; const {request} = this.props;
const {event} = request;
const userId = request.otherUserId; const userId = request.otherUserId;
let nameLabel = event.getRoomId() ? userLabelForEventRoom(userId, event) : userId; const roomId = request.channel.roomId;
let nameLabel = roomId ? userLabelForEventRoom(userId, roomId) : userId;
// for legacy to_device verification requests // for legacy to_device verification requests
if (nameLabel === userId) { if (nameLabel === userId) {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
const user = client.getUser(event.getSender()); const user = client.getUser(userId);
if (user && user.displayName) { if (user && user.displayName) {
nameLabel = _t("%(name)s (%(userId)s)", {name: user.displayName, userId}); nameLabel = _t("%(name)s (%(userId)s)", {name: user.displayName, userId});
} }

View file

@ -17,16 +17,15 @@ limitations under the License.
import {MatrixClientPeg} from '../MatrixClientPeg'; import {MatrixClientPeg} from '../MatrixClientPeg';
import { _t } from '../languageHandler'; import { _t } from '../languageHandler';
export function getNameForEventRoom(userId, mxEvent) { export function getNameForEventRoom(userId, roomId) {
const roomId = mxEvent.getRoomId();
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
const room = client.getRoom(roomId); const room = client.getRoom(roomId);
const member = room.getMember(userId); const member = room.getMember(userId);
return member ? member.name : userId; return member ? member.name : userId;
} }
export function userLabelForEventRoom(userId, mxEvent) { export function userLabelForEventRoom(userId, roomId) {
const name = getNameForEventRoom(userId, mxEvent); const name = getNameForEventRoom(userId, roomId);
if (name !== userId) { if (name !== userId) {
return _t("%(name)s (%(userId)s)", {name, userId}); return _t("%(name)s (%(userId)s)", {name, userId});
} else { } else {