diff --git a/tg/controllers.py b/tg/controllers.py index 21e2299..fce5326 100644 --- a/tg/controllers.py +++ b/tg/controllers.py @@ -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(): diff --git a/tg/models.py b/tg/models.py index 91758ec..3a0a42c 100644 --- a/tg/models.py +++ b/tg/models.py @@ -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: diff --git a/tg/tdlib.py b/tg/tdlib.py index 605efb0..a75f4f3 100644 --- a/tg/tdlib.py +++ b/tg/tdlib.py @@ -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",