Chats receiving new messages will be moved automatically to the first position in the chats section
This commit is contained in:
parent
bab02110b0
commit
d741035707
@ -13,6 +13,7 @@
|
||||
* Control + P: Play/pause.
|
||||
* control+Shift+P: Play all.
|
||||
* Fixed an error in the audio player that was skipping the first track if you were in the last song and pressed "play next" in the menu bar or via the keystroke.
|
||||
* Chats with unread messages will be placed at the top of the chats section. When a chat buffer receives a new message, socializer will move the buffer to the first position in the chats list. This should make easier for everyone to determine which chats contain unread items. ([#24,](https://code.manuelcortez.net/manuelcortez/socializer/issues/24))
|
||||
|
||||
## Changes in version 0.18 (21.01.2019)
|
||||
|
||||
|
@ -433,6 +433,7 @@ class Controller(object):
|
||||
num = self.session.order_buffer(buffer.name, data, True)
|
||||
buffer.insert(self.session.db[buffer.name]["items"][-1], False)
|
||||
self.session.soundplayer.play("message_received.ogg")
|
||||
wx.CallAfter(self.reorder_buffer, buffer)
|
||||
# Check if we have to read the message aloud
|
||||
if buffer == self.get_current_buffer():
|
||||
rendered_message = renderers.render_message(message, self.session)
|
||||
@ -670,4 +671,31 @@ class Controller(object):
|
||||
dlg.Destroy()
|
||||
|
||||
def on_report_error(self, *args, **kwargs):
|
||||
r = issueReporter.reportBug()
|
||||
r = issueReporter.reportBug()
|
||||
|
||||
def reorder_buffer(self, buffer):
|
||||
""" this puts the chat buffers at the top of the list when there are new incoming messages.
|
||||
In order to do so, we search for the current buffer's tab, remove the page from the TreeCtrl (without destroying the associated tab)
|
||||
and reinsert it as a new child of the chat buffer.
|
||||
Lastly we ensure the user is focused in the same buffer than before."""
|
||||
buffer_window = self.window.search(buffer.name)
|
||||
# If buffer window is already in the first position after chat, we should not do anything here because calculations for moving buffers are expensive.
|
||||
if buffer_window == self.window.search("chats")+1:
|
||||
return
|
||||
# Gets buffer title so we don't have to generate it again in future.
|
||||
buffer_title = self.window.get_buffer_text(buffer_window)
|
||||
# Determine if the current buffer is the buffer receiving a new message.
|
||||
if buffer == self.get_current_buffer():
|
||||
focused_buffer = True
|
||||
else:
|
||||
focused_buffer = False
|
||||
# This call will not destroy the associated tab for the chat buffer, thus allowing us to readd it in other position.
|
||||
self.window.remove_buffer_from_position(buffer_window)
|
||||
self.window.insert_chat_buffer(buffer.tab, buffer_title, self.window.search("chats")+1)
|
||||
# Let's manipulate focus so users will not notice the change in buffers.
|
||||
if focused_buffer:
|
||||
new_position = self.window.search(buffer.name)
|
||||
self.window.change_buffer(new_position)
|
||||
else:
|
||||
new_position = self.window.search(self.get_current_buffer().name)
|
||||
self.window.change_buffer(new_position)
|
@ -99,6 +99,9 @@ class mainWindow(wx.Frame):
|
||||
def insert_buffer(self, buffer, name, pos):
|
||||
return self.tb.InsertSubPage(pos, buffer, name)
|
||||
|
||||
def insert_chat_buffer(self, buffer, name, pos):
|
||||
return self.tb.InsertPage(pos, buffer, name)
|
||||
|
||||
def search(self, name_):
|
||||
for i in range(0, self.tb.GetPageCount()):
|
||||
if self.tb.GetPage(i).name == name_: return i
|
||||
@ -115,8 +118,10 @@ class mainWindow(wx.Frame):
|
||||
def change_buffer(self, position):
|
||||
self.tb.ChangeSelection(position)
|
||||
|
||||
def get_buffer_text(self):
|
||||
return self.tb.GetPageText(self.tb.GetSelection())
|
||||
def get_buffer_text(self, pos=None):
|
||||
if pos == None:
|
||||
pos = self.tb.GetSelection()
|
||||
return self.tb.GetPageText(pos)
|
||||
|
||||
def get_buffer_by_id(self, id):
|
||||
return self.nb.FindWindowById(id)
|
||||
@ -138,6 +143,9 @@ class mainWindow(wx.Frame):
|
||||
def remove_buffer(self, pos):
|
||||
self.tb.DeletePage(pos)
|
||||
|
||||
def remove_buffer_from_position(self, pos):
|
||||
return self.tb.RemovePage(pos)
|
||||
|
||||
def notify(self, title, text):
|
||||
self.notification = wx.adv.NotificationMessage(title, text, parent=self)
|
||||
self.notification.Show()
|
Loading…
Reference in New Issue
Block a user