mirror of
https://github.com/avitoras/telegram-tui.git
synced 2025-07-27 19:26:10 +00:00
ничего толком не поменял, но изменил функцию get_dialogs, которая теперь возвращает полный диалог
This commit is contained in:
parent
3472ae798d
commit
5be6da7eeb
13
app/app.py
13
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.app import App, ComposeResult
|
||||||
from textual.containers import Horizontal, VerticalScroll, Vertical, Container
|
from textual.containers import Horizontal, VerticalScroll
|
||||||
from textual.widgets import Placeholder, Label, Static, Input, Button
|
from textual.widgets import Static, Footer
|
||||||
from widgets.chat import Chat
|
from widgets.chat import Chat
|
||||||
from widgets.dialog import Dialog
|
from widgets.dialog import Dialog
|
||||||
from telegram.client import TelegramClientWrapper
|
from telegram.client import TelegramClientWrapper
|
||||||
from tokens import api_id, api_hash
|
from tokens import api_id, api_hash
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
class TelegramTUI(App):
|
class TelegramTUI(App):
|
||||||
CSS_PATH = "../tcss/style.tcss"
|
CSS_PATH = "../tcss/style.tcss"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.telegram_client = TelegramClientWrapper(api_id, api_hash, self.update_chat_list)
|
|
||||||
|
|
||||||
async def on_mount(self) -> None:
|
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.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):
|
for i in range(self.limit):
|
||||||
chat = Chat(id=f"chat-{i + 1}")
|
chat = Chat(id=f"chat-{i + 1}")
|
||||||
self.chat_container.mount(chat)
|
self.chat_container.mount(chat)
|
||||||
@ -51,6 +51,7 @@ class TelegramTUI(App):
|
|||||||
#self.notify("Новое сообщение") #колхоз дебаг
|
#self.notify("Новое сообщение") #колхоз дебаг
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
|
yield Footer()
|
||||||
with Horizontal(id="main_container"):
|
with Horizontal(id="main_container"):
|
||||||
with Horizontal(id="chats"):
|
with Horizontal(id="chats"):
|
||||||
yield VerticalScroll(Static(id="chat_container"))
|
yield VerticalScroll(Static(id="chat_container"))
|
||||||
|
@ -6,8 +6,6 @@ class TelegramClientWrapper:
|
|||||||
self.client = TelegramClient('user', api_id, api_hash)
|
self.client = TelegramClient('user', api_id, api_hash)
|
||||||
self.client.on(events.NewMessage())(self.local_message_handler)
|
self.client.on(events.NewMessage())(self.local_message_handler)
|
||||||
|
|
||||||
#ни то ни то не работает, костя спаси
|
|
||||||
|
|
||||||
async def local_message_handler(self, event):
|
async def local_message_handler(self, event):
|
||||||
await self.message_handler()
|
await self.message_handler()
|
||||||
|
|
||||||
@ -17,21 +15,24 @@ class TelegramClientWrapper:
|
|||||||
async def disconnect(self):
|
async def disconnect(self):
|
||||||
await self.client.disconnect()
|
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 = []
|
dialogs_list = []
|
||||||
async for dialog in self.client.iter_dialogs(limit=limit):
|
async for dialog in self.client.iter_dialogs(limit=limit):
|
||||||
dialogs_list.append(dialog)
|
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(
|
return DialogInfo(
|
||||||
id=dialog.id,
|
id=dialog.id,
|
||||||
name=utils.get_display_name(dialog.entity),
|
name=utils.get_display_name(dialog.entity),
|
||||||
message=dialog.message
|
message=dialog.message
|
||||||
)
|
)"""
|
||||||
|
|
||||||
class DialogInfo:
|
"""class DialogInfo:
|
||||||
def __init__(self, id, name, message):
|
def __init__(self, id, name, message):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.message = message
|
self.message = message"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user