From 7f141276fffd3a6873a3dfa7282b202a723b851c Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Mon, 15 Mar 2021 22:56:56 -0400 Subject: [PATCH 1/3] initial work on room history key sharing, take 2 --- src/components/views/dialogs/InviteDialog.tsx | 55 +++++++++++++++++-- src/i18n/strings/en_EN.json | 2 + src/settings/Settings.ts | 6 ++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/components/views/dialogs/InviteDialog.tsx b/src/components/views/dialogs/InviteDialog.tsx index 5b936e822c6..fa87826c092 100644 --- a/src/components/views/dialogs/InviteDialog.tsx +++ b/src/components/views/dialogs/InviteDialog.tsx @@ -42,6 +42,7 @@ import {UIFeature} from "../../../settings/UIFeature"; import CountlyAnalytics from "../../../CountlyAnalytics"; import {Room} from "matrix-js-sdk/src/models/room"; import { MatrixCall } from 'matrix-js-sdk/src/webrtc/call'; +import {getAddressType} from "../../../UserAddress"; // we have a number of types defined from the Matrix spec which can't reasonably be altered here. /* eslint-disable camelcase */ @@ -676,14 +677,15 @@ export default class InviteDialog extends React.PureComponent { + _inviteUsers = async () => { const startTime = CountlyAnalytics.getTimestamp(); this.setState({busy: true}); this._convertFilter(); const targets = this._convertFilter(); const targetIds = targets.map(t => t.userId); - const room = MatrixClientPeg.get().getRoom(this.props.roomId); + const cli = MatrixClientPeg.get(); + const room = cli.getRoom(this.props.roomId); if (!room) { console.error("Failed to find the room to invite users to"); this.setState({ @@ -693,12 +695,34 @@ export default class InviteDialog extends React.PureComponent { + try { + const result = await inviteMultipleToRoom(this.props.roomId, targetIds) CountlyAnalytics.instance.trackSendInvite(startTime, this.props.roomId, targetIds.length); if (!this._shouldAbortAfterInviteError(result)) { // handles setting error message too this.props.onFinished(); } - }).catch(err => { + + if (cli.isRoomEncrypted(this.props.roomId) && + SettingsStore.getValue("feature_room_history_key_sharing")) { + const visibilityEvent = room.currentState.getStateEvents( + "m.room.history_visibility", "", + ); + const visibility = visibilityEvent && visibilityEvent.getContent() && + visibilityEvent.getContent().history_visibility; + if (visibility == "world_readable" || visibility == "shared") { + const invitedUsers = []; + for (const [addr, state] of Object.entries(result.states)) { + if (state === "invited" && getAddressType(addr) === "mx-user-id") { + invitedUsers.push(addr); + } + } + console.log("Sharing history with", invitedUsers); + cli.sendSharedHistoryKeys( + this.props.roomId, invitedUsers, + ); + } + } + } catch (err) { console.error(err); this.setState({ busy: false, @@ -706,7 +730,7 @@ export default class InviteDialog extends React.PureComponent { @@ -1187,10 +1211,12 @@ export default class InviteDialog extends React.PureComponent; const identityServersEnabled = SettingsStore.getValue(UIFeature.IdentityServer); - const userId = MatrixClientPeg.get().getUserId(); + const cli = MatrixClientPeg.get(); + const userId = cli.getUserId(); if (this.props.kind === KIND_DM) { title = _t("Direct Messages"); @@ -1281,6 +1307,22 @@ export default class InviteDialog extends React.PureComponent + {_t("Note: Decryption keys for old messages will be shared with invited users.")} + ; + } + } } else if (this.props.kind === KIND_CALL_TRANSFER) { title = _t("Transfer"); buttonText = _t("Transfer"); @@ -1314,6 +1356,7 @@ export default class InviteDialog extends React.PureComponent + {keySharingWarning} {this._renderIdentityServerWarning()}
{this.state.errorText}
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 38460a5f6e1..dc808cb8bd7 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -791,6 +791,7 @@ "Show message previews for reactions in DMs": "Show message previews for reactions in DMs", "Show message previews for reactions in all rooms": "Show message previews for reactions in all rooms", "Offline encrypted messaging using dehydrated devices": "Offline encrypted messaging using dehydrated devices", + "Share decryption keys for room history when inviting users": "Share decryption keys for room history when inviting users", "Enable advanced debugging for the room list": "Enable advanced debugging for the room list", "Show info about bridges in room settings": "Show info about bridges in room settings", "Font size": "Font size", @@ -2153,6 +2154,7 @@ "Go": "Go", "Invite someone using their name, email address, username (like ) or share this room.": "Invite someone using their name, email address, username (like ) or share this room.", "Invite someone using their name, username (like ) or share this room.": "Invite someone using their name, username (like ) or share this room.", + "Note: Decryption keys for old messages will be shared with invited users.": "Note: Decryption keys for old messages will be shared with invited users.", "Transfer": "Transfer", "a new master key signature": "a new master key signature", "a new cross-signing key signature": "a new cross-signing key signature", diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index 43210021e56..77b0f187c72 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -214,6 +214,12 @@ export const SETTINGS: {[setting: string]: ISetting} = { supportedLevels: LEVELS_FEATURE, default: false, }, + "feature_room_history_key_sharing": { + isFeature: true, + displayName: _td("Share decryption keys for room history when inviting users"), + supportedLevels: LEVELS_FEATURE, + default: false, + }, "advancedRoomListLogging": { // TODO: Remove flag before launch: https://github.com/vector-im/element-web/issues/14231 displayName: _td("Enable advanced debugging for the room list"), From 727c189456c6f953993cb72118aae0ba9340e503 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Fri, 19 Mar 2021 16:55:07 -0400 Subject: [PATCH 2/3] apply changes from review --- src/components/views/dialogs/InviteDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/dialogs/InviteDialog.tsx b/src/components/views/dialogs/InviteDialog.tsx index fa87826c092..41fb1f5ab63 100644 --- a/src/components/views/dialogs/InviteDialog.tsx +++ b/src/components/views/dialogs/InviteDialog.tsx @@ -1316,7 +1316,7 @@ export default class InviteDialog extends React.PureComponent {_t("Note: Decryption keys for old messages will be shared with invited users.")} From 46fd549ace0e3c05e449da9d7cabc4bbf9735ce5 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Thu, 25 Mar 2021 19:27:14 -0400 Subject: [PATCH 3/3] update with new suggested design --- src/components/views/dialogs/InviteDialog.tsx | 9 ++++++--- src/i18n/strings/en_EN.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/views/dialogs/InviteDialog.tsx b/src/components/views/dialogs/InviteDialog.tsx index 41fb1f5ab63..9f7364e4de5 100644 --- a/src/components/views/dialogs/InviteDialog.tsx +++ b/src/components/views/dialogs/InviteDialog.tsx @@ -1318,9 +1318,12 @@ export default class InviteDialog extends React.PureComponent - {_t("Note: Decryption keys for old messages will be shared with invited users.")} -
; +

+ + {" " + _t("Invited people will be able to read old messages.")} +

; } } } else if (this.props.kind === KIND_CALL_TRANSFER) { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index dc808cb8bd7..743121a33e9 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2154,7 +2154,7 @@ "Go": "Go", "Invite someone using their name, email address, username (like ) or share this room.": "Invite someone using their name, email address, username (like ) or share this room.", "Invite someone using their name, username (like ) or share this room.": "Invite someone using their name, username (like ) or share this room.", - "Note: Decryption keys for old messages will be shared with invited users.": "Note: Decryption keys for old messages will be shared with invited users.", + "Invited people will be able to read old messages.": "Invited people will be able to read old messages.", "Transfer": "Transfer", "a new master key signature": "a new master key signature", "a new cross-signing key signature": "a new cross-signing key signature",