From ee0eda794757c426db1c55c1b9b009a36ed43f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 11 Aug 2021 17:54:18 +0200 Subject: [PATCH 1/7] Add ignoreSelfEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../algorithms/tag-sorting/RecentAlgorithm.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts index f47458d1b1..23fff70eef 100644 --- a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts +++ b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts @@ -20,6 +20,25 @@ import { IAlgorithm } from "./IAlgorithm"; import { MatrixClientPeg } from "../../../../MatrixClientPeg"; import * as Unread from "../../../../Unread"; import { EffectiveMembership, getEffectiveMembership } from "../../../../utils/membership"; +import { EventType } from "matrix-js-sdk/src/@types/event"; +import { MatrixEvent } from "matrix-js-sdk/src/models/event"; + +const ignoreSelfEvent = (event: MatrixEvent): boolean => { + const type = event.getType(); + const content = event.getContent(); + const prevContent = event.getPrevContent(); + + // Never ignore membership changes + if (type === EventType.RoomMember && prevContent.membership !== content.membership) return false; + + // Ignore status changes + // XXX: This should be an enum + if (type === "im.vector.user_status") return true; + // Ignore display name changes + if (type === EventType.RoomMember && prevContent.displayname !== content.displayname) return true; + + return false; +}; export const sortRooms = (rooms: Room[]): Room[] => { // We cache the timestamp lookup to avoid iterating forever on the timeline From 1f98ea4562844a64157e9629b184903bc017a068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 11 Aug 2021 17:54:27 +0200 Subject: [PATCH 2/7] Use ignoreSelfEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../room-list/algorithms/tag-sorting/RecentAlgorithm.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts index 23fff70eef..539cfde726 100644 --- a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts +++ b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts @@ -87,7 +87,10 @@ export const sortRooms = (rooms: Room[]): Room[] => { const ev = r.timeline[i]; if (!ev.getTs()) continue; // skip events that don't have timestamps (tests only?) - if (ev.getSender() === myUserId || Unread.eventTriggersUnreadCount(ev)) { + if ( + (ev.getSender() === myUserId && !ignoreSelfEvent(ev)) || + Unread.eventTriggersUnreadCount(ev) + ) { return ev.getTs(); } } From f2dccbc9f7bc58ee46609c31650d3f18af6cde28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 12 Aug 2021 09:38:57 +0200 Subject: [PATCH 3/7] Use function syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../room-list/algorithms/tag-sorting/RecentAlgorithm.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts index 539cfde726..5ddfd96c8a 100644 --- a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts +++ b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts @@ -23,7 +23,7 @@ import { EffectiveMembership, getEffectiveMembership } from "../../../../utils/m import { EventType } from "matrix-js-sdk/src/@types/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; -const ignoreSelfEvent = (event: MatrixEvent): boolean => { +export function ignoreSelfEvent(event: MatrixEvent): boolean { const type = event.getType(); const content = event.getContent(); const prevContent = event.getPrevContent(); @@ -38,7 +38,7 @@ const ignoreSelfEvent = (event: MatrixEvent): boolean => { if (type === EventType.RoomMember && prevContent.displayname !== content.displayname) return true; return false; -}; +} export const sortRooms = (rooms: Room[]): Room[] => { // We cache the timestamp lookup to avoid iterating forever on the timeline From 0a4a1506d412cdec610196af73fca6401fead15b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 12 Aug 2021 09:40:26 +0200 Subject: [PATCH 4/7] Use ignoreSelfEvent in the RoomListStore (which doesn't work!) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/stores/room-list/RoomListStore.ts | 4 ++++ .../room-list/algorithms/tag-sorting/RecentAlgorithm.ts | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/stores/room-list/RoomListStore.ts b/src/stores/room-list/RoomListStore.ts index 1a5ef0484e..6a80bcd1e5 100644 --- a/src/stores/room-list/RoomListStore.ts +++ b/src/stores/room-list/RoomListStore.ts @@ -38,6 +38,7 @@ import { SpaceWatcher } from "./SpaceWatcher"; import SpaceStore from "../SpaceStore"; import { Action } from "../../dispatcher/actions"; import { SettingUpdatedPayload } from "../../dispatcher/payloads/SettingUpdatedPayload"; +import { ignoreSelfEvent } from "./algorithms/tag-sorting/RecentAlgorithm"; interface IState { tagsEnabled?: boolean; @@ -270,6 +271,9 @@ export class RoomListStoreClass extends AsyncStoreWithClient { // Ignore non-live events (backfill) if (!eventPayload.isLiveEvent || !payload.isLiveUnfilteredRoomTimelineEvent) return; + // Avoid re-ordering on status, profile etc. changes + if (ignoreSelfEvent(eventPayload.event)) return; + const roomId = eventPayload.event.getRoomId(); const room = this.matrixClient.getRoom(roomId); const tryUpdate = async (updatedRoom: Room) => { diff --git a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts index 5ddfd96c8a..bbfac876bc 100644 --- a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts +++ b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts @@ -87,10 +87,7 @@ export const sortRooms = (rooms: Room[]): Room[] => { const ev = r.timeline[i]; if (!ev.getTs()) continue; // skip events that don't have timestamps (tests only?) - if ( - (ev.getSender() === myUserId && !ignoreSelfEvent(ev)) || - Unread.eventTriggersUnreadCount(ev) - ) { + if (ev.getSender() === myUserId || Unread.eventTriggersUnreadCount(ev)) { return ev.getTs(); } } From b7df1127bd7782ba143f71bffc2f19a6691f3eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 25 Aug 2021 08:38:47 +0200 Subject: [PATCH 5/7] Revert "Use ignoreSelfEvent in the RoomListStore (which doesn't work!)" This reverts commit 0a4a1506d412cdec610196af73fca6401fead15b. --- src/stores/room-list/RoomListStore.ts | 4 ---- .../room-list/algorithms/tag-sorting/RecentAlgorithm.ts | 5 ++++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/stores/room-list/RoomListStore.ts b/src/stores/room-list/RoomListStore.ts index 6a80bcd1e5..1a5ef0484e 100644 --- a/src/stores/room-list/RoomListStore.ts +++ b/src/stores/room-list/RoomListStore.ts @@ -38,7 +38,6 @@ import { SpaceWatcher } from "./SpaceWatcher"; import SpaceStore from "../SpaceStore"; import { Action } from "../../dispatcher/actions"; import { SettingUpdatedPayload } from "../../dispatcher/payloads/SettingUpdatedPayload"; -import { ignoreSelfEvent } from "./algorithms/tag-sorting/RecentAlgorithm"; interface IState { tagsEnabled?: boolean; @@ -271,9 +270,6 @@ export class RoomListStoreClass extends AsyncStoreWithClient { // Ignore non-live events (backfill) if (!eventPayload.isLiveEvent || !payload.isLiveUnfilteredRoomTimelineEvent) return; - // Avoid re-ordering on status, profile etc. changes - if (ignoreSelfEvent(eventPayload.event)) return; - const roomId = eventPayload.event.getRoomId(); const room = this.matrixClient.getRoom(roomId); const tryUpdate = async (updatedRoom: Room) => { diff --git a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts index bbfac876bc..5ddfd96c8a 100644 --- a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts +++ b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts @@ -87,7 +87,10 @@ export const sortRooms = (rooms: Room[]): Room[] => { const ev = r.timeline[i]; if (!ev.getTs()) continue; // skip events that don't have timestamps (tests only?) - if (ev.getSender() === myUserId || Unread.eventTriggersUnreadCount(ev)) { + if ( + (ev.getSender() === myUserId && !ignoreSelfEvent(ev)) || + Unread.eventTriggersUnreadCount(ev) + ) { return ev.getTs(); } } From 0465815486fd1afdcbf6bae3536d33b20d7c00a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 25 Aug 2021 08:43:13 +0200 Subject: [PATCH 6/7] ignoreSelfEvent -> shouldCauseReorder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../algorithms/tag-sorting/RecentAlgorithm.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts index 5ddfd96c8a..08f9f6efd5 100644 --- a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts +++ b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts @@ -23,21 +23,21 @@ import { EffectiveMembership, getEffectiveMembership } from "../../../../utils/m import { EventType } from "matrix-js-sdk/src/@types/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; -export function ignoreSelfEvent(event: MatrixEvent): boolean { +export function shouldCauseReorder(event: MatrixEvent): boolean { const type = event.getType(); const content = event.getContent(); const prevContent = event.getPrevContent(); // Never ignore membership changes - if (type === EventType.RoomMember && prevContent.membership !== content.membership) return false; + if (type === EventType.RoomMember && prevContent.membership !== content.membership) return true; // Ignore status changes // XXX: This should be an enum - if (type === "im.vector.user_status") return true; + if (type === "im.vector.user_status") return false; // Ignore display name changes - if (type === EventType.RoomMember && prevContent.displayname !== content.displayname) return true; + if (type === EventType.RoomMember && prevContent.displayname !== content.displayname) return false; - return false; + return true; } export const sortRooms = (rooms: Room[]): Room[] => { @@ -88,7 +88,7 @@ export const sortRooms = (rooms: Room[]): Room[] => { if (!ev.getTs()) continue; // skip events that don't have timestamps (tests only?) if ( - (ev.getSender() === myUserId && !ignoreSelfEvent(ev)) || + (ev.getSender() === myUserId && shouldCauseReorder(ev)) || Unread.eventTriggersUnreadCount(ev) ) { return ev.getTs(); From 78562685bb7e8739b380eca0ae487a431d9d2a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 25 Aug 2021 08:59:42 +0200 Subject: [PATCH 7/7] Ignore avatar changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts index 08f9f6efd5..0da2c69eb8 100644 --- a/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts +++ b/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts @@ -36,6 +36,8 @@ export function shouldCauseReorder(event: MatrixEvent): boolean { if (type === "im.vector.user_status") return false; // Ignore display name changes if (type === EventType.RoomMember && prevContent.displayname !== content.displayname) return false; + // Ignore avatar changes + if (type === EventType.RoomMember && prevContent.avatar_url !== content.avatar_url) return false; return true; }