don't store or return our own device

This commit is contained in:
Bruno Windels 2020-09-03 15:28:03 +02:00
parent eda15e1141
commit e22131bf57
2 changed files with 14 additions and 2 deletions

View File

@ -50,6 +50,8 @@ export class Session {
storage, storage,
getSyncToken: () => this.syncToken, getSyncToken: () => this.syncToken,
olmUtil: this._olmUtil, olmUtil: this._olmUtil,
ownUserId: sessionInfo.userId,
ownDeviceId: sessionInfo.deviceId,
}); });
} }
} }

View File

@ -34,11 +34,13 @@ function deviceKeysAsDeviceIdentity(deviceSection) {
} }
export class DeviceTracker { export class DeviceTracker {
constructor({storage, getSyncToken, olmUtil}) { constructor({storage, getSyncToken, olmUtil, ownUserId, ownDeviceId}) {
this._storage = storage; this._storage = storage;
this._getSyncToken = getSyncToken; this._getSyncToken = getSyncToken;
this._identityChangedForRoom = null; this._identityChangedForRoom = null;
this._olmUtil = olmUtil; this._olmUtil = olmUtil;
this._ownUserId = ownUserId;
this._ownDeviceId = ownDeviceId;
} }
async writeDeviceChanges(deviceLists, txn) { async writeDeviceChanges(deviceLists, txn) {
@ -198,6 +200,10 @@ export class DeviceTracker {
if (deviceIdOnKeys !== deviceId) { if (deviceIdOnKeys !== deviceId) {
return false; return false;
} }
// don't store our own device
if (userId === this._ownUserId && deviceId === this._ownDeviceId) {
return false;
}
return this._hasValidSignature(deviceKeys); return this._hasValidSignature(deviceKeys);
}); });
const verifiedKeys = verifiedEntries.map(([, deviceKeys]) => deviceKeys); const verifiedKeys = verifiedEntries.map(([, deviceKeys]) => deviceKeys);
@ -258,6 +264,10 @@ export class DeviceTracker {
if (queriedDevices && queriedDevices.length) { if (queriedDevices && queriedDevices.length) {
flattenedDevices = flattenedDevices.concat(queriedDevices); flattenedDevices = flattenedDevices.concat(queriedDevices);
} }
return flattenedDevices; // filter out our own devices if it got in somehow (even though we should not store it)
const devices = flattenedDevices.filter(device => {
return !(device.userId === this._ownUserId && device.deviceId === this._ownDeviceId);
});
return devices;
} }
} }