From ef93fee7aa3138001ab9182d2a266bf01a792738 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Fri, 11 May 2018 18:00:16 +0200
Subject: [PATCH] Add new Messages object and make get_history return it
---
compiler/api/compiler.py | 1 +
pyrogram/__init__.py | 2 +-
pyrogram/client/ext/utils.py | 2 +-
.../client/methods/messages/get_history.py | 12 +++++-
pyrogram/client/types/__init__.py | 1 +
pyrogram/client/types/messages.py | 40 +++++++++++++++++++
6 files changed, 55 insertions(+), 3 deletions(-)
create mode 100644 pyrogram/client/types/messages.py
diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py
index 7a4b0b06..d1bf8cfa 100644
--- a/compiler/api/compiler.py
+++ b/compiler/api/compiler.py
@@ -495,6 +495,7 @@ def start():
f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",")
f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",")
f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",")
+ f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",")
f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",")
f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",")
diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py
index 561e452a..079dfeaf 100644
--- a/pyrogram/__init__.py
+++ b/pyrogram/__init__.py
@@ -30,7 +30,7 @@ from .client.types import (
Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto,
InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity,
PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video,
- VideoNote, Voice, CallbackQuery
+ VideoNote, Voice, CallbackQuery, Messages
)
from .client.types.reply_markup import (
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py
index 06b3e103..54515eb2 100644
--- a/pyrogram/client/ext/utils.py
+++ b/pyrogram/client/ext/utils.py
@@ -253,7 +253,7 @@ def parse_messages(
users: dict,
chats: dict,
replies: int = 1
-) -> pyrogram_types.Message:
+) -> pyrogram_types.Message or list:
is_list = isinstance(messages, list)
messages = messages if is_list else [messages]
parsed_messages = []
diff --git a/pyrogram/client/methods/messages/get_history.py b/pyrogram/client/methods/messages/get_history.py
index c2acb423..cc724458 100644
--- a/pyrogram/client/methods/messages/get_history.py
+++ b/pyrogram/client/methods/messages/get_history.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+import pyrogram
from pyrogram.api import functions
from ...ext import BaseClient, utils
@@ -51,6 +52,12 @@ class GetHistory(BaseClient):
offset_date (``int``, *optional*):
Pass a date in Unix time as offset to retrieve only older messages starting from that date.
+
+ Returns:
+ On success, a :obj:`Messages ` object is returned.
+
+ Raises:
+ :class:`Error `
"""
r = self.send(
@@ -98,4 +105,7 @@ class GetHistory(BaseClient):
if r.messages[i].reply_to_msg_id:
messages[i].reply_to_message = reply_to_messages[r.messages[i].reply_to_msg_id]
- return messages
+ return pyrogram.Messages(
+ total_count=r.count,
+ messages=messages
+ )
diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py
index 308c9e62..5431b89e 100644
--- a/pyrogram/client/types/__init__.py
+++ b/pyrogram/client/types/__init__.py
@@ -43,3 +43,4 @@ from .venue import Venue
from .video import Video
from .video_note import VideoNote
from .voice import Voice
+from .messages import Messages
diff --git a/pyrogram/client/types/messages.py b/pyrogram/client/types/messages.py
new file mode 100644
index 00000000..eefc945d
--- /dev/null
+++ b/pyrogram/client/types/messages.py
@@ -0,0 +1,40 @@
+# Pyrogram - Telegram MTProto API Client Library for Python
+# Copyright (C) 2017-2018 Dan Tès
+#
+# This file is part of Pyrogram.
+#
+# Pyrogram is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pyrogram is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with Pyrogram. If not, see .
+
+from pyrogram.api.core import Object
+
+
+class Messages(Object):
+ """This object represent a chat's messages.
+
+ Attributes:
+ ID: ``0xb0700026``
+
+ Args:
+ total_count (``int``):
+ Total number of messages the target chat has.
+
+ messages (List of :obj:`Message `):
+ Requested messages.
+ """
+
+ ID = 0xb0700026
+
+ def __init__(self, total_count: int, messages: list):
+ self.total_count = total_count # int
+ self.messages = messages # Vector>