def update_read_timestamp(self, read_timestamp=None): """Update the timestamp of the latest event which has been read. This method will avoid making an API request if it will have no effect. Args: read_timestamp (datetime.datetime): (optional) Timestamp to set. Defaults to the timestamp of the newest event. Raises: .NetworkError: If the timestamp cannot be updated. """ if read_timestamp is None: read_timestamp = (self.events[-1].timestamp if self.events else datetime.datetime.now(datetime.timezone.utc)) if read_timestamp > self.latest_read_timestamp: logger.info( 'Setting {} latest_read_timestamp from {} to {}'.format( self.id_, self.latest_read_timestamp, read_timestamp)) # Prevent duplicate requests by updating the conversation now. state = self._conversation.self_conversation_state state.self_read_state.latest_read_timestamp = ( parsers.to_timestamp(read_timestamp)) try: yield from self._client.update_watermark( hangouts_pb2.UpdateWatermarkRequest( request_header=self._client.get_request_header(), conversation_id=hangouts_pb2.ConversationId( id=self.id_), last_read_timestamp=parsers.to_timestamp( read_timestamp), )) except exceptions.NetworkError as e: logger.warning('Failed to update read timestamp: {}'.format(e)) raise
async def mark_read(self, conversation_id: str, timestamp: Optional[Union[datetime.datetime, int]] = None) -> None: if isinstance(timestamp, datetime.datetime): timestamp = hangups.parsers.to_timestamp(timestamp) elif not timestamp: timestamp = int(time.time() * 1_000_000) await self.client.update_watermark(hangouts.UpdateWatermarkRequest( request_header=self.client.get_request_header(), conversation_id=hangouts.ConversationId(id=conversation_id), last_read_timestamp=timestamp, ))
def updatewatermark(self, conv_id, read_timestamp): """Update the watermark (read timestamp) for a conversation. Raises hangups.NetworkError if the request fails. """ request = hangouts_pb2.UpdateWatermarkRequest( request_header=self._get_request_header_pb(), conversation_id=hangouts_pb2.ConversationId(id=conv_id), last_read_timestamp=parsers.to_timestamp(read_timestamp), ) response = hangouts_pb2.UpdateWatermarkResponse() yield from self._pb_request('conversations/updatewatermark', request, response) return response