From 8d9082235be1bb4a7da8549e75efde2bbcc4b0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Mon, 6 Jun 2016 04:27:07 -0500 Subject: [PATCH] Marks read messages every two minutes --- src/controller/buffers.py | 11 ++++++++++- src/controller/mainController.py | 16 +++++++++++++++- src/wxUI/tabs/home.py | 3 +++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/controller/buffers.py b/src/controller/buffers.py index d0deb75..f04c3ad 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -274,13 +274,18 @@ class empty(object): class chatBuffer(baseBuffer): def onFocus(self, *args, **kwargs): - pass + msg = self.session.db[self.name]["items"][-1] + if msg["read_state"] == 0 and msg["id"] not in self.reads: + self.reads.append(msg["id"]) + self.session.db[self.name]["items"][-1]["read_state"] = 1 + def create_tab(self, parent): self.tab = home.chatTab(parent) def connect_events(self): widgetUtils.connect_event(self.tab.send, widgetUtils.BUTTON_PRESSED, self.send_chat_to_user) + self.tab.set_focus_function(self.onFocus) def get_items(self, show_nextpage=False): retrieved = True # Control variable for handling unauthorised/connection errors. @@ -308,6 +313,10 @@ class chatBuffer(baseBuffer): if text == "": return response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text) + def __init__(self, *args, **kwargs): + super(chatBuffer, self).__init__(*args, **kwargs) + self.reads = [] + class peopleBuffer(feedBuffer): def create_tab(self, parent): diff --git a/src/controller/mainController.py b/src/controller/mainController.py index f276b35..3158fde 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -61,6 +61,10 @@ class Controller(object): self.window.insert_buffer(home.tab, _(u"Home"), self.window.search("posts")) self.repeatedUpdate = RepeatingTimer(180, self.update_all_buffers) self.repeatedUpdate.start() + + self.readMarker = RepeatingTimer(120, self.mark_as_read) + self.readMarker.start() + feed = buffers.feedBuffer(parent=self.window.tb, name="me_feed", composefunc="compose_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"]) self.buffers.append(feed) self.window.insert_buffer(feed.tab, _(u"My wall"), self.window.search("posts")) @@ -317,9 +321,19 @@ class Controller(object): def set_online(self): r = self.session.vk.client.account.setOnline() - print "online: %d" % (r,) def create_unread_messages(self): msgs = self.session.vk.client.messages.getDialogs(count=200, unread=1) for i in msgs["items"]: wx.CallAfter(self.chat_from_id, i["message"]["user_id"], setfocus=False) + + def mark_as_read(self): + print "Marking as read" + ids = "" + for i in self.buffers: + if hasattr(i, "reads"): + for z in i.reads: + ids = ids+"%d," % (z,) + i.reads = [] + if ids != "": + response = self.session.vk.client.messages.markAsRead(message_ids=ids) diff --git a/src/wxUI/tabs/home.py b/src/wxUI/tabs/home.py index 2ff7e4a..d306e51 100644 --- a/src/wxUI/tabs/home.py +++ b/src/wxUI/tabs/home.py @@ -143,6 +143,9 @@ class chatTab(wx.Panel): box.Add(self.text, 0, wx.ALL, 5) return box + def set_focus_function(self, focus_function): + self.list.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, focus_function) + class peopleTab(homeTab): def create_list(self):