Make all events able to increment unread/mentions

This commit is contained in:
miruka 2020-04-16 14:08:24 -04:00
parent 4f374081a7
commit 0ba8c6eecf
3 changed files with 22 additions and 20 deletions

View File

@ -116,7 +116,7 @@ class MatrixClient(nio.AsyncClient):
self.backend: "Backend" = backend
self.models: ModelStore = self.backend.models
self.open_room: str = None
self.open_room: Optional[str] = None
self.profile_task: Optional[asyncio.Future] = None
self.server_config_task: Optional[asyncio.Future] = None
@ -1304,13 +1304,26 @@ class MatrixClient(nio.AsyncClient):
tx_id = ev.source.get("content", {}).get(
f"{__app_name__}.transaction_id",
)
local_sender = ev.sender in self.backend.clients
from_us = ev.sender in self.backend.clients
if local_sender and tx_id and f"echo-{tx_id}" in model:
if from_us and tx_id and f"echo-{tx_id}" in model:
item.id = f"echo-{tx_id}"
if not local_sender and not await self.event_is_past(ev):
AlertRequested()
model[item.id] = item
await self.set_room_last_event(room.room_id, item)
# Alerts
if from_us or await self.event_is_past(ev):
return
AlertRequested()
if self.open_room != room.room_id:
room = self.models[self.user_id, "rooms"][room.room_id]
room.unreads += 1
content = fields.get("content", "")
if HTML.user_id_link_in_html(content, self.user_id):
room.mentions += 1

View File

@ -108,17 +108,6 @@ class NioCallbacks:
room, ev, content=co, mentions=mention_list,
)
past = await self.client.event_is_past(ev)
from_us = ev.sender in self.client.backend.clients
if not past and not from_us and self.client.open_room != room.room_id:
model = self.client.models[self.client.user_id, "rooms"]
room = model[room.room_id]
room.unreads += 1
if HTML_PROCESSOR.user_id_link_in_html(co, self.client.user_id):
room.mentions += 1
async def onRoomMessageNotice(self, room, ev) -> None:
await self.onRoomMessageText(room, ev)