Add conversation sorting

This commit is contained in:
Fierelier 2020-11-25 02:08:41 +01:00
parent ec643880ef
commit 7a70dbeaec
1 changed files with 60 additions and 2 deletions

View File

@ -45,6 +45,10 @@ online = True
def doNothing():
pass
def listMove(list,ind,newInd):
if newInd > ind: newInd = newInd - 1
list.insert(newInd,list.pop(ind))
def addGuiTask(gui,func,args,kwargs,condition = None):
guiTasks.append((gui,func,args,kwargs,condition))
@ -359,8 +363,58 @@ class guiChannels:
channels.clear()
qlist.clear()
def repopulateChannels(self,list):
channels = None
qlist = None
if list == "conversations":
channels = self.conversations
qlist = self.conversationList
qlist.clear()
for channel in channels:
qlist.addItem(getChannelDisplayName(channel))
def moveChannel(self,list,channel,index):
pass
channels = None
if list == "conversations":
channels = self.conversations
listMove(channels,channels.index(channel),index)
self.repopulateChannels(list)
def sortChannels(self,list):
channels = None
if list == "conversations":
channels = self.conversations
newChannels = []
while True:
index = 0
length = len(channels)
largestTime = None
largestElement = None
while index < length:
channel = channels[index]
time = getLastMessageTime(channel)
if not time: index += 1; continue
if not largestTime:
largestTime = time
largestElement = index
index += 1
continue
if time < largestTime:
largestTime = time
largestElement = index
index += 1
if largestElement == None: break
newChannels.append(channels.pop(largestElement))
newChannels.reverse()
newChannels.extend(channels)
channels.clear()
channels.extend(newChannels)
self.repopulateChannels(list)
def addChannel(self,list,channel):
channels = None
@ -583,7 +637,7 @@ def discordClient(token):
for channel in client.private_channels:
addGuiTask(gui,gui.addChannel,("conversations",channel,),{})
addGuiTask(None,doNothing,(),{},condition)
addGuiTask(gui,gui.sortChannels,("conversations",),{},condition)
guiLock.release()
condition.wait()
condition.release()
@ -629,6 +683,10 @@ def discordClient(token):
addGuiTask(None,playNotificationSound,(),{})
for gui in openGuis:
if gui.type == "channels":
if message.channel in gui.conversations:
addGuiTask(gui,gui.moveChannel,("conversations",message.channel,0),{})
if gui.type == "channel":
if message.channel != gui.channel: continue
for msg in messages: