Fixed propagateUnreadCount() result when having unread messages in trash

This commit is contained in:
Dmitri Bogomolov 2019-02-27 11:49:17 +02:00
parent 29f9cd9545
commit ffdd91b021
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -967,56 +967,70 @@ class MyForm(settingsmixin.SMainWindow):
for col in (0, 1, 2): for col in (0, 1, 2):
related.item(rrow, col).setUnread(not status) related.item(rrow, col).setUnread(not status)
def propagateUnreadCount(self, address = None, folder = "inbox", widget = None, type = 1): def propagateUnreadCount(
widgets = [self.ui.treeWidgetYourIdentities, self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans] self, address=None, folder='inbox', widget=None, type=1):
queryReturn = sqlQuery("SELECT toaddress, folder, COUNT(msgid) AS cnt FROM inbox WHERE read = 0 GROUP BY toaddress, folder") 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 = {} totalUnread = {}
normalUnread = {} normalUnread = {}
for row in queryReturn: for addr, folder, count in queryReturn:
normalUnread[row[0]] = {} try:
if row[1] in ["trash"]: normalUnread[addr][folder] = count
continue except KeyError:
normalUnread[row[0]][row[1]] = row[2] normalUnread[addr] = {folder: count}
if row[1] in totalUnread: try:
totalUnread[row[1]] += row[2] totalUnread[folder] += count
else: except KeyError:
totalUnread[row[1]] = row[2] totalUnread[folder] = count
queryReturn = sqlQuery("SELECT fromaddress, folder, COUNT(msgid) AS cnt FROM inbox WHERE read = 0 AND toaddress = ? GROUP BY fromaddress, folder", str_broadcast_subscribers) queryReturn = sqlQuery(
'SELECT fromaddress, folder, COUNT(msgid) AS cnt FROM inbox'
' WHERE read = 0 AND toaddress = ? GROUP BY fromaddress, folder',
str_broadcast_subscribers)
broadcastsUnread = {} broadcastsUnread = {}
for row in queryReturn: for addr, folder, count in queryReturn:
broadcastsUnread[row[0]] = {} try:
broadcastsUnread[row[0]][row[1]] = row[2] broadcastsUnread[addr][folder] = count
except KeyError:
broadcastsUnread[addr] = {folder: count}
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)
newCount = 0
if addressItem.type == AccountMixin.ALL: if addressItem.type == AccountMixin.ALL:
newCount = sum(totalUnread.itervalues()) newCount = sum(totalUnread.itervalues())
self.drawTrayIcon(self.currentTrayIconFileName, newCount) self.drawTrayIcon(self.currentTrayIconFileName, newCount)
elif addressItem.type == AccountMixin.SUBSCRIPTION: else:
if addressItem.address in broadcastsUnread: try:
newCount = sum(broadcastsUnread[addressItem.address].itervalues()) newCount = sum((
elif addressItem.address in normalUnread: broadcastsUnread
newCount = sum(normalUnread[addressItem.address].itervalues()) if addressItem.type == AccountMixin.SUBSCRIPTION
else normalUnread
)[addressItem.address].itervalues())
except KeyError:
newCount = 0
if newCount != addressItem.unreadCount: if newCount != addressItem.unreadCount:
addressItem.setUnreadCount(newCount) addressItem.setUnreadCount(newCount)
if addressItem.childCount == 0:
continue
for j in range(addressItem.childCount()): for j in range(addressItem.childCount()):
folderItem = addressItem.child(j) folderItem = addressItem.child(j)
newCount = 0
folderName = folderItem.folderName folderName = folderItem.folderName
if folderName == "new": if folderName == "new":
folderName = "inbox" folderName = "inbox"
if addressItem.type == AccountMixin.ALL and folderName in totalUnread: if addressItem.type == AccountMixin.ALL:
newCount = totalUnread[folderName] newCount = totalUnread.get(folderName, 0)
elif addressItem.type == AccountMixin.SUBSCRIPTION: else:
if addressItem.address in broadcastsUnread and folderName in broadcastsUnread[addressItem.address]: try:
newCount = broadcastsUnread[addressItem.address][folderName] newCount = (
elif addressItem.address in normalUnread and folderName in normalUnread[addressItem.address]: broadcastsUnread
newCount = normalUnread[addressItem.address][folderName] if addressItem.type == AccountMixin.SUBSCRIPTION
else normalUnread
)[addressItem.address][folderName]
except KeyError:
newCount = 0
if newCount != folderItem.unreadCount: if newCount != folderItem.unreadCount:
folderItem.setUnreadCount(newCount) folderItem.setUnreadCount(newCount)