1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

encrypt for invited users if history visibility allows.

fixes https://github.com/vector-im/riot-web/issues/2713
This commit is contained in:
Matthew Hodgson
2018-07-05 01:45:45 +02:00
parent 0415f821eb
commit d8d35f4022
4 changed files with 31 additions and 6 deletions

View File

@@ -536,8 +536,7 @@ MegolmEncryption.prototype._checkForUnknownDevices = function(devicesInRoom) {
* from userId to deviceId to deviceInfo * from userId to deviceId to deviceInfo
*/ */
MegolmEncryption.prototype._getDevicesInRoom = function(room) { MegolmEncryption.prototype._getDevicesInRoom = function(room) {
// XXX what about rooms where invitees can see the content? const roomMembers = utils.map(room.getEncryptionTargetMembers(), function(u) {
const roomMembers = utils.map(room.getJoinedMembers(), function(u) {
return u.userId; return u.userId;
}); });

View File

@@ -89,7 +89,7 @@ OlmEncryption.prototype.encryptMessage = function(room, eventType, content) {
// TODO: there is a race condition here! What if a new user turns up // TODO: there is a race condition here! What if a new user turns up
// just as you are sending a secret message? // just as you are sending a secret message?
const users = utils.map(room.getJoinedMembers(), function(u) { const users = utils.map(room.getEncryptionTargetMembers(), function(u) {
return u.userId; return u.userId;
}); });

View File

@@ -652,7 +652,7 @@ Crypto.prototype.setRoomEncryption = async function(roomId, config, inhibitDevic
throw new Error(`Unable to enable encryption in unknown room ${roomId}`); throw new Error(`Unable to enable encryption in unknown room ${roomId}`);
} }
const members = room.getJoinedMembers(); const members = room.getEncryptionTargetMembers();
members.forEach((m) => { members.forEach((m) => {
this._deviceList.startTrackingDeviceList(m.userId); this._deviceList.startTrackingDeviceList(m.userId);
}); });
@@ -986,7 +986,7 @@ Crypto.prototype._evalDeviceListChanges = async function(deviceLists) {
Crypto.prototype._getE2eUsers = function() { Crypto.prototype._getE2eUsers = function() {
const e2eUserIds = []; const e2eUserIds = [];
for (const room of this._getE2eRooms()) { for (const room of this._getE2eRooms()) {
const members = room.getJoinedMembers(); const members = room.getEncryptionTargetMembers();
for (const member of members) { for (const member of members) {
e2eUserIds.push(member.userId); e2eUserIds.push(member.userId);
} }
@@ -1086,6 +1086,11 @@ Crypto.prototype._onRoomMembership = function(event, member, oldMembership) {
// make sure we are tracking the deviceList for this user // make sure we are tracking the deviceList for this user
this._deviceList.startTrackingDeviceList(member.userId); this._deviceList.startTrackingDeviceList(member.userId);
} }
else if (member.membership == 'invite' &&
this._clientStore.getRoom(roomId).shouldEncryptForInvitedUsers()) {
console.log('Invite event for ' + member.userId + ' in ' + roomId);
this._deviceList.startTrackingDeviceList(member.userId);
}
alg.onRoomMembership(event, member, oldMembership); alg.onRoomMembership(event, member, oldMembership);
}; };

View File

@@ -456,6 +456,28 @@ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline,
}); });
}; };
/**
* Get a list of members we should be encrypting for in this room
* @return {RoomMember[]} A list of members who we should encrypt messages for
* in this room.
*/
Room.prototype.getEncryptionTargetMembers = function() {
let members = this.getMembersWithMembership("join");
if (this.shouldEncryptForInvitedMembers()) {
members = members.concat(this.getMembersWithMembership("invite"));
}
return members;
};
/**
* Determine whether we should encrypt messages for invited users in this room
* @return {boolean} if we should encrypt messages for invited users
*/
Room.prototype.shouldEncryptForInvitedMembers = function() {
const ev = this.currentState.getStateEvents("m.room.history_visibility", "");
return (ev && ev.getContent() && ev.getContent().history_visibility !== "joined");
};
/** /**
* Get the default room name (i.e. what a given user would see if the * Get the default room name (i.e. what a given user would see if the
* room had no m.room.name) * room had no m.room.name)
@@ -950,7 +972,6 @@ Room.prototype.recalculate = function(userId) {
} }
}; };
/** /**
* Get a list of user IDs who have <b>read up to</b> the given event. * Get a list of user IDs who have <b>read up to</b> the given event.
* @param {MatrixEvent} event the event to get read receipts for. * @param {MatrixEvent} event the event to get read receipts for.