Skip to content

Commit

Permalink
fix: remove old pyrogram depend
Browse files Browse the repository at this point in the history
  • Loading branch information
tangyoha committed Jun 18, 2023
1 parent fd67b07 commit 6176ab9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
20 changes: 14 additions & 6 deletions module/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,17 +568,25 @@ def update_config(self, immediate: bool = True):
# pylint: disable = R1733
for key, value in self.chat_download_config.items():
# pylint: disable = W0201
self.chat_download_config[key].ids_to_retry = (
list(set(value.ids_to_retry) - set(value.downloaded_ids))
+ value.failed_ids
before_last_read_message_id = self.config["chat"][idx].get(
"last_read_message_id", 0
)

unfinished_ids = set(value.ids_to_retry) | set(
range(before_last_read_message_id, value.last_read_message_id + 1)
)
unfinished_ids -= set(value.downloaded_ids)

self.chat_download_config[key].ids_to_retry = list(unfinished_ids)

if idx >= len(self.app_data["chat"]):
self.app_data["chat"].append({})

self.config["chat"][idx][
"last_read_message_id"
] = value.last_read_message_id
if len(value.downloaded_ids) > 0:
self.config["chat"][idx]["last_read_message_id"] = (
value.last_read_message_id + 1
)

self.app_data["chat"][idx]["chat_id"] = key
self.app_data["chat"][idx]["ids_to_retry"] = value.ids_to_retry
idx += 1
Expand Down
21 changes: 4 additions & 17 deletions module/get_chat_history_v2.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.
"""Rewrite pyrogram.get_chat_history"""

from datetime import datetime
from typing import AsyncGenerator, Optional, Union
Expand Down Expand Up @@ -60,6 +44,9 @@ async def get_chunk_v2(
return messages


# pylint disable=C0301


async def get_chat_history_v2(
self: pyrogram.Client,
chat_id: Union[int, str],
Expand Down
15 changes: 9 additions & 6 deletions tests/module/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,23 @@ def test_app(self):
self.assertEqual(app.proxy, {})
self.assertEqual(app.restart_program, False)

app.last_read_message_id = 3
app.chat_download_config[123] = ChatDownloadConfig()
app.chat_download_config[123].failed_ids.append(1)
app.chat_download_config[123].ids_to_retry.append(2)
app.config["chat"] = [{"chat_id": 123, "last_read_message_id": 0}]
app.chat_download_config[123].last_read_message_id = 13
app.chat_download_config[123].failed_ids.append(6)
app.chat_download_config[123].ids_to_retry.append(7)
app.chat_download_config[123].downloaded_ids.append(8)
app.chat_download_config[123].downloaded_ids.append(10)
app.chat_download_config[123].downloaded_ids.append(13)
app.config["chat"] = [{"chat_id": 123, "last_read_message_id": 5}]

app.update_config(False)

self.assertEqual(
app.chat_download_config[123].last_read_message_id,
app.chat_download_config[123].last_read_message_id + 1,
app.config["chat"][0]["last_read_message_id"],
)
self.assertEqual(
app.chat_download_config[123].ids_to_retry,
[5, 6, 7, 9, 11, 12],
app.app_data["chat"][0]["ids_to_retry"],
)

Expand Down

0 comments on commit 6176ab9

Please sign in to comment.