Esempio n. 1
0
 async def sync_chats(self, chats: ConversationList) -> None:
     self.chats = chats
     portals = {
         conv.id_: po.Portal.get_by_conversation(conv, self.gid)
         for conv in chats.get_all()
     }
     await self._sync_community_rooms(portals)
     self.chats.on_event.add_observer(
         self._ensure_future_proxy(self.on_event))
     self.chats.on_typing.add_observer(
         self._ensure_future_proxy(self.on_typing))
     self.log.debug("Fetching recent conversations to create portals for")
     res = await self.client.sync_recent_conversations(
         hangouts.SyncRecentConversationsRequest(
             request_header=self.client.get_request_header(),
             max_conversations=config["bridge.initial_chat_sync"],
             max_events_per_conversation=1,
             sync_filter=[hangouts.SYNC_FILTER_INBOX],
         ))
     res = sorted(
         (conv_state.conversation for conv_state in res.conversation_state),
         reverse=True,
         key=lambda conv: conv.self_conversation_state.sort_timestamp)
     res = (chats.get(conv.conversation_id.id) for conv in res)
     await asyncio.gather(*[
         po.Portal.get_by_conversation(info, self.gid).create_matrix_room(
             self, info) for info in res
     ],
                          loop=self.loop)
Esempio n. 2
0
 async def sync_chats(self, chats: ConversationList) -> None:
     self.chats = chats
     self.chats_future.set_result(None)
     portals = {conv.id_: po.Portal.get_by_conversation(conv, self.gid)
                for conv in chats.get_all()}
     await self._sync_community_rooms(portals)
     self.chats.on_watermark_notification.add_observer(
         self._ensure_future_proxy(self.on_receipt))
     self.chats.on_event.add_observer(self._ensure_future_proxy(self.on_event))
     self.chats.on_typing.add_observer(self._ensure_future_proxy(self.on_typing))
     self.log.debug("Fetching recent conversations to create portals for")
     res = await self.client.sync_recent_conversations(hangouts.SyncRecentConversationsRequest(
         request_header=self.client.get_request_header(),
         max_conversations=config["bridge.initial_chat_sync"],
         max_events_per_conversation=1,
         sync_filter=[hangouts.SYNC_FILTER_INBOX],
     ))
     self.log.debug("Server returned %d conversations", len(res.conversation_state))
     convs = sorted(res.conversation_state, reverse=True,
                    key=lambda state: state.conversation.self_conversation_state.sort_timestamp)
     for state in convs:
         self.log.debug("Syncing %s", state.conversation_id.id)
         chat = chats.get(state.conversation_id.id)
         portal = po.Portal.get_by_conversation(chat, self.gid)
         if portal.mxid:
             await portal.update_matrix_room(self, chat)
             if len(state.event) > 0 and not DBMessage.get_by_gid(state.event[0].event_id):
                 self.log.debug("Last message %s in chat %s not found in db, backfilling...",
                                state.event[0].event_id, state.conversation_id.id)
                 await portal.backfill(self, is_initial=False)
         else:
             await portal.create_matrix_room(self, chat)
     await self.update_direct_chats()