Ensure first event for each rooms is a visible one
Dependening on the user's config, request for the first sync that profile changes, membership changes or unknown events be filtered out. This ensures we have something to show as the room subtitle (last message) in the UI.
This commit is contained in:
parent
aba2fd1b4b
commit
a4c33f8edb
|
@ -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(
|
||||
|
|
|
@ -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 <b>{ev.type}</b> event"
|
||||
|
|
Loading…
Reference in New Issue
Block a user