Add limit parameter to sync command

This commit is contained in:
Andrew Ferrazzutti 2021-07-22 03:23:11 -04:00
parent 3868c19b71
commit 2fd18c7309
3 changed files with 39 additions and 24 deletions

View File

@ -41,12 +41,18 @@ async def ping(evt: CommandEvent) -> None:
@command_handler(needs_auth=True, management_only=False, help_section=SECTION_CONNECTION,
help_text="Synchronize contacts and portals")
help_text="Synchronize contacts and chats", help_args="[_limit_]")
async def sync(evt: CommandEvent) -> None:
await evt.sender.sync()
limit = 0
for arg in evt.args:
try:
limit = int(arg)
except ValueError:
pass
await evt.sender.sync(limit)
@command_handler(needs_auth=True, management_only=False, help_section=SECTION_CONNECTION,
help_text="Synchronize contacts")
help_text="Synchronize contacts only")
async def sync_contacts(evt: CommandEvent) -> None:
await evt.sender.sync_contacts()

View File

@ -81,8 +81,9 @@ bridge:
# Maximum length of displayname
displayname_max_length: 100
# Number of conversations to sync (and create portals for) on login.
# Set 0 to disable automatic syncing.
# Number of conversations to sync (and create portals for) on login
# and with the "sync" command with no numeric argument passed to it.
# Set 0 to disable automatic syncing on login.
initial_conversation_sync: 10
# Whether or not the LINE users of logged in Matrix users should be
# invited to rooms when the user sends a message from another client.
@ -97,7 +98,7 @@ bridge:
# Whether or not created rooms should have federation enabled.
# If false, created portal rooms will never be federated.
federate_rooms: true
# Settings for backfilling messages from the Messages app.
# Settings for backfilling messages.
backfill:
# If using double puppeting, should notifications be disabled
# while the initial backfill is in progress?

View File

@ -131,7 +131,7 @@ class User(DBUser, BaseUser):
self._track_metric(METRIC_CONNECTED, await self.client.is_connected())
await asyncio.sleep(5)
async def sync(self) -> None:
async def sync(self, limit: int = 0) -> None:
await self.sync_contacts()
# TODO Use some kind of async lock / event to queue syncing actions
self.is_syncing = True
@ -139,12 +139,19 @@ class User(DBUser, BaseUser):
self._connection_check_task.cancel()
self._connection_check_task = self.loop.create_task(self._check_connection_loop())
await self.client.pause()
try:
await self.sync_own_profile()
await self.client.set_last_message_ids(
await DBMessage.get_max_mids(),
await DBMessage.get_max_outgoing_mids(),
await DBReceipt.get_max_mids_per_num_read())
if limit <= 0:
limit = self.config["bridge.initial_conversation_sync"]
if limit == 0:
self.log.info("Skipping chat sync")
return
self.log.info("Syncing chats")
await self.send_bridge_notice("Synchronizing chats...")
@ -155,6 +162,7 @@ class User(DBUser, BaseUser):
chat_info_full = await self.client.get_chat(chat_info.id)
await portal.create_matrix_room(self, chat_info_full)
await self.send_bridge_notice("Chat synchronization complete")
finally:
await self.client.resume()
self.is_syncing = False