Skip to content

Commit 7876906

Browse files
omg-xtaoColinSharkdelivranceAkkiaS7
authored
Fix history TTL Service Message Parse (hydrogram#21)
Co-authored-by: Colin <colin@colinshark.de> Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com> Co-authored-by: Akkia <AkkiaS7@outlook.com>
1 parent 738b96b commit 7876906

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

pyrogram/enums/message_service_type.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,6 @@ class MessageServiceType(AutoName):
101101

102102
REQUESTED_CHAT = auto()
103103
"Requested chat"
104+
105+
CHAT_TTL_CHANGED = auto()
106+
"Chat TTL changed"

pyrogram/methods/chats/set_chat_ttl.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,19 @@ async def set_chat_ttl(
5454
# Disable TTL for this chat
5555
app.set_chat_ttl(chat_id, 0)
5656
"""
57-
await self.invoke(
57+
r = await self.invoke(
5858
raw.functions.messages.SetHistoryTTL(
5959
peer=await self.resolve_peer(chat_id),
6060
period=ttl_seconds,
6161
)
6262
)
6363

64-
return True
64+
for i in r.updates:
65+
if isinstance(i, (raw.types.UpdateNewMessage,
66+
raw.types.UpdateNewChannelMessage)):
67+
return await types.Message._parse(
68+
self,
69+
i.message,
70+
{i.id: i for i in r.users},
71+
{i.id: i for i in r.chats},
72+
)

pyrogram/types/messages_and_media/message.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ def __init__(
466466
gift_code: "types.GiftCode" = None,
467467
requested_chats: List["types.Chat"] = None,
468468
giveaway_launched: bool = None,
469+
chat_ttl_period: int = None,
469470
reply_markup: Union[
470471
"types.InlineKeyboardMarkup",
471472
"types.ReplyKeyboardMarkup",
@@ -567,6 +568,7 @@ def __init__(
567568
self.requested_chats = requested_chats
568569
self.giveaway_launched = giveaway_launched
569570
self.reactions = reactions
571+
self.chat_ttl_period = chat_ttl_period
570572

571573
@staticmethod
572574
async def _parse(
@@ -629,6 +631,7 @@ async def _parse(
629631
gift_code = None
630632
giveaway_launched = None
631633
requested_chats = None
634+
chat_ttl_period = None
632635

633636
service_type = None
634637

@@ -732,6 +735,9 @@ async def _parse(
732735
requested_chats = types.List(_requested_chats) or None
733736

734737
service_type = enums.MessageServiceType.REQUESTED_CHAT
738+
elif isinstance(action, raw.types.MessageActionSetMessagesTTL):
739+
chat_ttl_period = action.period
740+
service_type = enums.MessageServiceType.CHAT_TTL_CHANGED
735741

736742
from_user = types.User._parse(client, users.get(user_id, None))
737743
sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None
@@ -768,6 +774,7 @@ async def _parse(
768774
giveaway_launched=giveaway_launched,
769775
gift_code=gift_code,
770776
requested_chats=requested_chats,
777+
chat_ttl_period=chat_ttl_period,
771778
client=client
772779
# TODO: supergroup_chat_created
773780
)

pyrogram/types/user_and_chats/chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ async def set_photo(
661661
video_start_ts=video_start_ts
662662
)
663663

664-
async def set_ttl(self, ttl_seconds: int) -> bool:
664+
async def set_ttl(self, ttl_seconds: int) -> "types.Message":
665665
"""Bound method *set_ttl* of :obj:`~pyrogram.types.Chat`.
666666
667667
Use as a shortcut for:
@@ -679,7 +679,7 @@ async def set_ttl(self, ttl_seconds: int) -> bool:
679679
await chat.set_ttl(86400)
680680
681681
Returns:
682-
``bool``: True on success.
682+
:obj:`~pyrogram.types.Message`: On success, the generated service message is returned.
683683
"""
684684
return await self._client.set_chat_ttl(
685685
chat_id=self.id,

0 commit comments

Comments
 (0)