From 5be6da7eeb13ec9a3fbe8c24b595bcfb881b3ad6 Mon Sep 17 00:00:00 2001 From: kirill Date: Fri, 24 Jan 2025 21:15:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B8=D1=87=D0=B5=D0=B3=D0=BE=20=D1=82?= =?UTF-8?q?=D0=BE=D0=BB=D0=BA=D0=BE=D0=BC=20=D0=BD=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8F=D0=BB,=20=D0=BD=D0=BE=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D1=8E=20get=5Fdialogs,=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D1=82=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D0=BD=D1=8B=D0=B9=20=D0=B4=D0=B8=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.py | 13 +++++++------ telegram/client.py | 17 +++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/app.py b/app/app.py index a3c1f09..6b15054 100644 --- a/app/app.py +++ b/app/app.py @@ -1,23 +1,23 @@ -from telethon import TelegramClient, events +#from telethon import TelegramClient, events from textual.app import App, ComposeResult -from textual.containers import Horizontal, VerticalScroll, Vertical, Container -from textual.widgets import Placeholder, Label, Static, Input, Button +from textual.containers import Horizontal, VerticalScroll +from textual.widgets import Static, Footer from widgets.chat import Chat from widgets.dialog import Dialog from telegram.client import TelegramClientWrapper from tokens import api_id, api_hash -from time import sleep class TelegramTUI(App): CSS_PATH = "../tcss/style.tcss" def __init__(self): super().__init__() - self.telegram_client = TelegramClientWrapper(api_id, api_hash, self.update_chat_list) + async def on_mount(self) -> None: + self.telegram_client = TelegramClientWrapper(api_id, api_hash, self.update_chat_list) self.chat_container = self.query_one("#main_container").query_one("#chats").query_one("#chat_container") - self.limit = 25 + self.limit = 100 for i in range(self.limit): chat = Chat(id=f"chat-{i + 1}") self.chat_container.mount(chat) @@ -51,6 +51,7 @@ class TelegramTUI(App): #self.notify("Новое сообщение") #колхоз дебаг def compose(self) -> ComposeResult: + yield Footer() with Horizontal(id="main_container"): with Horizontal(id="chats"): yield VerticalScroll(Static(id="chat_container")) diff --git a/telegram/client.py b/telegram/client.py index 4a3ab25..03b5fbe 100644 --- a/telegram/client.py +++ b/telegram/client.py @@ -6,8 +6,6 @@ class TelegramClientWrapper: self.client = TelegramClient('user', api_id, api_hash) self.client.on(events.NewMessage())(self.local_message_handler) - #ни то ни то не работает, костя спаси - async def local_message_handler(self, event): await self.message_handler() @@ -17,21 +15,24 @@ class TelegramClientWrapper: async def disconnect(self): await self.client.disconnect() - async def get_dialogs(self, limit=10): + async def get_dialogs(self, limit=None): + await self.client.get_dialogs(limit=limit) dialogs_list = [] async for dialog in self.client.iter_dialogs(limit=limit): dialogs_list.append(dialog) - return [self._map_dialog(d) for d in dialogs_list] + #return [self._map_dialog(d) for d in dialogs_list] + return dialogs_list - def _map_dialog(self, dialog): +#ого: + """def _map_dialog(self, dialog): return DialogInfo( id=dialog.id, name=utils.get_display_name(dialog.entity), message=dialog.message - ) + )""" -class DialogInfo: +"""class DialogInfo: def __init__(self, id, name, message): self.id = id self.name = name - self.message = message + self.message = message"""