diff --git a/tg/controllers.py b/tg/controllers.py index 3195a48..bdbea13 100644 --- a/tg/controllers.py +++ b/tg/controllers.py @@ -240,13 +240,17 @@ class Controller: def reply_message(self): # write new message + chat_id = self.model.current_chat_id + reply_to_msg = self.model.current_msg_id if msg := self.view.status.get_input(): - self.model.reply_message(text=msg) + self.tg.reply_message(chat_id, reply_to_msg, msg) self.present_info("Message reply sent") else: self.present_info("Message reply wasn't sent") def reply_with_long_message(self): + chat_id = self.model.current_chat_id + reply_to_msg = self.model.current_msg_id msg = MsgProxy(self.model.current_msg) with NamedTemporaryFile("w+", suffix=".txt") as f, suspend( self.view @@ -256,7 +260,7 @@ class Controller: s.call(config.LONG_MSG_CMD.format(file_path=f.name)) with open(f.name) as f: if msg := strip_replied_msg(f.read().strip()): - self.model.reply_message(text=msg) + self.tg.reply_message(chat_id, reply_to_msg, msg) self.present_info("Message sent") else: self.present_info("Message wasn't sent") diff --git a/tg/models.py b/tg/models.py index d7cd5f1..e659e61 100644 --- a/tg/models.py +++ b/tg/models.py @@ -28,6 +28,10 @@ class Model: def get_user(self, user_id): return self.users.get_user(user_id) + @property + def current_chat_id(self): + return self.chats.id_by_index(self.current_chat) + def get_current_chat_msg_idx(self) -> Optional[int]: chat_id = self.chats.id_by_index(self.current_chat) if chat_id is None: @@ -120,14 +124,6 @@ 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: