mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 03:43:19 +00:00
wip
This commit is contained in:
parent
3d682441f2
commit
3479fcb9d4
2 changed files with 47 additions and 0 deletions
|
@ -533,6 +533,35 @@ class Controller:
|
|||
if self.model.set_current_chat_by_id(chat_id):
|
||||
self.render()
|
||||
|
||||
@bind(msg_handler, ["/"])
|
||||
def search_messages(self) -> None:
|
||||
"""Search contacts and set jumps to it if found"""
|
||||
msg = self.view.status.get_input(prefix="/")
|
||||
if not msg:
|
||||
return self.present_info("Search discarded")
|
||||
|
||||
chat = self.model.chats.chats[self.model.current_chat]
|
||||
chat_id = chat["id"]
|
||||
msg_id = chat["last_message"]["id"]
|
||||
|
||||
rv = self.tg.search_messages(msg, chat_id, msg_id)
|
||||
total_count = rv.update["total_count"]
|
||||
if total_count:
|
||||
return self.present_info(f"Found {total_count} messages")
|
||||
else:
|
||||
return self.present_info("Messages not found")
|
||||
|
||||
|
||||
messages = rv.update["messages"]
|
||||
if chat_id not in self.model.chats.chat_ids:
|
||||
self.present_info("Chat not loaded")
|
||||
return
|
||||
|
||||
self.model.chats.found_chats = chat_ids
|
||||
|
||||
if self.model.set_current_chat_by_id(chat_id):
|
||||
self.render()
|
||||
|
||||
@bind(chat_handler, ["c"])
|
||||
def view_contacts(self) -> None:
|
||||
contacts = self.model.users.get_contacts()
|
||||
|
|
18
tg/tdlib.py
18
tg/tdlib.py
|
@ -113,6 +113,24 @@ class Tdlib(Telegram):
|
|||
|
||||
return self._send_data(data)
|
||||
|
||||
def search_messages(
|
||||
self,
|
||||
target: str,
|
||||
offset_chat_id: int,
|
||||
offset_msg_id: int,
|
||||
limit: int = 10,
|
||||
) -> AsyncResult:
|
||||
data = {
|
||||
"@type": "searchMessages",
|
||||
"query": target,
|
||||
"limit": limit,
|
||||
"offset_date": 0,
|
||||
"offset_chat_id": offset_chat_id,
|
||||
"offset_message_id": offset_msg_id,
|
||||
"chat_list": None
|
||||
}
|
||||
return self._send_data(data, block=True)
|
||||
|
||||
def search_contacts(self, target: str, limit: int = 10) -> AsyncResult:
|
||||
data = {"@type": "searchChats", "query": target, "limit": limit}
|
||||
return self._send_data(data, block=True)
|
||||
|
|
Loading…
Reference in a new issue