Improve notification logic

merge-requests/30/head
Bob Mottram 2021-03-23 10:03:45 +00:00
parent 1dda323ea7
commit 6a31b0e9d7
1 changed files with 26 additions and 26 deletions

View File

@ -200,47 +200,47 @@ def _newDesktopNotifications(actor: str, inboxJson: {},
notifyJson: {}) -> None: notifyJson: {}) -> None:
"""Looks for changes in the inbox and adds notifications """Looks for changes in the inbox and adds notifications
""" """
notifyJson['dmNotifyChanged'] = False
notifyJson['repliesNotifyChanged'] = False
if not inboxJson: if not inboxJson:
return return
if not inboxJson.get('orderedItems'): if not inboxJson.get('orderedItems'):
return return
newDM = False DMdone = False
newReply = False replyDone = False
notifyJson['dmNotifyChanged'] = False
notifyJson['repliesNotifyChanged'] = False
for postJsonObject in inboxJson['orderedItems']: for postJsonObject in inboxJson['orderedItems']:
if not postJsonObject.get('id'): if not postJsonObject.get('id'):
continue continue
if not _postIsToYou(actor, postJsonObject): if not _postIsToYou(actor, postJsonObject):
continue continue
if 'dmNotify' not in notifyJson:
notifyJson['dmNotify'] = False
if isDM(postJsonObject): if isDM(postJsonObject):
if not newDM: if not DMdone:
if not _hasReadPost(actor, postJsonObject['id'], 'dm'): if not _hasReadPost(actor, postJsonObject['id'], 'dm'):
if notifyJson.get('dmPostId'): changed = False
if not notifyJson.get('dmPostId'):
changed = True
else:
if notifyJson['dmPostId'] != postJsonObject['id']: if notifyJson['dmPostId'] != postJsonObject['id']:
notifyJson['dmNotify'] = True changed = True
notifyJson['dmNotifyChanged'] = True if changed:
newDM = True notifyJson['dmNotify'] = True
else: notifyJson['dmNotifyChanged'] = True
notifyJson['dmNotifyChanged'] = False notifyJson['dmPostId'] = postJsonObject['id']
notifyJson['dmPostId'] = postJsonObject['id'] DMdone = True
if newDM:
break
else: else:
if not newReply: if not replyDone:
if not _hasReadPost(actor, postJsonObject['id'], 'replies'): if not _hasReadPost(actor, postJsonObject['id'], 'replies'):
if notifyJson.get('repliesPostId'): changed = False
if not notifyJson.get('repliesPostId'):
changed = True
else:
if notifyJson['repliesPostId'] != postJsonObject['id']: if notifyJson['repliesPostId'] != postJsonObject['id']:
notifyJson['repliesNotify'] = True changed = True
notifyJson['repliesNotifyChanged'] = True if changed:
newReply = True notifyJson['repliesNotify'] = True
else: notifyJson['repliesNotifyChanged'] = True
notifyJson['repliesNotifyChanged'] = False notifyJson['repliesPostId'] = postJsonObject['id']
notifyJson['repliesPostId'] = postJsonObject['id'] replyDone = True
if newReply:
break
def _desktopClearScreen() -> None: def _desktopClearScreen() -> None: