From 40128c7ff6436e0106e92b501ae758e9c851db53 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 4 Aug 2021 13:35:33 +0530 Subject: [PATCH] Set pl from room response Signed-off-by: RMidhunSuresh --- src/matrix/room/Room.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index c49d6a4e..7b75d361 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -23,6 +23,7 @@ import {WrappedError} from "../error.js" import {Heroes} from "./members/Heroes.js"; import {AttachmentUpload} from "./AttachmentUpload.js"; import {DecryptionSource} from "../e2ee/common.js"; +import {PowerLevels, EVENT_TYPE as POWERLEVELS_EVENT_TYPE } from "./timeline/PowerLevels.js"; const EVENT_ENCRYPTED_TYPE = "m.room.encrypted"; @@ -173,6 +174,7 @@ export class Room extends BaseRoom { if (Array.isArray(roomResponse.timeline?.events)) { removedPendingEvents = await this._sendQueue.removeRemoteEchos(roomResponse.timeline.events, txn, log); } + this._updatePowerLevels(roomResponse); return { summaryChanges, roomEncryption, @@ -262,6 +264,18 @@ export class Room extends BaseRoom { } } + _updatePowerLevels(roomResponse) { + const powerLevelEvent = roomResponse.timeline.events.find(event => event.type === POWERLEVELS_EVENT_TYPE); + if (powerLevelEvent && this._powerLevels) { + const newPowerLevels = new PowerLevels({ + powerLevelEvent, + ownUserId: this._user.id, + membership: this.membership, + }); + this._powerLevels.set(newPowerLevels); + } + } + needsAfterSyncCompleted({shouldFlushKeyShares}) { return shouldFlushKeyShares; }