Merge pull request #178 from paul-nameless/mark-as-viewed

Mark msgs as viewed when sent new msg
This commit is contained in:
Nameless 2020-09-14 08:02:46 +03:00 committed by GitHub
commit c38b1186d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View file

@ -263,6 +263,7 @@ class Controller:
return return
reply_to_msg = self.model.current_msg_id reply_to_msg = self.model.current_msg_id
if msg := self.view.status.get_input(): if msg := self.view.status.get_input():
self.model.view_all_msgs()
self.tg.reply_message(chat_id, reply_to_msg, msg) self.tg.reply_message(chat_id, reply_to_msg, msg)
self.present_info("Message reply sent") self.present_info("Message reply sent")
else: else:
@ -286,6 +287,7 @@ class Controller:
s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name))) s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name)))
with open(f.name) as f: with open(f.name) as f:
if replied_msg := strip_replied_msg(f.read().strip()): if replied_msg := strip_replied_msg(f.read().strip()):
self.model.view_all_msgs()
self.tg.reply_message(chat_id, reply_to_msg, replied_msg) self.tg.reply_message(chat_id, reply_to_msg, replied_msg)
self.present_info("Message sent") self.present_info("Message sent")
else: else:
@ -697,10 +699,7 @@ class Controller:
@bind(chat_handler, ["r"]) @bind(chat_handler, ["r"])
def read_msgs(self) -> None: def read_msgs(self) -> None:
chat = self.model.chats.chats[self.model.current_chat] self.model.view_all_msgs()
chat_id = chat["id"]
msg_id = chat["last_message"]["id"]
self.tg.view_messages(chat_id, [msg_id])
self.render() self.render()
@bind(chat_handler, ["m"]) @bind(chat_handler, ["m"])

View file

@ -77,9 +77,11 @@ class Model:
return self.current_msg["id"] return self.current_msg["id"]
def jump_bottom(self) -> bool: def jump_bottom(self) -> bool:
res = False
if chat_id := self.chats.id_by_index(self.current_chat): if chat_id := self.chats.id_by_index(self.current_chat):
return self.msgs.jump_bottom(chat_id) res = self.msgs.jump_bottom(chat_id)
return False self.view_current_msg()
return res
def set_current_chat_by_id(self, chat_id: int) -> bool: def set_current_chat_by_id(self, chat_id: int) -> bool:
idx = next( idx = next(
@ -122,12 +124,17 @@ class Model:
if chat_id := self.chats.id_by_index(self.current_chat): if chat_id := self.chats.id_by_index(self.current_chat):
self.tg.view_messages(chat_id, [msg_id]) self.tg.view_messages(chat_id, [msg_id])
def view_all_msgs(self) -> None:
chat = self.chats.chats[self.current_chat]
chat_id = chat["id"]
msg_id = chat["last_message"]["id"]
self.tg.view_messages(chat_id, [msg_id])
def next_msg(self, step: int = 1) -> bool: def next_msg(self, step: int = 1) -> bool:
chat_id = self.chats.id_by_index(self.current_chat) chat_id = self.chats.id_by_index(self.current_chat)
if not chat_id: if not chat_id:
return False return False
is_next = self.msgs.next_msg(chat_id, step) is_next = self.msgs.next_msg(chat_id, step)
if is_next:
self.view_current_msg() self.view_current_msg()
return is_next return is_next
@ -155,6 +162,9 @@ class Model:
chat_id = self.chats.id_by_index(self.current_chat) chat_id = self.chats.id_by_index(self.current_chat)
if chat_id is None: if chat_id is None:
return False return False
# order is matter: this should be before send_message
# otherwise it will view message that was sent
self.view_all_msgs()
self.msgs.send_message(chat_id, text) self.msgs.send_message(chat_id, text)
return True return True