From 977dcb7dc3d44af0c8c8747229fd10d6abb4fa1f Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Mon, 17 Dec 2018 17:47:15 -0600 Subject: [PATCH] Improvement to unread messages: Mark as unread only messages sent by another user --- src/controller/buffers.py | 2 +- src/controller/mainController.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/controller/buffers.py b/src/controller/buffers.py index 26462dd..82cf21f 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -700,7 +700,7 @@ class chatBuffer(baseBuffer): msg = self.get_focused_post() if msg == False: # Handle the case where the last line of the control cannot be matched to anything. return - if msg.has_key("read_state") and msg["read_state"] == 0 and msg["id"] not in self.reads: + if msg.has_key("read_state") and msg["read_state"] == 0 and msg["id"] not in self.reads and msg.has_key("out") and msg["out"] == 0: self.session.soundplayer.play("message_unread.ogg") self.reads.append(msg["id"]) self.session.db[self.name]["items"][-1]["read_state"] = 1 diff --git a/src/controller/mainController.py b/src/controller/mainController.py index aa91f70..1d13d89 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -406,10 +406,12 @@ class Controller(object): def get_chat(self, obj=None): """ Searches or creates a chat buffer with the id of the user that is sending or receiving a message. obj vk_api.longpoll.EventType: an event wich defines some data from the vk's long poll server.""" + message = {} # If someone else sends a message to the current user. if obj.to_me: buffer = self.search_chat_buffer(obj.user_id) uid = obj.user_id + message.update(out=0) # If the current user sends a message to someone else. else: buffer = self.search_chat_buffer(obj.peer_id) @@ -420,7 +422,7 @@ class Controller(object): self.session.soundplayer.play("conversation_opened.ogg") return # If the chat already exists, let's create a dictionary wich will contains data of the received message. - message = {"id": obj.message_id, "user_id": uid, "date": obj.timestamp, "body": obj.text, "attachments": obj.attachments, "read_state": 0} + message.update(id=obj.message_id, user_id=uid, date=obj.timestamp, body=obj.text, attachments=obj.attachments, read_state=0) # if attachments is true, let's request for the full message with attachments formatted in a better way. # Todo: code improvements. We shouldn't need to request the same message again just for these attachments. if len(message["attachments"]) != 0: