From 1fddc563e25690929741d8ee9addd067b1725f3e Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Wed, 30 Jun 2021 03:05:49 -0400 Subject: [PATCH] Avoid conflicting actions during sync More is likely need for this to work well --- matrix_puppeteer_line/matrix.py | 3 ++- matrix_puppeteer_line/user.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/matrix_puppeteer_line/matrix.py b/matrix_puppeteer_line/matrix.py index cae3463..7ac8f84 100644 --- a/matrix_puppeteer_line/matrix.py +++ b/matrix_puppeteer_line/matrix.py @@ -74,4 +74,5 @@ class MatrixHandler(BaseMatrixHandler): #if await DBMessage.is_last_by_mxid(event_id, portal.mxid): # Viewing a chat by updating it whole-hog, lest a ninja arrives - await user.sync_portal(portal) + if not user.is_syncing: + await user.sync_portal(portal) diff --git a/matrix_puppeteer_line/user.py b/matrix_puppeteer_line/user.py index 24fef52..65b7b15 100644 --- a/matrix_puppeteer_line/user.py +++ b/matrix_puppeteer_line/user.py @@ -42,6 +42,7 @@ class User(DBUser, BaseUser): client: Optional[Client] intent: Optional[IntentAPI] is_real_user = True + is_syncing: bool _notice_room_lock: asyncio.Lock _connection_check_task: Optional[asyncio.Task] @@ -56,6 +57,7 @@ class User(DBUser, BaseUser): self._connection_check_task = None self.client = None self.intent = None + self.is_syncing = False @classmethod def init_cls(cls, bridge: 'MessagesBridge') -> None: @@ -130,6 +132,8 @@ class User(DBUser, BaseUser): await asyncio.sleep(5) async def sync(self) -> None: + # TODO Use some kind of async lock / event to queue syncing actions + self.is_syncing = True if self._connection_check_task: self._connection_check_task.cancel() self._connection_check_task = self.loop.create_task(self._check_connection_loop()) @@ -155,6 +159,7 @@ class User(DBUser, BaseUser): num_created += 1 await self.send_bridge_notice("Synchronization complete") await self.client.resume() + self.is_syncing = False async def sync_portal(self, portal: 'po.Portal') -> None: chat_id = portal.chat_id