Skip to content

Commit ef93fee

Browse files
committed
Add new Messages object and make get_history return it
1 parent f7aca80 commit ef93fee

File tree

6 files changed

+55
-3
lines changed

6 files changed

+55
-3
lines changed

compiler/api/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ def start():
495495
f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",")
496496
f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",")
497497
f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",")
498+
f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",")
498499

499500
f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",")
500501
f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",")

pyrogram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto,
3131
InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity,
3232
PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video,
33-
VideoNote, Voice, CallbackQuery
33+
VideoNote, Voice, CallbackQuery, Messages
3434
)
3535
from .client.types.reply_markup import (
3636
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,

pyrogram/client/ext/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def parse_messages(
253253
users: dict,
254254
chats: dict,
255255
replies: int = 1
256-
) -> pyrogram_types.Message:
256+
) -> pyrogram_types.Message or list:
257257
is_list = isinstance(messages, list)
258258
messages = messages if is_list else [messages]
259259
parsed_messages = []

pyrogram/client/methods/messages/get_history.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
import pyrogram
1920
from pyrogram.api import functions
2021
from ...ext import BaseClient, utils
2122

@@ -51,6 +52,12 @@ def get_history(self,
5152
5253
offset_date (``int``, *optional*):
5354
Pass a date in Unix time as offset to retrieve only older messages starting from that date.
55+
56+
Returns:
57+
On success, a :obj:`Messages <pyrogram.Messages>` object is returned.
58+
59+
Raises:
60+
:class:`Error <pyrogram.Error>`
5461
"""
5562

5663
r = self.send(
@@ -98,4 +105,7 @@ def get_history(self,
98105
if r.messages[i].reply_to_msg_id:
99106
messages[i].reply_to_message = reply_to_messages[r.messages[i].reply_to_msg_id]
100107

101-
return messages
108+
return pyrogram.Messages(
109+
total_count=r.count,
110+
messages=messages
111+
)

pyrogram/client/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@
4343
from .video import Video
4444
from .video_note import VideoNote
4545
from .voice import Voice
46+
from .messages import Messages

pyrogram/client/types/messages.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from pyrogram.api.core import Object
20+
21+
22+
class Messages(Object):
23+
"""This object represent a chat's messages.
24+
25+
Attributes:
26+
ID: ``0xb0700026``
27+
28+
Args:
29+
total_count (``int``):
30+
Total number of messages the target chat has.
31+
32+
messages (List of :obj:`Message <pyrogram.Message>`):
33+
Requested messages.
34+
"""
35+
36+
ID = 0xb0700026
37+
38+
def __init__(self, total_count: int, messages: list):
39+
self.total_count = total_count # int
40+
self.messages = messages # Vector<Vector<PhotoSize>>

0 commit comments

Comments
 (0)