forked from fair/matrix-puppeteer-line
Avoid conflicting actions during sync
More is likely need for this to work well
This commit is contained in:
parent
8c2c0126c9
commit
1fddc563e2
|
@ -74,4 +74,5 @@ class MatrixHandler(BaseMatrixHandler):
|
||||||
#if await DBMessage.is_last_by_mxid(event_id, portal.mxid):
|
#if await DBMessage.is_last_by_mxid(event_id, portal.mxid):
|
||||||
|
|
||||||
# Viewing a chat by updating it whole-hog, lest a ninja arrives
|
# 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)
|
||||||
|
|
|
@ -42,6 +42,7 @@ class User(DBUser, BaseUser):
|
||||||
client: Optional[Client]
|
client: Optional[Client]
|
||||||
intent: Optional[IntentAPI]
|
intent: Optional[IntentAPI]
|
||||||
is_real_user = True
|
is_real_user = True
|
||||||
|
is_syncing: bool
|
||||||
|
|
||||||
_notice_room_lock: asyncio.Lock
|
_notice_room_lock: asyncio.Lock
|
||||||
_connection_check_task: Optional[asyncio.Task]
|
_connection_check_task: Optional[asyncio.Task]
|
||||||
|
@ -56,6 +57,7 @@ class User(DBUser, BaseUser):
|
||||||
self._connection_check_task = None
|
self._connection_check_task = None
|
||||||
self.client = None
|
self.client = None
|
||||||
self.intent = None
|
self.intent = None
|
||||||
|
self.is_syncing = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def init_cls(cls, bridge: 'MessagesBridge') -> None:
|
def init_cls(cls, bridge: 'MessagesBridge') -> None:
|
||||||
|
@ -130,6 +132,8 @@ class User(DBUser, BaseUser):
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
async def sync(self) -> None:
|
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:
|
if self._connection_check_task:
|
||||||
self._connection_check_task.cancel()
|
self._connection_check_task.cancel()
|
||||||
self._connection_check_task = self.loop.create_task(self._check_connection_loop())
|
self._connection_check_task = self.loop.create_task(self._check_connection_loop())
|
||||||
|
@ -155,6 +159,7 @@ class User(DBUser, BaseUser):
|
||||||
num_created += 1
|
num_created += 1
|
||||||
await self.send_bridge_notice("Synchronization complete")
|
await self.send_bridge_notice("Synchronization complete")
|
||||||
await self.client.resume()
|
await self.client.resume()
|
||||||
|
self.is_syncing = False
|
||||||
|
|
||||||
async def sync_portal(self, portal: 'po.Portal') -> None:
|
async def sync_portal(self, portal: 'po.Portal') -> None:
|
||||||
chat_id = portal.chat_id
|
chat_id = portal.chat_id
|
||||||
|
|
Loading…
Reference in New Issue