Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit e23583d

Browse files
authored
Merge pull request #5763 from uhoreg/room-history-key-sharing2
Share keys for historical messages when inviting users to encrypted rooms
2 parents e48dbef + db2f573 commit e23583d

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

src/components/views/dialogs/InviteDialog.tsx

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {Room} from "matrix-js-sdk/src/models/room";
4343
import { MatrixCall } from 'matrix-js-sdk/src/webrtc/call';
4444
import {replaceableComponent} from "../../../utils/replaceableComponent";
4545
import {mediaFromMxc} from "../../../customisations/Media";
46+
import {getAddressType} from "../../../UserAddress";
4647

4748
// we have a number of types defined from the Matrix spec which can't reasonably be altered here.
4849
/* eslint-disable camelcase */
@@ -678,14 +679,15 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
678679
});
679680
};
680681

681-
_inviteUsers = () => {
682+
_inviteUsers = async () => {
682683
const startTime = CountlyAnalytics.getTimestamp();
683684
this.setState({busy: true});
684685
this._convertFilter();
685686
const targets = this._convertFilter();
686687
const targetIds = targets.map(t => t.userId);
687688

688-
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
689+
const cli = MatrixClientPeg.get();
690+
const room = cli.getRoom(this.props.roomId);
689691
if (!room) {
690692
console.error("Failed to find the room to invite users to");
691693
this.setState({
@@ -695,20 +697,42 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
695697
return;
696698
}
697699

698-
inviteMultipleToRoom(this.props.roomId, targetIds).then(result => {
700+
try {
701+
const result = await inviteMultipleToRoom(this.props.roomId, targetIds)
699702
CountlyAnalytics.instance.trackSendInvite(startTime, this.props.roomId, targetIds.length);
700703
if (!this._shouldAbortAfterInviteError(result)) { // handles setting error message too
701704
this.props.onFinished();
702705
}
703-
}).catch(err => {
706+
707+
if (cli.isRoomEncrypted(this.props.roomId) &&
708+
SettingsStore.getValue("feature_room_history_key_sharing")) {
709+
const visibilityEvent = room.currentState.getStateEvents(
710+
"m.room.history_visibility", "",
711+
);
712+
const visibility = visibilityEvent && visibilityEvent.getContent() &&
713+
visibilityEvent.getContent().history_visibility;
714+
if (visibility == "world_readable" || visibility == "shared") {
715+
const invitedUsers = [];
716+
for (const [addr, state] of Object.entries(result.states)) {
717+
if (state === "invited" && getAddressType(addr) === "mx-user-id") {
718+
invitedUsers.push(addr);
719+
}
720+
}
721+
console.log("Sharing history with", invitedUsers);
722+
cli.sendSharedHistoryKeys(
723+
this.props.roomId, invitedUsers,
724+
);
725+
}
726+
}
727+
} catch (err) {
704728
console.error(err);
705729
this.setState({
706730
busy: false,
707731
errorText: _t(
708732
"We couldn't invite those users. Please check the users you want to invite and try again.",
709733
),
710734
});
711-
});
735+
}
712736
};
713737

714738
_transferCall = async () => {
@@ -1191,10 +1215,12 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
11911215
let helpText;
11921216
let buttonText;
11931217
let goButtonFn;
1218+
let keySharingWarning = <span />;
11941219

11951220
const identityServersEnabled = SettingsStore.getValue(UIFeature.IdentityServer);
11961221

1197-
const userId = MatrixClientPeg.get().getUserId();
1222+
const cli = MatrixClientPeg.get();
1223+
const userId = cli.getUserId();
11981224
if (this.props.kind === KIND_DM) {
11991225
title = _t("Direct Messages");
12001226

@@ -1290,6 +1316,25 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
12901316

12911317
buttonText = _t("Invite");
12921318
goButtonFn = this._inviteUsers;
1319+
1320+
if (SettingsStore.getValue("feature_room_history_key_sharing") &&
1321+
cli.isRoomEncrypted(this.props.roomId)) {
1322+
const room = cli.getRoom(this.props.roomId);
1323+
const visibilityEvent = room.currentState.getStateEvents(
1324+
"m.room.history_visibility", "",
1325+
);
1326+
const visibility = visibilityEvent && visibilityEvent.getContent() &&
1327+
visibilityEvent.getContent().history_visibility;
1328+
if (visibility === "world_readable" || visibility === "shared") {
1329+
keySharingWarning =
1330+
<p className='mx_InviteDialog_helpText'>
1331+
<img
1332+
src={require("../../../../res/img/element-icons/info.svg")}
1333+
width={14} height={14} />
1334+
{" " + _t("Invited people will be able to read old messages.")}
1335+
</p>;
1336+
}
1337+
}
12931338
} else if (this.props.kind === KIND_CALL_TRANSFER) {
12941339
title = _t("Transfer");
12951340
buttonText = _t("Transfer");
@@ -1323,6 +1368,7 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
13231368
{spinner}
13241369
</div>
13251370
</div>
1371+
{keySharingWarning}
13261372
{this._renderIdentityServerWarning()}
13271373
<div className='error'>{this.state.errorText}</div>
13281374
<div className='mx_InviteDialog_userSections'>

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@
797797
"Show message previews for reactions in DMs": "Show message previews for reactions in DMs",
798798
"Show message previews for reactions in all rooms": "Show message previews for reactions in all rooms",
799799
"Offline encrypted messaging using dehydrated devices": "Offline encrypted messaging using dehydrated devices",
800+
"Share decryption keys for room history when inviting users": "Share decryption keys for room history when inviting users",
800801
"Enable advanced debugging for the room list": "Enable advanced debugging for the room list",
801802
"Show info about bridges in room settings": "Show info about bridges in room settings",
802803
"Font size": "Font size",
@@ -2208,6 +2209,7 @@
22082209
"Invite someone using their name, username (like <userId/>) or <a>share this space</a>.": "Invite someone using their name, username (like <userId/>) or <a>share this space</a>.",
22092210
"Invite someone using their name, email address, username (like <userId/>) or <a>share this room</a>.": "Invite someone using their name, email address, username (like <userId/>) or <a>share this room</a>.",
22102211
"Invite someone using their name, username (like <userId/>) or <a>share this room</a>.": "Invite someone using their name, username (like <userId/>) or <a>share this room</a>.",
2212+
"Invited people will be able to read old messages.": "Invited people will be able to read old messages.",
22112213
"Transfer": "Transfer",
22122214
"a new master key signature": "a new master key signature",
22132215
"a new cross-signing key signature": "a new cross-signing key signature",

src/settings/Settings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ export const SETTINGS: {[setting: string]: ISetting} = {
220220
supportedLevels: LEVELS_FEATURE,
221221
default: false,
222222
},
223+
"feature_room_history_key_sharing": {
224+
isFeature: true,
225+
displayName: _td("Share decryption keys for room history when inviting users"),
226+
supportedLevels: LEVELS_FEATURE,
227+
default: false,
228+
},
223229
"advancedRoomListLogging": {
224230
// TODO: Remove flag before launch: https://github.com/vector-im/element-web/issues/14231
225231
displayName: _td("Enable advanced debugging for the room list"),

0 commit comments

Comments
 (0)