Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 1 addition & 9 deletions src/app/utils/sort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function makeClient(
name: r.name,
getLastActiveTimestamp: () => r.ts,
getBumpStamp: () => r.bumpStamp,
getLiveTimeline: () => ({ getEvents: () => [] }),
} as unknown as ReturnType<MatrixClient['getRoom']>;
},
} as unknown as MatrixClient;
Expand Down Expand Up @@ -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', () => {
Expand Down
21 changes: 16 additions & 5 deletions src/app/utils/sort.ts
Original file line number Diff line number Diff line change
@@ -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<T> = (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 =
Expand Down
Loading