Merge pull request #59 from paul-nameless/fix-reply

Fix message reply
This commit is contained in:
Nameless 2020-05-30 20:25:29 +08:00 committed by GitHub
commit 500b5734ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View file

@ -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")

View file

@ -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: