Tidying of low frequency post notification

merge-requests/30/head
Bob Mottram 2021-11-04 12:43:46 +00:00
parent 6f43314d34
commit 27cf80dce2
1 changed files with 34 additions and 19 deletions

View File

@ -2650,6 +2650,37 @@ def _createReplyNotificationFile(baseDir: str, nickname: str, domain: str,
return isReplyToMutedPost return isReplyToMutedPost
def _lowFrequencyPostNotification(baseDir: str, httpPrefix: str, nickname: str,
domain: str, port: int, handle: str,
postIsDM: bool, jsonObj: {}) -> None:
"""Should we notify that a post from this person has arrived?
This is for cases where the notify checkbox is enabled on the
person options screen
"""
if postIsDM:
return
if not jsonObj:
return
if not jsonObj.get('attributedTo'):
return
if not jsonObj.get('id'):
return
attributedTo = jsonObj['attributedTo']
if not isinstance(attributedTo, str):
return
fromNickname = getNicknameFromActor(attributedTo)
fromDomain, fromPort = getDomainFromActor(attributedTo)
fromDomainFull = getFullDomain(fromDomain, fromPort)
if notifyWhenPersonPosts(baseDir, nickname, domain,
fromNickname, fromDomainFull):
postId = removeIdEnding(jsonObj['id'])
domFull = getFullDomain(domain, port)
postLink = \
localActorUrl(httpPrefix, nickname, domFull) + \
'?notifypost=' + postId.replace('/', '-')
_notifyPostArrival(baseDir, handle, postLink)
def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int, def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
session, keyId: str, handle: str, messageJson: {}, session, keyId: str, handle: str, messageJson: {},
baseDir: str, httpPrefix: str, sendThreads: [], baseDir: str, httpPrefix: str, sendThreads: [],
@ -2950,25 +2981,9 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
# save the post to file # save the post to file
if saveJson(postJsonObject, destinationFilename): if saveJson(postJsonObject, destinationFilename):
# should we notify that a post from this person has arrived? _lowFrequencyPostNotification(baseDir, httpPrefix,
# This is for cases where the notify checkbox is enabled nickname, domain, port,
# on the person options screen handle, postIsDM, jsonObj)
if not postIsDM and jsonObj:
if jsonObj.get('attributedTo') and jsonObj.get('id'):
attributedTo = jsonObj['attributedTo']
if isinstance(attributedTo, str):
fromNickname = getNicknameFromActor(attributedTo)
fromDomain, fromPort = getDomainFromActor(attributedTo)
fromDomainFull = getFullDomain(fromDomain, fromPort)
if notifyWhenPersonPosts(baseDir, nickname, domain,
fromNickname, fromDomainFull):
postId = removeIdEnding(jsonObj['id'])
domFull = getFullDomain(domain, port)
postLink = \
localActorUrl(httpPrefix,
nickname, domFull) + \
'?notifypost=' + postId.replace('/', '-')
_notifyPostArrival(baseDir, handle, postLink)
# If this is a reply to a muted post then also mute it. # If this is a reply to a muted post then also mute it.
# This enables you to ignore a threat that's getting boring # This enables you to ignore a threat that's getting boring