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

Commit 7f14127

Browse files
committed
initial work on room history key sharing, take 2
1 parent 588e94e commit 7f14127

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

src/components/views/dialogs/InviteDialog.tsx

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {UIFeature} from "../../../settings/UIFeature";
4242
import CountlyAnalytics from "../../../CountlyAnalytics";
4343
import {Room} from "matrix-js-sdk/src/models/room";
4444
import { MatrixCall } from 'matrix-js-sdk/src/webrtc/call';
45+
import {getAddressType} from "../../../UserAddress";
4546

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

679-
_inviteUsers = () => {
680+
_inviteUsers = async () => {
680681
const startTime = CountlyAnalytics.getTimestamp();
681682
this.setState({busy: true});
682683
this._convertFilter();
683684
const targets = this._convertFilter();
684685
const targetIds = targets.map(t => t.userId);
685686

686-
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
687+
const cli = MatrixClientPeg.get();
688+
const room = cli.getRoom(this.props.roomId);
687689
if (!room) {
688690
console.error("Failed to find the room to invite users to");
689691
this.setState({
@@ -693,20 +695,42 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
693695
return;
694696
}
695697

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

712736
_transferCall = async () => {
@@ -1187,10 +1211,12 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
11871211
let helpText;
11881212
let buttonText;
11891213
let goButtonFn;
1214+
let keySharingWarning = <span />;
11901215

11911216
const identityServersEnabled = SettingsStore.getValue(UIFeature.IdentityServer);
11921217

1193-
const userId = MatrixClientPeg.get().getUserId();
1218+
const cli = MatrixClientPeg.get();
1219+
const userId = cli.getUserId();
11941220
if (this.props.kind === KIND_DM) {
11951221
title = _t("Direct Messages");
11961222

@@ -1281,6 +1307,22 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
12811307

12821308
buttonText = _t("Invite");
12831309
goButtonFn = this._inviteUsers;
1310+
1311+
if (SettingsStore.getValue("feature_room_history_key_sharing") &&
1312+
cli.isRoomEncrypted(this.props.roomId)) {
1313+
const room = cli.getRoom(this.props.roomId);
1314+
const visibilityEvent = room.currentState.getStateEvents(
1315+
"m.room.history_visibility", "",
1316+
);
1317+
const visibility = visibilityEvent && visibilityEvent.getContent() &&
1318+
visibilityEvent.getContent().history_visibility;
1319+
if (visibility == "world_readable" || visibility == "shared") {
1320+
keySharingWarning =
1321+
<div>
1322+
{_t("Note: Decryption keys for old messages will be shared with invited users.")}
1323+
</div>;
1324+
}
1325+
}
12841326
} else if (this.props.kind === KIND_CALL_TRANSFER) {
12851327
title = _t("Transfer");
12861328
buttonText = _t("Transfer");
@@ -1314,6 +1356,7 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
13141356
{spinner}
13151357
</div>
13161358
</div>
1359+
{keySharingWarning}
13171360
{this._renderIdentityServerWarning()}
13181361
<div className='error'>{this.state.errorText}</div>
13191362
<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
@@ -791,6 +791,7 @@
791791
"Show message previews for reactions in DMs": "Show message previews for reactions in DMs",
792792
"Show message previews for reactions in all rooms": "Show message previews for reactions in all rooms",
793793
"Offline encrypted messaging using dehydrated devices": "Offline encrypted messaging using dehydrated devices",
794+
"Share decryption keys for room history when inviting users": "Share decryption keys for room history when inviting users",
794795
"Enable advanced debugging for the room list": "Enable advanced debugging for the room list",
795796
"Show info about bridges in room settings": "Show info about bridges in room settings",
796797
"Font size": "Font size",
@@ -2153,6 +2154,7 @@
21532154
"Go": "Go",
21542155
"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>.",
21552156
"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>.",
2157+
"Note: Decryption keys for old messages will be shared with invited users.": "Note: Decryption keys for old messages will be shared with invited users.",
21562158
"Transfer": "Transfer",
21572159
"a new master key signature": "a new master key signature",
21582160
"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
@@ -214,6 +214,12 @@ export const SETTINGS: {[setting: string]: ISetting} = {
214214
supportedLevels: LEVELS_FEATURE,
215215
default: false,
216216
},
217+
"feature_room_history_key_sharing": {
218+
isFeature: true,
219+
displayName: _td("Share decryption keys for room history when inviting users"),
220+
supportedLevels: LEVELS_FEATURE,
221+
default: false,
222+
},
217223
"advancedRoomListLogging": {
218224
// TODO: Remove flag before launch: https://github.com/vector-im/element-web/issues/14231
219225
displayName: _td("Enable advanced debugging for the room list"),

0 commit comments

Comments
 (0)