Skip to content

Commit

Permalink
Add clear_mentions parameter to .send_read_acknowledge()
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Jan 10, 2018
1 parent 045f7f5 commit 8038971
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions telethon/telegram_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .tl.functions.messages import (
GetDialogsRequest, GetHistoryRequest, SendMediaRequest,
SendMessageRequest, GetChatsRequest, GetAllDraftsRequest,
CheckChatInviteRequest
CheckChatInviteRequest, ReadMentionsRequest
)

from .tl.functions import channels
Expand Down Expand Up @@ -639,7 +639,8 @@ def get_message_history(self, entity, limit=20, offset_date=None,

return messages

def send_read_acknowledge(self, entity, message=None, max_id=None):
def send_read_acknowledge(self, entity, message=None, max_id=None,
clear_mentions=False):
"""
Sends a "read acknowledge" (i.e., notifying the given peer that we've
read their messages, also known as the "double check").
Expand All @@ -654,22 +655,37 @@ def send_read_acknowledge(self, entity, message=None, max_id=None):
max_id (:obj:`int`):
Overrides messages, until which message should the
acknowledge should be sent.
clear_mentions (:obj:`bool`):
Whether the mention badge should be cleared (so that
there are no more mentions) or not for the given entity.
If no message is provided, this will be the only action
taken.
"""
if max_id is None:
if not messages:
if message:
if hasattr(message, '__iter__'):
max_id = max(msg.id for msg in message)
else:
max_id = message.id
elif not clear_mentions:
raise ValueError(
'Either a message list or a max_id must be provided.')

if hasattr(message, '__iter__'):
max_id = max(msg.id for msg in message)
entity = self.get_input_entity(entity)
if clear_mentions:
self(ReadMentionsRequest(entity))
if max_id is None:
return True

if max_id is not None:
if isinstance(entity, InputPeerChannel):
return self(channels.ReadHistoryRequest(entity, max_id=max_id))
else:
max_id = message.id
return self(messages.ReadHistoryRequest(entity, max_id=max_id))

entity = self.get_input_entity(entity)
if isinstance(entity, InputPeerChannel):
return self(channels.ReadHistoryRequest(entity, max_id=max_id))
else:
return self(messages.ReadHistoryRequest(entity, max_id=max_id))
return False

@staticmethod
def _get_reply_to(reply_to):
Expand Down

0 comments on commit 8038971

Please sign in to comment.