2018-07-10 16:15:22 +03:00
|
|
|
from .chatgetter import ChatGetter
|
|
|
|
from .sendergetter import SenderGetter
|
2020-10-01 13:22:55 +03:00
|
|
|
from ... import utils, helpers
|
2018-07-10 16:15:22 +03:00
|
|
|
from ...tl import types
|
2018-06-25 12:34:10 +03:00
|
|
|
|
|
|
|
|
2018-07-10 16:15:22 +03:00
|
|
|
class Forward(ChatGetter, SenderGetter):
|
2018-06-25 12:34:10 +03:00
|
|
|
"""
|
|
|
|
Custom class that encapsulates a :tl:`MessageFwdHeader` providing an
|
|
|
|
abstraction to easily access information like the original sender.
|
|
|
|
|
2018-07-10 16:15:22 +03:00
|
|
|
Remember that this class implements `ChatGetter
|
|
|
|
<telethon.tl.custom.chatgetter.ChatGetter>` and `SenderGetter
|
|
|
|
<telethon.tl.custom.sendergetter.SenderGetter>` which means you
|
|
|
|
have access to all their sender and chat properties and methods.
|
|
|
|
|
2018-06-25 12:34:10 +03:00
|
|
|
Attributes:
|
|
|
|
|
|
|
|
original_fwd (:tl:`MessageFwdHeader`):
|
|
|
|
The original :tl:`MessageFwdHeader` instance.
|
|
|
|
|
|
|
|
Any other attribute:
|
|
|
|
Attributes not described here are the same as those available
|
|
|
|
in the original :tl:`MessageFwdHeader`.
|
|
|
|
"""
|
|
|
|
def __init__(self, client, original, entities):
|
2019-06-26 12:16:02 +03:00
|
|
|
# Copy all the fields, not reference! It would cause memory cycles:
|
|
|
|
# self.original_fwd.original_fwd.original_fwd.original_fwd
|
|
|
|
# ...would be valid if we referenced.
|
2019-07-31 12:01:48 +03:00
|
|
|
self.__dict__.update(original.__dict__)
|
2018-06-25 12:34:10 +03:00
|
|
|
self.original_fwd = original
|
|
|
|
|
2020-10-01 13:22:55 +03:00
|
|
|
sender_id = sender = input_sender = peer = chat = input_chat = None
|
|
|
|
if not original.from_id:
|
|
|
|
pass
|
2018-07-10 16:15:22 +03:00
|
|
|
else:
|
2020-10-01 13:22:55 +03:00
|
|
|
ty = helpers._entity_type(original.from_id)
|
|
|
|
if ty == helpers._EntityType.USER:
|
|
|
|
sender_id = utils.get_peer_id(original.from_id)
|
|
|
|
sender, input_sender = utils._get_entity_pair(
|
|
|
|
sender_id, entities, client._entity_cache)
|
|
|
|
|
|
|
|
elif ty in (helpers._EntityType.CHAT, helpers._EntityType.CHANNEL):
|
|
|
|
peer = original.from_id
|
|
|
|
chat, input_chat = utils._get_entity_pair(
|
|
|
|
utils.get_peer_id(peer), entities, client._entity_cache)
|
2019-05-12 15:00:12 +03:00
|
|
|
|
2019-07-31 12:01:48 +03:00
|
|
|
# This call resets the client
|
2019-05-12 15:00:12 +03:00
|
|
|
ChatGetter.__init__(self, peer, chat=chat, input_chat=input_chat)
|
2020-10-01 13:22:55 +03:00
|
|
|
SenderGetter.__init__(self, sender_id, sender=sender, input_sender=input_sender)
|
2019-07-31 12:01:48 +03:00
|
|
|
self._client = client
|
2018-06-25 12:34:10 +03:00
|
|
|
|
2018-07-10 16:15:22 +03:00
|
|
|
# TODO We could reload the message
|