Skip to content

Commit

Permalink
Fix download_media method not checking for file_id.
Browse files Browse the repository at this point in the history
Fix topic.top_message parsing.

Signed-off-by: Aliwoto <[email protected]>
  • Loading branch information
ALiwoto committed Mar 28, 2024
1 parent 79cbad9 commit 6e0bdf9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyrogram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

__version__ = "2.0.141"
__version__ = "2.0.142"
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
__copyright__ = "Copyright (C) 2017-present Dan <https://github.com/delivrance>"

Expand Down
12 changes: 12 additions & 0 deletions pyrogram/methods/chats/get_forum_topics_by_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ async def get_forum_topics_by_id(
chats = {c.id: c for c in getattr(r, "chats", [])}
messages = {m.id: m for m in getattr(r, "messages", [])}

for message in messages:
if isinstance(message, raw.types.MessageEmpty):
continue

messages[message.id] = await types.Message._parse(
client=self,
message=message,
users=users,
chats=chats,
replies=0
)

for current in getattr(r, "topics", []):
topics.append(types.ForumTopic._parse(
self,
Expand Down
7 changes: 6 additions & 1 deletion pyrogram/methods/messages/download_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ async def download_media(
# Download from file id
await app.download_media(message.photo.file_id)
# Download document of a message
await app.download_media(message.document)
# Keep track of the progress while downloading
async def progress(current, total):
print(f"{current * 100 / total:.1f}%")
Expand Down Expand Up @@ -138,6 +141,8 @@ async def progress(current, total):
media = getattr(message, message.media.value, None)
elif isinstance(message, str):
media = message
elif hasattr(message, "file_id"):
media = getattr(message, "file_id")

if not media:
raise ValueError("This message doesn't contain any downloadable media")
Expand Down Expand Up @@ -193,4 +198,4 @@ async def progress(current, total):
if block:
return await downloader
else:
asyncio.get_event_loop().create_task(downloader)
asyncio.get_event_loop().create_task(downloader)
8 changes: 6 additions & 2 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ async def _parse(
chats: dict,
topics: dict = None,
is_scheduled: bool = False,
replies: int = 1
replies: int = 1,
from_topic: types.ForumTopic = None
):
if isinstance(message, raw.types.MessageEmpty):
return Message(id=message.id, empty=True, client=client, raw=message)
Expand Down Expand Up @@ -1066,6 +1067,9 @@ async def _parse(
if any((isinstance(entity, raw.types.MessageEntityBlockquote) for entity in message.entities)):
parsed_message.quote = True

if from_topic:
parsed_message.topic = from_topic

if message.reply_to:
if isinstance(message.reply_to, raw.types.MessageReplyHeader):
if message.reply_to.forum_topic:
Expand All @@ -1077,7 +1081,7 @@ async def _parse(

parsed_message.message_thread_id = thread_id

if topics:
if topics and not parsed_message.topic:
parsed_message.topic = types.ForumTopic._parse(client, topics[thread_id], users=users, chats=chats)
else:
if message.reply_to.quote:
Expand Down

0 comments on commit 6e0bdf9

Please sign in to comment.