From d1bebec1dcc489d98d4fcc0bd7a63bb03aab7487 Mon Sep 17 00:00:00 2001 From: lunar-seal Date: Fri, 14 Aug 2026 23:15:22 +0200 Subject: [PATCH] fix: sort dm rooms by last proper activity --- ...eg_only_the_name_of_someone_has_changed.md | 5 +++++ src/app/utils/sort.test.ts | 10 +-------- src/app/utils/sort.ts | 21 ++++++++++++++----- 3 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 .changeset/dont_sort_a_dm_room_to_the_top_if_eg_only_the_name_of_someone_has_changed.md diff --git a/.changeset/dont_sort_a_dm_room_to_the_top_if_eg_only_the_name_of_someone_has_changed.md b/.changeset/dont_sort_a_dm_room_to_the_top_if_eg_only_the_name_of_someone_has_changed.md new file mode 100644 index 0000000000..083e8c4d04 --- /dev/null +++ b/.changeset/dont_sort_a_dm_room_to_the_top_if_eg_only_the_name_of_someone_has_changed.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +# Don't sort a DM room to the top if e.g. only the name of someone has changed. diff --git a/src/app/utils/sort.test.ts b/src/app/utils/sort.test.ts index 27be7da507..4bf6556c13 100644 --- a/src/app/utils/sort.test.ts +++ b/src/app/utils/sort.test.ts @@ -25,6 +25,7 @@ function makeClient( name: r.name, getLastActiveTimestamp: () => r.ts, getBumpStamp: () => r.bumpStamp, + getLiveTimeline: () => ({ getEvents: () => [] }), } as unknown as ReturnType; }, } as unknown as MatrixClient; @@ -72,15 +73,6 @@ describe('factoryRoomIdByActivity', () => { const sort = factoryRoomIdByActivity(mx); expect(['!unknown:h', '!known:h'].toSorted(sort)).toEqual(['!known:h', '!unknown:h']); }); - - it('uses sliding-sync bump stamps when no timeline event is loaded', () => { - const mx = makeClient({ - '!old:h': { name: 'Old', ts: Number.MIN_SAFE_INTEGER, bumpStamp: 1000 }, - '!new:h': { name: 'New', ts: Number.MIN_SAFE_INTEGER, bumpStamp: 9000 }, - }); - const sort = factoryRoomIdByActivity(mx); - expect(['!old:h', '!new:h'].toSorted(sort)).toEqual(['!new:h', '!old:h']); - }); }); describe('factoryRoomIdByAtoZ', () => { diff --git a/src/app/utils/sort.ts b/src/app/utils/sort.ts index 342ce351b8..6cd4d0e083 100644 --- a/src/app/utils/sort.ts +++ b/src/app/utils/sort.ts @@ -1,14 +1,25 @@ -import type { MatrixClient } from '$types/matrix-sdk'; +import type { MatrixClient, Room } from '$types/matrix-sdk'; +import { isNotificationEvent } from '$utils/room/unread'; export type SortFunc = (a: T, b: T) => number; +const getLastActivityTs = (room: Room): number | undefined => { + const events = room.getLiveTimeline().getEvents(); + for (let i = events.length - 1; i >= 0; i--) { + const mEvent = events[i]; + if (mEvent && isNotificationEvent(mEvent)) { + return mEvent.getTs(); + } + } + return undefined; +}; + const getRoomActivity = (mx: MatrixClient, roomId: string): number => { const room = mx.getRoom(roomId); if (!room) return Number.MIN_SAFE_INTEGER; - const timelineTimestamp = room.getLastActiveTimestamp(); - return timelineTimestamp === Number.MIN_SAFE_INTEGER - ? (room.getBumpStamp() ?? Number.MIN_SAFE_INTEGER) - : timelineTimestamp; + const activityTs = getLastActivityTs(room); + if (activityTs !== undefined) return activityTs; + return room.getLastActiveTimestamp(); }; export const factoryRoomIdByActivity =