Merge pull request #1075 from vector-im/fix-broken-key-share

Update code in RoomEncryption to use device_id and user_id
This commit is contained in:
Bruno Windels 2023-04-14 14:34:17 +02:00 committed by GitHub
commit 7a726ff8e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -183,6 +183,16 @@ export class Member {
return this.callDeviceMembership.device_id; return this.callDeviceMembership.device_id;
} }
/** @internal, to emulate deviceKey properties when calling formatToDeviceMessagesPayload */
get user_id(): string {
return this.userId;
}
/** @internal, to emulate deviceKey properties when calling formatToDeviceMessagesPayload */
get device_id(): string {
return this.deviceId;
}
/** session id of the member */ /** session id of the member */
get sessionId(): string { get sessionId(): string {
return this.callDeviceMembership.session_id; return this.callDeviceMembership.session_id;

View File

@ -33,11 +33,11 @@ export function isTxnId(txnId) {
} }
export function formatToDeviceMessagesPayload(messages) { export function formatToDeviceMessagesPayload(messages) {
const messagesByUser = groupBy(messages, message => message.device.userId); const messagesByUser = groupBy(messages, message => message.device.user_id);
const payload = { const payload = {
messages: Array.from(messagesByUser.entries()).reduce((userMap, [userId, messages]) => { messages: Array.from(messagesByUser.entries()).reduce((userMap, [userId, messages]) => {
userMap[userId] = messages.reduce((deviceMap, message) => { userMap[userId] = messages.reduce((deviceMap, message) => {
deviceMap[message.device.deviceId] = message.content; deviceMap[message.device.device_id] = message.content;
return deviceMap; return deviceMap;
}, {}); }, {});
return userMap; return userMap;

View File

@ -353,7 +353,7 @@ export class RoomEncryption {
this._historyVisibility = await this._loadHistoryVisibilityIfNeeded(this._historyVisibility); this._historyVisibility = await this._loadHistoryVisibilityIfNeeded(this._historyVisibility);
await this._deviceTracker.trackRoom(this._room, this._historyVisibility, log); await this._deviceTracker.trackRoom(this._room, this._historyVisibility, log);
const devices = await this._deviceTracker.devicesForTrackedRoom(this._room.id, hsApi, log); const devices = await this._deviceTracker.devicesForTrackedRoom(this._room.id, hsApi, log);
const userIds = Array.from(devices.reduce((set, device) => set.add(device.userId), new Set())); const userIds = Array.from(devices.reduce((set, device) => set.add(device.user_id), new Set()));
let writeOpTxn = await this._storage.readWriteTxn([this._storage.storeNames.operations]); let writeOpTxn = await this._storage.readWriteTxn([this._storage.storeNames.operations]);
let operation; let operation;
@ -431,8 +431,8 @@ export class RoomEncryption {
await log.wrap("send", log => this._sendMessagesToDevices(ENCRYPTED_TYPE, messages, hsApi, log)); await log.wrap("send", log => this._sendMessagesToDevices(ENCRYPTED_TYPE, messages, hsApi, log));
if (missingDevices.length) { if (missingDevices.length) {
await log.wrap("missingDevices", async log => { await log.wrap("missingDevices", async log => {
log.set("devices", missingDevices.map(d => d.deviceId)); log.set("devices", missingDevices.map(d => d.device_id));
const unsentUserIds = operation.userIds.filter(userId => missingDevices.some(d => d.userId === userId)); const unsentUserIds = operation.userIds.filter(userId => missingDevices.some(d => d.user_id === userId));
log.set("unsentUserIds", unsentUserIds); log.set("unsentUserIds", unsentUserIds);
operation.userIds = unsentUserIds; operation.userIds = unsentUserIds;
// first remove the users that we've sent the keys already from the operation, // first remove the users that we've sent the keys already from the operation,
@ -459,11 +459,11 @@ export class RoomEncryption {
// TODO: make this use _sendMessagesToDevices // TODO: make this use _sendMessagesToDevices
async _sendSharedMessageToDevices(type, message, devices, hsApi, log) { async _sendSharedMessageToDevices(type, message, devices, hsApi, log) {
const devicesByUser = groupBy(devices, device => device.userId); const devicesByUser = groupBy(devices, device => device.user_id);
const payload = { const payload = {
messages: Array.from(devicesByUser.entries()).reduce((userMap, [userId, devices]) => { messages: Array.from(devicesByUser.entries()).reduce((userMap, [userId, devices]) => {
userMap[userId] = devices.reduce((deviceMap, device) => { userMap[userId] = devices.reduce((deviceMap, device) => {
deviceMap[device.deviceId] = message; deviceMap[device.device_id] = message;
return deviceMap; return deviceMap;
}, {}); }, {});
return userMap; return userMap;