From 402a5e5d54c2c905c44e2befe3348ed03177dafb Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 12 May 2021 18:26:55 +0200 Subject: [PATCH 1/3] fix room list sorting not keeping sorting position after clearing unread --- src/domain/session/leftpanel/BaseTileViewModel.js | 5 ++--- src/domain/session/leftpanel/LeftPanelViewModel.js | 7 ++++--- src/domain/session/leftpanel/RoomTileViewModel.js | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/domain/session/leftpanel/BaseTileViewModel.js b/src/domain/session/leftpanel/BaseTileViewModel.js index 360f2b3959..684bbf1f5d 100644 --- a/src/domain/session/leftpanel/BaseTileViewModel.js +++ b/src/domain/session/leftpanel/BaseTileViewModel.js @@ -25,9 +25,6 @@ export class BaseTileViewModel extends ViewModel { super(options); this._isOpen = false; this._hidden = false; - if (options.isOpen) { - this.open(); - } } get hidden() { @@ -52,7 +49,9 @@ export class BaseTileViewModel extends ViewModel { if (!this._isOpen) { this._isOpen = true; this.emitChange("isOpen"); + return true; } + return false; } get isOpen() { diff --git a/src/domain/session/leftpanel/LeftPanelViewModel.js b/src/domain/session/leftpanel/LeftPanelViewModel.js index a1a577a9ee..6503c124db 100644 --- a/src/domain/session/leftpanel/LeftPanelViewModel.js +++ b/src/domain/session/leftpanel/LeftPanelViewModel.js @@ -37,14 +37,15 @@ export class LeftPanelViewModel extends ViewModel { _mapTileViewModels(rooms, invites) { // join is not commutative, invites will take precedence over rooms return invites.join(rooms).mapValues((roomOrInvite, emitChange) => { - const isOpen = this.navigation.path.get("room")?.value === roomOrInvite.id; let vm; if (roomOrInvite.isInvite) { - vm = new InviteTileViewModel(this.childOptions({isOpen, invite: roomOrInvite, emitChange})); + vm = new InviteTileViewModel(this.childOptions({invite: roomOrInvite, emitChange})); } else { - vm = new RoomTileViewModel(this.childOptions({isOpen, room: roomOrInvite, emitChange})); + vm = new RoomTileViewModel(this.childOptions({room: roomOrInvite, emitChange})); } + const isOpen = this.navigation.path.get("room")?.value === roomOrInvite.id; if (isOpen) { + vm.open(); this._updateCurrentVM(vm); } return vm; diff --git a/src/domain/session/leftpanel/RoomTileViewModel.js b/src/domain/session/leftpanel/RoomTileViewModel.js index 50164b1887..fe199ff1bc 100644 --- a/src/domain/session/leftpanel/RoomTileViewModel.js +++ b/src/domain/session/leftpanel/RoomTileViewModel.js @@ -105,4 +105,10 @@ export class RoomTileViewModel extends BaseTileViewModel { get _avatarSource() { return this._room; } + + open() { + if (super.open()) { + this._wasUnreadWhenOpening = this._room.isUnread; + } + } } From 86d60496c0be21ce19a7d4528a1720cf01adcb56 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 12 May 2021 18:28:39 +0200 Subject: [PATCH 2/3] Don't move read rooms to lower sorting position --- .../session/leftpanel/RoomTileViewModel.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/domain/session/leftpanel/RoomTileViewModel.js b/src/domain/session/leftpanel/RoomTileViewModel.js index fe199ff1bc..eebea61834 100644 --- a/src/domain/session/leftpanel/RoomTileViewModel.js +++ b/src/domain/session/leftpanel/RoomTileViewModel.js @@ -17,16 +17,11 @@ limitations under the License. import {BaseTileViewModel} from "./BaseTileViewModel.js"; -function isSortedAsUnread(vm) { - return vm.isUnread || (vm.isOpen && vm._wasUnreadWhenOpening); -} - export class RoomTileViewModel extends BaseTileViewModel { constructor(options) { super(options); const {room} = options; this._room = room; - this._wasUnreadWhenOpening = false; this._url = this.urlCreator.openRoomActionUrl(this._room.id); } @@ -57,12 +52,6 @@ export class RoomTileViewModel extends BaseTileViewModel { } return -1; } - if (isSortedAsUnread(this) !== isSortedAsUnread(other)) { - if (isSortedAsUnread(this)) { - return -1; - } - return 1; - } const myTimestamp = myRoom.lastMessageTimestamp; const theirTimestamp = theirRoom.lastMessageTimestamp; const myTimestampValid = Number.isSafeInteger(myTimestamp); @@ -105,10 +94,4 @@ export class RoomTileViewModel extends BaseTileViewModel { get _avatarSource() { return this._room; } - - open() { - if (super.open()) { - this._wasUnreadWhenOpening = this._room.isUnread; - } - } } From 56699baaf11c7fb7b6016033c39c5b6ec2c9ef86 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 12 May 2021 18:31:13 +0200 Subject: [PATCH 3/3] dont need this anymore --- src/domain/session/leftpanel/BaseTileViewModel.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/domain/session/leftpanel/BaseTileViewModel.js b/src/domain/session/leftpanel/BaseTileViewModel.js index 684bbf1f5d..62ea638054 100644 --- a/src/domain/session/leftpanel/BaseTileViewModel.js +++ b/src/domain/session/leftpanel/BaseTileViewModel.js @@ -49,9 +49,7 @@ export class BaseTileViewModel extends ViewModel { if (!this._isOpen) { this._isOpen = true; this.emitChange("isOpen"); - return true; } - return false; } get isOpen() {