From d89abaa2db0a7f7979d6db97a1ebe1d66871164a Mon Sep 17 00:00:00 2001 From: Paul Nameless Date: Fri, 11 Sep 2020 12:28:19 +0300 Subject: [PATCH] Mark msgs as viewed when sent new msg --- tg/controllers.py | 5 +---- tg/models.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tg/controllers.py b/tg/controllers.py index 0fa8b04..b21e7e0 100644 --- a/tg/controllers.py +++ b/tg/controllers.py @@ -697,10 +697,7 @@ class Controller: @bind(chat_handler, ["r"]) def read_msgs(self) -> None: - chat = self.model.chats.chats[self.model.current_chat] - chat_id = chat["id"] - msg_id = chat["last_message"]["id"] - self.tg.view_messages(chat_id, [msg_id]) + self.model.view_all_msgs() self.render() @bind(chat_handler, ["m"]) diff --git a/tg/models.py b/tg/models.py index 2c810c7..2ca9690 100644 --- a/tg/models.py +++ b/tg/models.py @@ -77,9 +77,11 @@ class Model: return self.current_msg["id"] def jump_bottom(self) -> bool: + res = False if chat_id := self.chats.id_by_index(self.current_chat): - return self.msgs.jump_bottom(chat_id) - return False + res = self.msgs.jump_bottom(chat_id) + self.view_current_msg() + return res def set_current_chat_by_id(self, chat_id: int) -> bool: idx = next( @@ -122,13 +124,18 @@ class Model: if chat_id := self.chats.id_by_index(self.current_chat): 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: chat_id = self.chats.id_by_index(self.current_chat) if not chat_id: return False is_next = self.msgs.next_msg(chat_id, step) - if is_next: - self.view_current_msg() + self.view_current_msg() return is_next def prev_msg(self, step: int = 1) -> bool: @@ -155,6 +162,9 @@ class Model: chat_id = self.chats.id_by_index(self.current_chat) if chat_id is None: return False + # order is matter: this should be before send_message + # otherwise it vill view message that was sent + self.view_all_msgs() self.msgs.send_message(chat_id, text) return True