From 5dbd7a843bc3918d8523ce47ad3716b344a6bdd0 Mon Sep 17 00:00:00 2001 From: Paul Nameless Date: Thu, 7 May 2020 10:14:34 +0800 Subject: [PATCH] Fix downloading voice msg and remove unnecessary sort operation --- tg/models/__init__.py | 6 +----- tg/msg.py | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/tg/models/__init__.py b/tg/models/__init__.py index cd01a6b..9219087 100644 --- a/tg/models/__init__.py +++ b/tg/models/__init__.py @@ -229,11 +229,9 @@ class MsgModel: log.info(f"adding {msg_id=} {message}") self.msgs[chat_id].append(message) msg_set.add(msg_id) - self.msgs[chat_id] = sorted( self.msgs[chat_id], key=lambda d: d["id"], reverse=True ) - return True def add_messages(self, chat_id: int, messages: Any) -> bool: @@ -282,9 +280,7 @@ class MsgModel: messages = self._fetch_msgs_until_limit(chat_id, offset, limit) self.add_messages(chat_id, messages) - return sorted(self.msgs[chat_id], key=lambda d: d["id"], reverse=True)[ - offset:limit - ] + return self.msgs[chat_id][offset:limit] def send_message(self, chat_id: int, text: str) -> None: log.info("Sending msg") diff --git a/tg/msg.py b/tg/msg.py index 8dd0fee..3add00a 100644 --- a/tg/msg.py +++ b/tg/msg.py @@ -85,6 +85,7 @@ class MsgProxy: "video", "recording", "sticker", + "voice", ): return None doc = self.get_doc(self.msg)