From 61f7a096703d97d4e5b1f6b77326020e8b435956 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 8 Jul 2020 20:49:15 +0100 Subject: [PATCH] Create notification when likes arrive --- inbox.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/inbox.py b/inbox.py index 56c3b5f80..237fa98bb 100644 --- a/inbox.py +++ b/inbox.py @@ -1033,6 +1033,7 @@ def receiveLike(recentPostsCache: {}, updateLikesCollection(recentPostsCache, baseDir, postFilename, messageJson['object'], messageJson['actor'], domain, debug) + likeNotify(baseDir, handle, messageJson['actor'], messageJson['object']) return True @@ -1704,6 +1705,28 @@ def dmNotify(baseDir: str, handle: str, url: str) -> None: fp.write(url) +def likeNotify(baseDir: str, handle: str, actor: str, url: str) -> None: + """Creates a notification that a like has arrived + """ + accountDir = baseDir + '/accounts/' + handle + if not os.path.isdir(accountDir): + return + likeFile = accountDir + '/.newLike' + + domain = handle.split('@')[1] + nickname = handle.split('@')[0] + actor = '://' + domain + '/users/' + nickname + # the liked post is one which you made + if actor not in url: + return + likerNickname = getNicknameFromActor(actor) + likerDomain, likerPort = getDomainFromActor(actor) + likerHandle = likerNickname + '@' + likerDomain + if likerHandle != handle: + with open(likeFile, 'w') as fp: + fp.write(likerHandle + ' ' + url) + + def replyNotify(baseDir: str, handle: str, url: str) -> None: """Creates a notification that a new reply has arrived """