From 81a454c29c004905443f3fcc6d82f383831c705b Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Wed, 10 Apr 2019 15:18:46 -0500 Subject: [PATCH] Read confirmations will be sent in real time in conversations --- changelog.md | 3 ++- src/controller/buffers.py | 11 ++++------- src/controller/mainController.py | 10 ---------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index c7265f7..068ec1b 100644 --- a/changelog.md +++ b/changelog.md @@ -8,7 +8,8 @@ * For users with multiple soundcards, there is a new tab in the preferences dialogue of Socializer, called sound. From there, you can define what soundcard will be used for input and output. * Improvements in conversation buffers: * it is possible to retrieve more items for conversation buffers. Due to API limitations, it is possible to load up to the last 600 messages for every conversation. Take into account that the process of loading more items takes some time. You will hear a message when the process is done. - * It is possible to delete entire conversations from the tree of buffers, by using the menu key and selecting "delete conversation". The conversation will be removed from VK. + * It is possible to delete entire conversations from the buffer's tree, by using the menu key and selecting "delete conversation". The conversation will be removed from VK. + * Read confirmations will be sent to VK as soon as you read the message. Before, read confirmations were being sent every 3 minutes to the social network. ## Changes in version 0.19 (13.03.2019) diff --git a/src/controller/buffers.py b/src/controller/buffers.py index b8b5e9b..4921892 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -911,13 +911,11 @@ class chatBuffer(baseBuffer): def insert(self, item, reversed=False): """ Add a new item to the list. Uses session.composefunc for parsing the dictionary and create a valid result for putting it in the list.""" + # as this tab is based in a text control, we have to overwrite the defaults. item_ = getattr(renderers, self.compose_function)(item, self.session) # the self.chat dictionary will have (first_line, last_line) as keys and message ID as a value for looking into it when needed. # Here we will get first and last line of a chat message appended to the history. - lines = self.tab.history.GetNumberOfLines() values = self.tab.add_message(item_[0], reverse=reversed) - if reversed: - values = (values[0]-lines, values[1]-lines) self.chats[values] = item["id"] def get_focused_post(self): @@ -933,7 +931,6 @@ class chatBuffer(baseBuffer): # position[2]+1 is added because line may start with 0, while in wx.TextCtrl.GetNumberLines() that is not possible. if position[2]+1 >= i[0] and position[2]+1 < i[1]: id_ = self.chats[i] -# print i break # Retrieve here the object based in id_ if id_ != None: @@ -949,9 +946,10 @@ 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 "read_state" in msg and msg["read_state"] == 0 and msg["id"] not in self.reads and "out" in msg and msg["out"] == 0: + # Mark unread conversations as read. + if "read_state" in msg and msg["read_state"] == 0 and "out" in msg and msg["out"] == 0: self.session.soundplayer.play("message_unread.ogg") - self.reads.append(msg["id"]) + call_threaded(self.session.vk.client.messages.markAsRead, peer_id=self.kwargs["peer_id"]) self.session.db[self.name]["items"][-1]["read_state"] = 1 if "attachments" in msg and len(msg["attachments"]) > 0: self.tab.attachments.list.Enable(True) @@ -1115,7 +1113,6 @@ class chatBuffer(baseBuffer): def __init__(self, unread=False, *args, **kwargs): super(chatBuffer, self).__init__(*args, **kwargs) self.unread = unread - self.reads = [] self.chats = dict() self.peer_typing = 0 self.last_keypress = time.time() diff --git a/src/controller/mainController.py b/src/controller/mainController.py index ebdee22..9660e4e 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -114,8 +114,6 @@ class Controller(object): self.window.realize() self.repeatedUpdate = RepeatingTimer(120, self.update_all_buffers) self.repeatedUpdate.start() - self.readMarker = RepeatingTimer(60, self.mark_as_read) - self.readMarker.start() def complete_buffer_creation(self, buffer, name_, position): answer = buffer.get_items() @@ -158,14 +156,6 @@ class Controller(object): call_threaded(self.chat_from_id, i["last_message"]["peer_id"], setfocus=False, unread=False) time.sleep(0.6) - def mark_as_read(self): - for i in self.buffers: - if hasattr(i, "reads") and len(i.reads) != 0: - response = self.session.vk.client.messages.markAsRead(peer_id=i.kwargs["peer_id"]) - i.clear_reads() - i.reads = [] - time.sleep(1) - def get_audio_albums(self, user_id=None, create_buffers=True, force_action=False): if self.session.settings["load_at_startup"]["audio_albums"] == False and force_action == False: return