Skip to content

Commit 6e0bdf9

Browse files
committed
Fix download_media method not checking for file_id.
Fix topic.top_message parsing. Signed-off-by: Aliwoto <[email protected]>
1 parent 79cbad9 commit 6e0bdf9

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

pyrogram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +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-
__version__ = "2.0.141"
19+
__version__ = "2.0.142"
2020
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
2121
__copyright__ = "Copyright (C) 2017-present Dan <https://github.com/delivrance>"
2222

pyrogram/methods/chats/get_forum_topics_by_id.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ async def get_forum_topics_by_id(
7575
chats = {c.id: c for c in getattr(r, "chats", [])}
7676
messages = {m.id: m for m in getattr(r, "messages", [])}
7777

78+
for message in messages:
79+
if isinstance(message, raw.types.MessageEmpty):
80+
continue
81+
82+
messages[message.id] = await types.Message._parse(
83+
client=self,
84+
message=message,
85+
users=users,
86+
chats=chats,
87+
replies=0
88+
)
89+
7890
for current in getattr(r, "topics", []):
7991
topics.append(types.ForumTopic._parse(
8092
self,

pyrogram/methods/messages/download_media.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ async def download_media(
104104
# Download from file id
105105
await app.download_media(message.photo.file_id)
106106
107+
# Download document of a message
108+
await app.download_media(message.document)
109+
107110
# Keep track of the progress while downloading
108111
async def progress(current, total):
109112
print(f"{current * 100 / total:.1f}%")
@@ -138,6 +141,8 @@ async def progress(current, total):
138141
media = getattr(message, message.media.value, None)
139142
elif isinstance(message, str):
140143
media = message
144+
elif hasattr(message, "file_id"):
145+
media = getattr(message, "file_id")
141146

142147
if not media:
143148
raise ValueError("This message doesn't contain any downloadable media")
@@ -193,4 +198,4 @@ async def progress(current, total):
193198
if block:
194199
return await downloader
195200
else:
196-
asyncio.get_event_loop().create_task(downloader)
201+
asyncio.get_event_loop().create_task(downloader)

pyrogram/types/messages_and_media/message.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ async def _parse(
599599
chats: dict,
600600
topics: dict = None,
601601
is_scheduled: bool = False,
602-
replies: int = 1
602+
replies: int = 1,
603+
from_topic: types.ForumTopic = None
603604
):
604605
if isinstance(message, raw.types.MessageEmpty):
605606
return Message(id=message.id, empty=True, client=client, raw=message)
@@ -1066,6 +1067,9 @@ async def _parse(
10661067
if any((isinstance(entity, raw.types.MessageEntityBlockquote) for entity in message.entities)):
10671068
parsed_message.quote = True
10681069

1070+
if from_topic:
1071+
parsed_message.topic = from_topic
1072+
10691073
if message.reply_to:
10701074
if isinstance(message.reply_to, raw.types.MessageReplyHeader):
10711075
if message.reply_to.forum_topic:
@@ -1077,7 +1081,7 @@ async def _parse(
10771081

10781082
parsed_message.message_thread_id = thread_id
10791083

1080-
if topics:
1084+
if topics and not parsed_message.topic:
10811085
parsed_message.topic = types.ForumTopic._parse(client, topics[thread_id], users=users, chats=chats)
10821086
else:
10831087
if message.reply_to.quote:

0 commit comments

Comments
 (0)