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] 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