Unread count and subscriptions
- unread count was optimised (based on profiling) - unread count is now accurate - listing subscription messagelists and count fixed
This commit is contained in:
parent
b194e4ca20
commit
6dff105a5b
|
@ -902,65 +902,57 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.ui.tabWidget.setCurrentIndex(3)
|
self.ui.tabWidget.setCurrentIndex(3)
|
||||||
|
|
||||||
def propagateUnreadCount(self, address = None, folder = "inbox", widget = None, type = 1):
|
def propagateUnreadCount(self, address = None, folder = "inbox", widget = None, type = 1):
|
||||||
def updateUnreadCount(item):
|
|
||||||
# if refreshing the account root, we need to rescan folders
|
|
||||||
if type == 0 or (folder is None and isinstance(item, Ui_FolderWidget)):
|
|
||||||
if addressItem.type in [AccountMixin.SUBSCRIPTION, AccountMixin.MAILINGLIST]:
|
|
||||||
xAddress = "fromaddress"
|
|
||||||
else:
|
|
||||||
xAddress = "toaddress"
|
|
||||||
xFolder = folder
|
|
||||||
if isinstance(item, Ui_FolderWidget):
|
|
||||||
xFolder = item.folderName
|
|
||||||
if xFolder == "new":
|
|
||||||
xFolder = "inbox"
|
|
||||||
if addressItem.type == AccountMixin.ALL:
|
|
||||||
if xFolder:
|
|
||||||
queryreturn = sqlQuery("SELECT COUNT(*) FROM inbox WHERE folder = ? AND read = 0", xFolder)
|
|
||||||
else:
|
|
||||||
queryreturn = sqlQuery("SELECT COUNT(*) FROM inbox WHERE read = 0")
|
|
||||||
else:
|
|
||||||
if address and xFolder:
|
|
||||||
queryreturn = sqlQuery("SELECT COUNT(*) FROM inbox WHERE " + xAddress + " = ? AND folder = ? AND read = 0", address, xFolder)
|
|
||||||
elif address:
|
|
||||||
queryreturn = sqlQuery("SELECT COUNT(*) FROM inbox WHERE " + xAddress + " = ? AND read = 0", address)
|
|
||||||
for row in queryreturn:
|
|
||||||
item.setUnreadCount(int(row[0]))
|
|
||||||
if isinstance(item, Ui_AddressWidget) and item.type == AccountMixin.ALL:
|
|
||||||
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount())
|
|
||||||
elif type == 1:
|
|
||||||
item.setUnreadCount(item.unreadCount + 1)
|
|
||||||
if isinstance(item, Ui_AddressWidget) and item.type == AccountMixin.ALL:
|
|
||||||
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount(self.unreadCount + 1))
|
|
||||||
elif type == -1:
|
|
||||||
item.setUnreadCount(item.unreadCount - 1)
|
|
||||||
if isinstance(item, Ui_AddressWidget) and item.type == AccountMixin.ALL:
|
|
||||||
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount(self.unreadCount -1))
|
|
||||||
|
|
||||||
widgets = [self.ui.treeWidgetYourIdentities, self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans]
|
widgets = [self.ui.treeWidgetYourIdentities, self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans]
|
||||||
|
queryReturn = sqlQuery("SELECT toaddress, folder, COUNT(msgid) AS cnt FROM inbox WHERE read = 0 GROUP BY toaddress, folder")
|
||||||
|
totalUnread = {}
|
||||||
|
normalUnread = {}
|
||||||
|
for row in queryReturn:
|
||||||
|
normalUnread[row[0]] = {}
|
||||||
|
if row[1] in ["trash"]:
|
||||||
|
continue
|
||||||
|
normalUnread[row[0]][row[1]] = row[2]
|
||||||
|
if row[1] in totalUnread:
|
||||||
|
totalUnread[row[1]] += row[2]
|
||||||
|
else:
|
||||||
|
totalUnread[row[1]] = row[2]
|
||||||
|
queryReturn = sqlQuery("SELECT fromaddress, folder, COUNT(msgid) AS cnt FROM inbox WHERE read = 0 AND toaddress = ? GROUP BY fromaddress, folder", str_broadcast_subscribers)
|
||||||
|
broadcastsUnread = {}
|
||||||
|
for row in queryReturn:
|
||||||
|
broadcastsUnread[row[0]] = {}
|
||||||
|
broadcastsUnread[row[0]][row[1]] = row[2]
|
||||||
|
|
||||||
for treeWidget in widgets:
|
for treeWidget in widgets:
|
||||||
root = treeWidget.invisibleRootItem()
|
root = treeWidget.invisibleRootItem()
|
||||||
for i in range(root.childCount()):
|
for i in range(root.childCount()):
|
||||||
addressItem = root.child(i)
|
addressItem = root.child(i)
|
||||||
if addressItem.type != AccountMixin.ALL and address is not None and addressItem.data(0, QtCore.Qt.UserRole) != address:
|
newCount = 0
|
||||||
continue
|
if addressItem.type == AccountMixin.ALL:
|
||||||
if folder not in ["trash"]:
|
newCount = sum(totalUnread.itervalues())
|
||||||
updateUnreadCount(addressItem)
|
self.drawTrayIcon(self.currentTrayIconFileName, newCount)
|
||||||
|
elif addressItem.type == AccountMixin.SUBSCRIPTION:
|
||||||
|
if addressItem.address in broadcastsUnread:
|
||||||
|
newCount = sum(broadcastsUnread[addressItem.address].itervalues())
|
||||||
|
elif addressItem.address in normalUnread:
|
||||||
|
newCount = sum(normalUnread[addressItem.address].itervalues())
|
||||||
|
if newCount != addressItem.unreadCount:
|
||||||
|
addressItem.setUnreadCount(newCount)
|
||||||
if addressItem.childCount == 0:
|
if addressItem.childCount == 0:
|
||||||
continue
|
continue
|
||||||
for j in range(addressItem.childCount()):
|
for j in range(addressItem.childCount()):
|
||||||
folderItem = addressItem.child(j)
|
folderItem = addressItem.child(j)
|
||||||
if folderItem.folderName == "new" and (folder is None or folder in ["inbox", "new"]):
|
newCount = 0
|
||||||
updateUnreadCount(folderItem)
|
folderName = folderItem.folderName
|
||||||
continue
|
if folderName == "new":
|
||||||
if folder is None and folderItem.folderName != "inbox":
|
folderName = "inbox"
|
||||||
continue
|
if addressItem.type == AccountMixin.ALL and folderName in totalUnread:
|
||||||
if folder is not None and ((folder == "new" and folderItem.folderName != "inbox") or \
|
newCount = totalUnread[folderName]
|
||||||
(folder != "new" and folderItem.folderName != folder)):
|
elif addressItem.type == AccountMixin.SUBSCRIPTION:
|
||||||
continue
|
if addressItem.address in broadcastsUnread and folderName in broadcastsUnread[addressItem.address]:
|
||||||
if folder in ["sent", "trash"] and folderItem.folderName != folder:
|
newCount = broadcastsUnread[addressItem.address][folderName]
|
||||||
continue
|
elif addressItem.address in normalUnread and folderName in normalUnread[addressItem.address]:
|
||||||
updateUnreadCount(folderItem)
|
newCount = normalUnread[addressItem.address][folderName]
|
||||||
|
if newCount != folderItem.unreadCount:
|
||||||
|
folderItem.setUnreadCount(newCount)
|
||||||
|
|
||||||
def addMessageListItem(self, tableWidget, items):
|
def addMessageListItem(self, tableWidget, items):
|
||||||
sortingEnabled = tableWidget.isSortingEnabled()
|
sortingEnabled = tableWidget.isSortingEnabled()
|
||||||
|
@ -3756,6 +3748,9 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if messagelist:
|
if messagelist:
|
||||||
account = self.getCurrentAccount()
|
account = self.getCurrentAccount()
|
||||||
folder = self.getCurrentFolder()
|
folder = self.getCurrentFolder()
|
||||||
|
treeWidget = self.getCurrentTreeWidget()
|
||||||
|
# refresh count indicator
|
||||||
|
self.propagateUnreadCount(account.address if hasattr(account, 'address') else None, folder, treeWidget, 0)
|
||||||
self.loadMessagelist(messagelist, account, folder, searchOption, searchLine)
|
self.loadMessagelist(messagelist, account, folder, searchOption, searchLine)
|
||||||
|
|
||||||
def treeWidgetItemChanged(self, item, column):
|
def treeWidgetItemChanged(self, item, column):
|
||||||
|
|
|
@ -30,9 +30,9 @@ def getSortedSubscriptions(count = False):
|
||||||
ret[address]["inbox"]['count'] = 0
|
ret[address]["inbox"]['count'] = 0
|
||||||
if count:
|
if count:
|
||||||
queryreturn = sqlQuery('''SELECT fromaddress, folder, count(msgid) as cnt
|
queryreturn = sqlQuery('''SELECT fromaddress, folder, count(msgid) as cnt
|
||||||
FROM inbox, subscriptions
|
FROM inbox, subscriptions ON subscriptions.address = inbox.fromaddress
|
||||||
WHERE read = 0 AND subscriptions.address = inbox.fromaddress
|
WHERE read = 0 AND toaddress = ?
|
||||||
GROUP BY inbox.fromaddress, folder''')
|
GROUP BY inbox.fromaddress, folder''', str_broadcast_subscribers)
|
||||||
for row in queryreturn:
|
for row in queryreturn:
|
||||||
address, folder, cnt = row
|
address, folder, cnt = row
|
||||||
if not folder in ret[address]:
|
if not folder in ret[address]:
|
||||||
|
|
Reference in New Issue
Block a user