forked from fair/matrix-puppeteer-line
Add limit parameter to sync command
This commit is contained in:
parent
3868c19b71
commit
2fd18c7309
|
@ -41,12 +41,18 @@ async def ping(evt: CommandEvent) -> None:
|
||||||
|
|
||||||
|
|
||||||
@command_handler(needs_auth=True, management_only=False, help_section=SECTION_CONNECTION,
|
@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:
|
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,
|
@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:
|
async def sync_contacts(evt: CommandEvent) -> None:
|
||||||
await evt.sender.sync_contacts()
|
await evt.sender.sync_contacts()
|
||||||
|
|
|
@ -81,8 +81,9 @@ bridge:
|
||||||
# Maximum length of displayname
|
# Maximum length of displayname
|
||||||
displayname_max_length: 100
|
displayname_max_length: 100
|
||||||
|
|
||||||
# Number of conversations to sync (and create portals for) on login.
|
# Number of conversations to sync (and create portals for) on login
|
||||||
# Set 0 to disable automatic syncing.
|
# and with the "sync" command with no numeric argument passed to it.
|
||||||
|
# Set 0 to disable automatic syncing on login.
|
||||||
initial_conversation_sync: 10
|
initial_conversation_sync: 10
|
||||||
# Whether or not the LINE users of logged in Matrix users should be
|
# 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.
|
# 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.
|
# Whether or not created rooms should have federation enabled.
|
||||||
# If false, created portal rooms will never be federated.
|
# If false, created portal rooms will never be federated.
|
||||||
federate_rooms: true
|
federate_rooms: true
|
||||||
# Settings for backfilling messages from the Messages app.
|
# Settings for backfilling messages.
|
||||||
backfill:
|
backfill:
|
||||||
# If using double puppeting, should notifications be disabled
|
# If using double puppeting, should notifications be disabled
|
||||||
# while the initial backfill is in progress?
|
# while the initial backfill is in progress?
|
||||||
|
|
|
@ -131,7 +131,7 @@ class User(DBUser, BaseUser):
|
||||||
self._track_metric(METRIC_CONNECTED, await self.client.is_connected())
|
self._track_metric(METRIC_CONNECTED, await self.client.is_connected())
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
async def sync(self) -> None:
|
async def sync(self, limit: int = 0) -> None:
|
||||||
await self.sync_contacts()
|
await self.sync_contacts()
|
||||||
# TODO Use some kind of async lock / event to queue syncing actions
|
# TODO Use some kind of async lock / event to queue syncing actions
|
||||||
self.is_syncing = True
|
self.is_syncing = True
|
||||||
|
@ -139,24 +139,32 @@ class User(DBUser, BaseUser):
|
||||||
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())
|
||||||
await self.client.pause()
|
await self.client.pause()
|
||||||
await self.sync_own_profile()
|
try:
|
||||||
await self.client.set_last_message_ids(
|
await self.sync_own_profile()
|
||||||
await DBMessage.get_max_mids(),
|
await self.client.set_last_message_ids(
|
||||||
await DBMessage.get_max_outgoing_mids(),
|
await DBMessage.get_max_mids(),
|
||||||
await DBReceipt.get_max_mids_per_num_read())
|
await DBMessage.get_max_outgoing_mids(),
|
||||||
limit = self.config["bridge.initial_conversation_sync"]
|
await DBReceipt.get_max_mids_per_num_read())
|
||||||
self.log.info("Syncing chats")
|
|
||||||
await self.send_bridge_notice("Synchronizing chats...")
|
|
||||||
|
|
||||||
# TODO Since only chat ID is used, retrieve only that
|
if limit <= 0:
|
||||||
chat_infos = await self.client.get_chats()
|
limit = self.config["bridge.initial_conversation_sync"]
|
||||||
for chat_info in chat_infos[:limit]:
|
if limit == 0:
|
||||||
portal = await po.Portal.get_by_chat_id(chat_info.id, create=True)
|
self.log.info("Skipping chat sync")
|
||||||
chat_info_full = await self.client.get_chat(chat_info.id)
|
return
|
||||||
await portal.create_matrix_room(self, chat_info_full)
|
|
||||||
await self.send_bridge_notice("Chat synchronization complete")
|
self.log.info("Syncing chats")
|
||||||
await self.client.resume()
|
await self.send_bridge_notice("Synchronizing chats...")
|
||||||
self.is_syncing = False
|
|
||||||
|
# TODO Since only chat ID is used, retrieve only that
|
||||||
|
chat_infos = await self.client.get_chats()
|
||||||
|
for chat_info in chat_infos[:limit]:
|
||||||
|
portal = await po.Portal.get_by_chat_id(chat_info.id, create=True)
|
||||||
|
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
|
||||||
|
|
||||||
async def sync_contacts(self) -> None:
|
async def sync_contacts(self) -> None:
|
||||||
await self.send_bridge_notice("Synchronizing contacts...")
|
await self.send_bridge_notice("Synchronizing contacts...")
|
||||||
|
|
Loading…
Reference in New Issue