diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 04b91da6..62f31df4 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -16,8 +16,8 @@ from datetime import datetime, timedelta from functools import partial from pathlib import Path from typing import ( - TYPE_CHECKING, Any, ClassVar, DefaultDict, Dict, List, NamedTuple, - Optional, Set, Tuple, Type, Union, + TYPE_CHECKING, Any, ClassVar, Dict, List, NamedTuple, Optional, Set, Tuple, + Type, Union, ) from urllib.parse import urlparse from uuid import UUID, uuid4 @@ -109,6 +109,27 @@ class MatrixClient(nio.AsyncClient): }, } + no_profile_events_filter: ClassVar[Dict[str, Any]] = { + "room": { + "timeline": {"not_types": ["m.room.member"]}, + }, + } + + no_unknown_events_filter: ClassVar[Dict[str, Any]] = { + "room": { + "timeline": { + "not_types": [ + "m.room.message.feedback", + "m.room.pinned_events", + "m.call.*", + "m.room.third_part_invite", + "m.room.tombstone", + "m.reaction", + ], + }, + }, + } + def __init__(self, backend, @@ -155,8 +176,6 @@ class MatrixClient(nio.AsyncClient): self.loaded_once_rooms: Set[str] = set() # {room_id} self.cleared_events_rooms: Set[str] = set() # {room_id} - self.skipped_events: DefaultDict[str, int] = DefaultDict(lambda: 0) - self.nio_callbacks = NioCallbacks(self) @@ -299,6 +318,16 @@ class MatrixClient(nio.AsyncClient): filter1 = deepcopy(self.lazy_load_filter) utils.dict_update_recursive(filter1, self.limit_1_filter) + + cfg = self.backend.ui_settings + if cfg["hideProfileChangeEvents"] or cfg["hideMembershipEvents"]: + utils.dict_update_recursive(filter1, self.no_profile_events_filter) + + if cfg["hideUnknownEvents"]: + filter1["room"]["timeline"]["not_types"].extend( + self.no_unknown_events_filter["room"]["timeline"]["not_types"], + ) + while True: try: self.sync_task = asyncio.ensure_future(self.sync_forever( diff --git a/src/backend/nio_callbacks.py b/src/backend/nio_callbacks.py index 580a6d0b..55973805 100644 --- a/src/backend/nio_callbacks.py +++ b/src/backend/nio_callbacks.py @@ -264,7 +264,6 @@ class NioCallbacks: # Membership changes if not prev or membership != prev_membership: if self.client.backend.ui_settings["hideMembershipEvents"]: - self.client.skipped_events[room.room_id] += 1 return None reason = f", reason: {now['reason']}" if now.get("reason") else "" @@ -327,7 +326,6 @@ class NioCallbacks: account.avatar_url = now.get("avatar_url") or "" if self.client.backend.ui_settings["hideProfileChangeEvents"]: - self.client.skipped_events[room.room_id] += 1 return None return ( @@ -419,7 +417,6 @@ class NioCallbacks: async def onUnknownEvent(self, room, ev) -> None: if self.client.backend.ui_settings["hideUnknownEvents"]: - self.client.skipped_events[room.room_id] += 1 return co = f"%1 sent an unsupported {ev.type} event"