Don't put our own profile changes in the timeline

This commit is contained in:
miruka 2019-07-04 19:11:22 -04:00
parent e97773dc97
commit 634796b7d9
2 changed files with 16 additions and 4 deletions

View File

@ -33,7 +33,7 @@ class Backend:
device_id: Optional[str] = None,
homeserver: str = "https://matrix.org") -> str:
client = MatrixClient(
user=user, homeserver=homeserver, device_id=device_id
backend=self, user=user, homeserver=homeserver, device_id=device_id
)
await client.login(password)
self.clients[client.user_id] = client
@ -47,6 +47,7 @@ class Backend:
device_id: str,
homeserver: str = "https://matrix.org") -> None:
client = MatrixClient(
backend=self,
user=user_id, homeserver=homeserver, device_id=device_id
)
await client.resume(user_id=user_id, token=token, device_id=device_id)

View File

@ -20,11 +20,15 @@ from .html_filter import HTML_FILTER
class MatrixClient(nio.AsyncClient):
def __init__(self,
backend,
user: str,
homeserver: str = "https://matrix.org",
device_id: Optional[str] = None) -> None:
# TODO: ensure homeserver starts with a scheme://
from .backend import Backend
self.backend: Backend = backend
self.sync_task: Optional[asyncio.Future] = None
super().__init__(homeserver=homeserver, user=user, device_id=device_id)
@ -242,7 +246,7 @@ class MatrixClient(nio.AsyncClient):
TimelineEventReceived.from_nio(room, ev, content=co)
async def _get_room_member_event_content(self, ev) -> str:
async def _get_room_member_event_content(self, ev) -> Optional[str]:
prev = ev.prev_content
prev_membership = prev["membership"] if prev else None
now = ev.content
@ -280,6 +284,11 @@ class MatrixClient(nio.AsyncClient):
if membership == "ban":
return f"%S banned %T from the room.{reason}"
if ev.sender in self.backend.clients:
# Don't put our own name/avatar changes in the timeline
return None
changed = []
if prev and now["avatar_url"] != prev["avatar_url"]:
@ -297,7 +306,7 @@ class MatrixClient(nio.AsyncClient):
log.warning("Invalid member event - %s",
json.dumps(ev.__dict__, indent=4))
return "%S ???"
return None
async def onRoomMemberEvent(self, room, ev) -> None:
@ -311,6 +320,8 @@ class MatrixClient(nio.AsyncClient):
)
co = await self._get_room_member_event_content(ev)
if co is not None:
TimelineEventReceived.from_nio(room, ev, content=co)