Msg reply PoC

This commit is contained in:
Alexander Zveruk 2020-05-25 09:12:34 +03:00
parent c435ed4264
commit eb19aefc1b
3 changed files with 29 additions and 0 deletions

View file

@ -96,6 +96,7 @@ class Controller:
"a": lambda _: self.write_short_msg(),
"I": lambda _: self.write_long_msg(),
"A": lambda _: self.write_long_msg(),
"r": lambda _: self.reply_message(),
"bp": lambda _: self.breakpoint(),
" ": lambda _: self.toggle_select_msg(),
"^[": lambda _: self.discard_selected_msgs(), # esc
@ -213,6 +214,14 @@ class Controller:
with suspend(self.view):
breakpoint()
def reply_message(self):
# write new message
if msg := self.view.status.get_input():
self.model.reply_message(text=msg)
self.present_info("Message reply sent")
else:
self.present_info("Message reply wasn't sent")
def write_short_msg(self):
# write new message
if msg := self.view.status.get_input():

View file

@ -120,6 +120,14 @@ class Model:
limit = offset + page_size
return self.chats.fetch_chats(offset=offset, limit=limit)
def reply_message(self, text: str) -> bool:
chat_id = self.chats.id_by_index(self.current_chat)
if chat_id is None:
return False
reply_to_msg = self.current_msg_id
self.tg.reply_message(chat_id, reply_to_msg, text)
return True
def send_message(self, text: str) -> bool:
chat_id = self.chats.id_by_index(self.current_chat)
if chat_id is None:

View file

@ -20,6 +20,18 @@ class Tdlib(Telegram):
)
result.wait()
def reply_message(self, chat_id: int, reply_to_message_id: int, text: str) -> AsyncResult:
data = {
'@type': 'sendMessage',
'chat_id': chat_id,
'reply_to_message_id': reply_to_message_id,
'input_message_content': {
'@type': 'inputMessageText',
'text': {'@type': 'formattedText', 'text': text},
},
}
return self._send_data(data)
def send_doc(self, file_path: str, chat_id: int) -> AsyncResult:
data = {
"@type": "sendMessage",