From a8642682d0e326c47872e98e1cebeadc39b404bf Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 6 Jul 2017 16:05:40 +0100 Subject: [PATCH] Remove m.new_device support We now rely on the server to track new devices, and tell us about them when users add them, rather than forcing devices to announce themselves (see https://github.com/vector-im/riot-web/issues/2305 for the whole backstory there). The necessary support for that has now been in all the clients and the server for several months (since March or so). I now want to get rid of the localstorage store, which this code is relying on, so now seems like a good time to get rid of it. Yay. --- spec/integ/matrix-client-crypto.spec.js | 54 ---------------- src/crypto/index.js | 84 ------------------------- src/store/session/webstorage.js | 17 ----- 3 files changed, 155 deletions(-) diff --git a/spec/integ/matrix-client-crypto.spec.js b/spec/integ/matrix-client-crypto.spec.js index 9d59d6a996d..5ea3e9430ae 100644 --- a/spec/integ/matrix-client-crypto.spec.js +++ b/spec/integ/matrix-client-crypto.spec.js @@ -647,60 +647,6 @@ describe("MatrixClient crypto", function() { }).then(aliRecvMessage); }); - - it("Ali does a key query when she gets a new_device event", function() { - return q() - .then(() => aliTestClient.start()) - .then(() => firstSync(aliTestClient)) - - // ali will only care about bob's new_device if she is tracking - // bob's devices, which she will do if we enable encryption - .then(aliEnablesEncryption) - - .then(() => { - aliTestClient.expectKeyQuery({ - device_keys: { - [aliUserId]: {}, - [bobUserId]: {}, - }, - }); - return aliTestClient.httpBackend.flush('/keys/query', 1); - }) - - // make sure that the initial key download has completed - // (downloadKeys will wait until it does) - .then(() => { - return aliTestClient.client.downloadKeys([bobUserId]); - }) - - .then(function() { - const syncData = { - next_batch: '2', - to_device: { - events: [ - testUtils.mkEvent({ - content: { - device_id: 'TEST_DEVICE', - rooms: [], - }, - sender: bobUserId, - type: 'm.new_device', - }), - ], - }, - }; - aliTestClient.httpBackend.when('GET', '/sync').respond(200, syncData); - return aliTestClient.httpBackend.flush('/sync', 1); - }).then(() => { - aliTestClient.expectKeyQuery({ - device_keys: { - [bobUserId]: {}, - }, - }); - return aliTestClient.httpBackend.flush('/keys/query', 1); - }); - }); - it("Ali does a key query when encryption is enabled", function() { // enabling encryption in the room should make alice download devices // for both members. diff --git a/src/crypto/index.js b/src/crypto/index.js index 2e50fec38af..8417384b31d 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -155,8 +155,6 @@ function _registerEventHandlers(crypto, eventEmitter) { if (event.getType() == "m.room_key" || event.getType() == "m.forwarded_room_key") { crypto._onRoomKeyEvent(event); - } else if (event.getType() == "m.new_device") { - crypto._onNewDeviceEvent(event); } else if (event.getType() == "m.room_key_request") { crypto._onRoomKeyRequestEvent(event); } @@ -875,9 +873,6 @@ Crypto.prototype._onSyncCompleted = function(syncData) { if (!syncData.oldSyncToken) { console.log("Completed initial sync"); - // an initialsync. - this._sendNewDeviceEvents(); - // if we have a deviceSyncToken, we can tell the deviceList to // invalidate devices which have changed since then. const oldSyncToken = this._sessionStore.getEndToEndDeviceSyncToken(); @@ -926,57 +921,6 @@ Crypto.prototype._onSyncCompleted = function(syncData) { } }; -/** - * Send m.new_device messages to any devices we share a room with. - * - * (TODO: we can get rid of this once a suitable number of homeservers and - * clients support the more reliable device list update stream mechanism) - * - * @private - */ -Crypto.prototype._sendNewDeviceEvents = function() { - if (this._sessionStore.getDeviceAnnounced()) { - return; - } - - // we need to tell all the devices in all the rooms we are members of that - // we have arrived. - // build a list of rooms for each user. - const roomsByUser = {}; - for (const room of this._getE2eRooms()) { - const members = room.getJoinedMembers(); - for (let j = 0; j < members.length; j++) { - const m = members[j]; - if (!roomsByUser[m.userId]) { - roomsByUser[m.userId] = []; - } - roomsByUser[m.userId].push(room.roomId); - } - } - - // build a per-device message for each user - const content = {}; - for (const userId in roomsByUser) { - if (!roomsByUser.hasOwnProperty(userId)) { - continue; - } - content[userId] = { - "*": { - device_id: this._deviceId, - rooms: roomsByUser[userId], - }, - }; - } - - const self = this; - this._baseApis.sendToDevice( - "m.new_device", // OH HAI! - content, - ).done(function() { - self._sessionStore.setDeviceAnnounced(); - }); -}; - /** * Ask the server which users have new devices since a given token, * and invalidate them @@ -1083,34 +1027,6 @@ Crypto.prototype._onRoomMembership = function(event, member, oldMembership) { }; -/** - * Called when a new device announces itself - * - * @private - * @param {module:models/event.MatrixEvent} event announcement event - */ -Crypto.prototype._onNewDeviceEvent = function(event) { - const content = event.getContent(); - const userId = event.getSender(); - const deviceId = content.device_id; - const rooms = content.rooms; - - if (!rooms || !deviceId) { - console.warn("new_device event missing keys"); - return; - } - - console.log("m.new_device event from " + userId + ":" + deviceId + - " for rooms " + rooms); - - if (this.getStoredDevice(userId, deviceId)) { - console.log("Known device; ignoring"); - return; - } - - this._deviceList.invalidateUserDeviceList(userId); -}; - /** * Called when we get an m.room_key_request event. * diff --git a/src/store/session/webstorage.js b/src/store/session/webstorage.js index 07bfa74eeba..53220cb5e40 100644 --- a/src/store/session/webstorage.js +++ b/src/store/session/webstorage.js @@ -65,22 +65,6 @@ WebStorageSessionStore.prototype = { return this.store.getItem(KEY_END_TO_END_ACCOUNT); }, - /** - * Store a flag indicating that we have announced the new device. - */ - setDeviceAnnounced: function() { - this.store.setItem(KEY_END_TO_END_ANNOUNCED, "true"); - }, - - /** - * Check if the "device announced" flag is set - * - * @return {boolean} true if the "device announced" flag has been set. - */ - getDeviceAnnounced: function() { - return this.store.getItem(KEY_END_TO_END_ANNOUNCED) == "true"; - }, - /** * Stores the known devices for a user. * @param {string} userId The user's ID. @@ -208,7 +192,6 @@ WebStorageSessionStore.prototype = { }; const KEY_END_TO_END_ACCOUNT = E2E_PREFIX + "account"; -const KEY_END_TO_END_ANNOUNCED = E2E_PREFIX + "announced"; const KEY_END_TO_END_DEVICE_SYNC_TOKEN = E2E_PREFIX + "device_sync_token"; const KEY_END_TO_END_DEVICE_LIST_TRACKING_STATUS = E2E_PREFIX + "device_tracking";