From 6a9cbf7f33abc9180a1da1f825434169e41dc83c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 27 Aug 2020 20:52:51 +0200 Subject: [PATCH] store and sort by m.lowpriority tag --- .../session/roomlist/RoomTileViewModel.js | 7 +++++++ src/matrix/room/Room.js | 5 +++++ src/matrix/room/RoomSummary.js | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/domain/session/roomlist/RoomTileViewModel.js b/src/domain/session/roomlist/RoomTileViewModel.js index e586bbd1..1882438f 100644 --- a/src/domain/session/roomlist/RoomTileViewModel.js +++ b/src/domain/session/roomlist/RoomTileViewModel.js @@ -73,6 +73,13 @@ export class RoomTileViewModel extends ViewModel { return result; } log(`comparing ${myRoom.name || theirRoom.id} and ${theirRoom.name || theirRoom.id} ...`); + log("comparing isLowPriority..."); + if (myRoom.isLowPriority !== theirRoom.isLowPriority) { + if (myRoom.isLowPriority) { + return logResult(1); + } + return logResult(-1); + } log("comparing isUnread..."); if (isSortedAsUnread(this) !== isSortedAsUnread(other)) { if (isSortedAsUnread(this)) { diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 1bb8371b..27031203 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -251,6 +251,11 @@ export class Room extends EventEmitter { return this._summary.highlightCount; } + get isLowPriority() { + const tags = this._summary.tags; + return !!(tags && tags['m.lowpriority']); + } + async _getLastEventId() { const lastKey = this._syncWriter.lastMessageKey; if (lastKey) { diff --git a/src/matrix/room/RoomSummary.js b/src/matrix/room/RoomSummary.js index b3758d23..e910c4bc 100644 --- a/src/matrix/room/RoomSummary.js +++ b/src/matrix/room/RoomSummary.js @@ -22,6 +22,9 @@ function applySyncResponse(data, roomResponse, membership, isInitialSync, isTime data = data.cloneIfNeeded(); data.membership = membership; } + if (roomResponse.account_data) { + data = roomResponse.account_data.events.reduce(processRoomAccountData, data); + } // state comes before timeline if (roomResponse.state) { data = roomResponse.state.events.reduce(processStateEvent, data); @@ -51,6 +54,18 @@ function applySyncResponse(data, roomResponse, membership, isInitialSync, isTime return data; } +function processRoomAccountData(data, event) { + if (event?.type === "m.tag") { + let tags = event?.content?.tags; + if (!tags || Array.isArray(tags) || typeof tags !== "object") { + tags = null; + } + data = data.cloneIfNeeded(); + data.tags = tags; + } + return data; +} + function processStateEvent(data, event) { if (event.type === "m.room.encryption") { if (!data.isEncrypted) { @@ -133,6 +148,7 @@ class SummaryData { this.avatarUrl = copy ? copy.avatarUrl : null; this.notificationCount = copy ? copy.notificationCount : 0; this.highlightCount = copy ? copy.highlightCount : 0; + this.tags = copy ? copy.tags : null; this.cloned = copy ? true : false; } @@ -218,6 +234,10 @@ export class RoomSummary { return this._data.lastPaginationToken; } + get tags() { + return this._data.tags; + } + writeClearUnread(txn) { const data = new SummaryData(this._data); data.isUnread = false;