From 85b6f157c1314d51b904f62cdef5080cf690efce Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 30 Aug 2018 12:01:13 +0200 Subject: [PATCH] only patch m.direct data on server once per session to avoid request storm --- src/utils/DMRoomMap.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils/DMRoomMap.js b/src/utils/DMRoomMap.js index 1db8e7f970..ff0a7cbbf0 100644 --- a/src/utils/DMRoomMap.js +++ b/src/utils/DMRoomMap.js @@ -27,6 +27,8 @@ export default class DMRoomMap { constructor(matrixClient) { this.matrixClient = matrixClient; this.roomToUser = null; + // see _onAccountData + this._hasSentOutPatchDirectAccountDataPatch = false; // XXX: Force-bind the event handler method because it // doesn't call it with our object as the 'this' @@ -75,7 +77,13 @@ export default class DMRoomMap { const selfDMs = userToRooms[myUserId]; if (selfDMs && selfDMs.length) { this._patchUpSelfDMs(userToRooms); - this.matrixClient.setAccountData('m.direct', userToRooms); + // to avoid multiple devices fighting to correct + // the account data, only try to send the corrected + // version once. + if (!this._hasSentOutPatchDirectAccountDataPatch) { + this._hasSentOutPatchDirectAccountDataPatch = true; + this.matrixClient.setAccountData('m.direct', userToRooms); + } } this.userToRooms = userToRooms; this._populateRoomToUser();