def _sync(self): """Sync conversation state and events that could have been missed.""" logger.info('Syncing events since {}'.format(self._sync_timestamp)) try: res = yield from self._client.sync_all_new_events( hangouts_pb2.SyncAllNewEventsRequest( request_header=self._client.get_request_header(), last_sync_timestamp=parsers.to_timestamp( self._sync_timestamp), max_response_size_bytes=1048576, # 1 MB )) except exceptions.NetworkError as e: logger.warning( 'Failed to sync events, some events may be lost: {}'.format(e)) else: for conv_state in res.conversation_state: conv_id = conv_state.conversation_id.id conv = self._conv_dict.get(conv_id, None) if conv is not None: conv.update_conversation(conv_state.conversation) for event_ in conv_state.event: timestamp = parsers.from_timestamp(event_.timestamp) if timestamp > self._sync_timestamp: # This updates the sync_timestamp for us, as well # as triggering events. yield from self._on_event(event_) else: self._add_conversation(conv_state.conversation, conv_state.event)
def syncallnewevents(self, timestamp): """List all events occurring at or after timestamp. This method requests protojson rather than json so we have one chat message parser rather than two. timestamp: datetime.datetime instance specifying the time after which to return all events occurring in. Raises hangups.NetworkError if the request fails. Returns SyncAllNewEventsResponse. """ request = hangouts_pb2.SyncAllNewEventsRequest( request_header=self._get_request_header_pb(), last_sync_timestamp=parsers.to_timestamp(timestamp), max_response_size_bytes=1048576, ) response = hangouts_pb2.SyncAllNewEventsResponse() yield from self._pb_request('conversations/syncallnewevents', request, response) return response