From 0833850f4f0da78bf24cf5e390cf42e88fb63695 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 19 May 2018 16:18:04 +0300 Subject: [PATCH] Fix potential duplicate unauthenticated user join/leave message in Matrix --- mautrix_telegram/portal.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 5644e06b..c3846ac2 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -584,10 +584,11 @@ class Portal: async def leave_matrix(self, user, source, event_id): if not user.logged_in: - response = await self.bot.client.send_message( - self.peer, f"__{user.displayname} left the room.__", markdown=True) - space = self.tgid if self.peer_type == "channel" else self.bot.tgid - self.is_duplicate(response, (event_id, space)) + async with self.require_send_lock(self.bot.tgid): + response = await self.bot.client.send_message( + self.peer, f"__{user.displayname} left the room.__", markdown=True) + space = self.tgid if self.peer_type == "channel" else self.bot.tgid + self.is_duplicate(response, (event_id, space)) return if self.peer_type == "user": @@ -615,10 +616,11 @@ class Portal: async def join_matrix(self, user, event_id): if not user.logged_in: - response = await self.bot.client.send_message( - self.peer, f"__{user.displayname} joined the room.__", markdown=True) - space = self.tgid if self.peer_type == "channel" else self.bot.tgid - self.is_duplicate(response, (event_id, space)) + async with self.require_send_lock(self.bot.tgid): + response = await self.bot.client.send_message( + self.peer, f"__{user.displayname} joined the room.__", markdown=True) + space = self.tgid if self.peer_type == "channel" else self.bot.tgid + self.is_duplicate(response, (event_id, space)) return if self.peer_type == "channel":