Mark unread messags as read and play sound when unread messages are focused
This commit is contained in:
parent
a21d0f8a73
commit
4b51126239
@ -7,6 +7,8 @@
|
||||
* Audio albums are loaded correctly.
|
||||
* It is possible to play audios added by friends appearing in the news feed.
|
||||
* Adding and removing an audio file to your library works.
|
||||
* Unread messages will play a sound when focused.
|
||||
* Unread messages will be marked as read when user focuses them.
|
||||
|
||||
## Changes in version 0.16 (13.12.2018)
|
||||
|
||||
@ -69,6 +71,3 @@
|
||||
* Added a new attachments' list. When a post is opened, this list will show up if there are attachments in the current post (attachments are audio, photos, video and links). You will be able to interact with the supported data (at the moment only photos, videos, audio and links are supported, more will be added in future).
|
||||
* Added a changelog file which could be opened from the help menu.
|
||||
* Added a preferences dialogue and a new application menu in the menu bar. From this dialogue you can change the number of items to be loaded for every buffer.
|
||||
|
||||
---
|
||||
© 2016, manuel cortéz.
|
@ -653,6 +653,7 @@ class chatBuffer(baseBuffer):
|
||||
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:
|
||||
self.session.soundplayer.play("message_unread.ogg")
|
||||
self.reads.append(msg["id"])
|
||||
self.session.db[self.name]["items"][-1]["read_state"] = 1
|
||||
# print msg
|
||||
@ -681,7 +682,7 @@ class chatBuffer(baseBuffer):
|
||||
self.send_chat_to_user()
|
||||
event.Skip()
|
||||
|
||||
def get_items(self, show_nextpage=False):
|
||||
def get_items(self, show_nextpage=False, unread=False):
|
||||
if self.can_get_items == False: return
|
||||
retrieved = True # Control variable for handling unauthorised/connection errors.
|
||||
try:
|
||||
@ -700,6 +701,8 @@ class chatBuffer(baseBuffer):
|
||||
else:
|
||||
if num > 0:
|
||||
[self.insert(i, False) for i in self.session.db[self.name]["items"][:num]]
|
||||
if unread:
|
||||
self.session.db[self.name]["items"][-1].update(read_state=0)
|
||||
return retrieved
|
||||
|
||||
def add_attachment(self, *args, **kwargs):
|
||||
|
@ -67,9 +67,9 @@ class Controller(object):
|
||||
self.buffers.append(home)
|
||||
# Translators: Newsfeed's name in the tree view.
|
||||
self.window.insert_buffer(home.tab, _(u"Home"), self.window.search("posts"))
|
||||
self.repeatedUpdate = RepeatingTimer(180, self.update_all_buffers)
|
||||
self.repeatedUpdate = RepeatingTimer(120, self.update_all_buffers)
|
||||
self.repeatedUpdate.start()
|
||||
self.readMarker = RepeatingTimer(120, self.mark_as_read)
|
||||
self.readMarker = RepeatingTimer(60, self.mark_as_read)
|
||||
self.readMarker.start()
|
||||
feed = buffers.feedBuffer(parent=self.window.tb, name="me_feed", composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"])
|
||||
self.buffers.append(feed)
|
||||
@ -363,7 +363,7 @@ class Controller(object):
|
||||
if i.kwargs.has_key("user_id") and i.kwargs["user_id"] == user_id: return i
|
||||
return None
|
||||
|
||||
def chat_from_id(self, user_id, setfocus=True):
|
||||
def chat_from_id(self, user_id, setfocus=True, unread=False):
|
||||
b = self.search_chat_buffer(user_id)
|
||||
if b != None:
|
||||
pos = self.window.search(b.name)
|
||||
@ -378,7 +378,7 @@ class Controller(object):
|
||||
if setfocus:
|
||||
pos = self.window.search(buffer.name)
|
||||
self.window.change_buffer(pos)
|
||||
wx.CallAfter(buffer.get_items)
|
||||
wx.CallAfter(buffer.get_items, unread=unread)
|
||||
if setfocus: buffer.tab.text.SetFocus()
|
||||
return True
|
||||
|
||||
@ -411,17 +411,18 @@ class Controller(object):
|
||||
uid = obj.peer_id
|
||||
# If there is no buffer, we must create one in a wxThread so it will not crash.
|
||||
if buffer == None:
|
||||
wx.CallAfter(self.chat_from_id, uid, setfocus=self.session.settings["chat"]["automove_to_conversations"])
|
||||
wx.CallAfter(self.chat_from_id, uid, setfocus=self.session.settings["chat"]["automove_to_conversations"], unread=True)
|
||||
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}
|
||||
message = {"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:
|
||||
message_ids = message["id"]
|
||||
results = self.session.vk.client.messages.getById(message_ids=message_ids)
|
||||
message = results["items"][0]
|
||||
message.update(read_state=0)
|
||||
if obj.from_me:
|
||||
message["from_id"] = self.session.user_id
|
||||
else:
|
||||
@ -462,17 +463,14 @@ class Controller(object):
|
||||
time.sleep(2)
|
||||
return self.create_unread_messages()
|
||||
for i in msgs["items"]:
|
||||
wx.CallAfter(self.chat_from_id, i["message"]["user_id"], setfocus=False)
|
||||
wx.CallAfter(self.chat_from_id, i["message"]["user_id"], setfocus=False, unread=True)
|
||||
|
||||
def mark_as_read(self):
|
||||
ids = ""
|
||||
for i in self.buffers:
|
||||
if hasattr(i, "reads"):
|
||||
for z in i.reads:
|
||||
ids = ids+"%d," % (z,)
|
||||
if hasattr(i, "reads") and len(i.reads) != 0:
|
||||
response = self.session.vk.client.messages.markAsRead(peer_id=i.kwargs["user_id"])
|
||||
i.reads = []
|
||||
if ids != "":
|
||||
response = self.session.vk.client.messages.markAsRead(message_ids=ids)
|
||||
time.sleep(1)
|
||||
|
||||
def get_audio_albums(self, user_id=None):
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user