Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Don't re-sort the room-list based on profile/status changes #6595

Merged
merged 9 commits into from
Aug 25, 2021
24 changes: 23 additions & 1 deletion src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -68,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();
}
}
Expand Down