From 1d3c74bd215589615960334a11649f594579be0c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 1 Oct 2019 13:28:13 +0100 Subject: [PATCH] Obtaining actors for replies and announces --- inbox.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/inbox.py b/inbox.py index 84ec14556..34df912e7 100644 --- a/inbox.py +++ b/inbox.py @@ -993,8 +993,12 @@ def receiveAnnounce(session,handle: str,baseDir: str, \ lookupActor=postJsonObject['object']['attributedTo'] if lookupActor: if debug: - print('DEBUG: Obtaining actor for announce post '+lookupActor) - getPersonFromCache(baseDir,lookupActor,personCache) + print('DEBUG: Obtaining actor for announce post from cache '+lookupActor) + if not getPersonFromCache(baseDir,lookupActor,personCache): + print('DEBUG: retrieve actor for announce post '+lookupActor) + getPersonPubKey(baseDir,session,lookupActor, \ + personCache,debug, \ + __version__,httpPrefix,domain) if debug: print('DEBUG: announced/repeated post arrived in inbox') return True @@ -1162,7 +1166,7 @@ def validPostContent(messageJson: {},maxMentions: int) -> bool: print('ACCEPT: post content is valid') return True -def obtainAvatarForReplyPost(baseDir: str,personCache: {},postJsonObject: {},debug: bool) -> None: +def obtainAvatarForReplyPost(session,baseDir: str,httpPrefix: str,domain: str,personCache: {},postJsonObject: {},debug: bool) -> None: """Tries to obtain the actor for the person being replied to so that their avatar can later be shown """ @@ -1179,7 +1183,11 @@ def obtainAvatarForReplyPost(baseDir: str,personCache: {},postJsonObject: {},deb if lookupActor: if debug: print('DEBUG: Obtaining actor for reply post '+lookupActor) - getPersonFromCache(baseDir,lookupActor,personCache) + if not getPersonFromCache(baseDir,lookupActor,personCache): + print('DEBUG: retrieve actor for announce post '+lookupActor) + getPersonPubKey(baseDir,session,lookupActor, \ + personCache,debug, \ + __version__,httpPrefix,domain) def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \ baseDir: str,httpPrefix: str,sendThreads: [], \ @@ -1271,7 +1279,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \ if messageJson.get('postNickname'): if validPostContent(messageJson['post'],maxMentions): - obtainAvatarForReplyPost(baseDir,personCache,messageJson['post'],debug) + obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson['post'],debug) try: with open(destinationFilename, 'w+') as fp: commentjson.dump(messageJson['post'], fp, indent=4, sort_keys=False) @@ -1279,7 +1287,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \ print(e) else: if validPostContent(messageJson,maxMentions): - obtainAvatarForReplyPost(baseDir,personCache,messageJson,debug) + obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson,debug) try: with open(destinationFilename, 'w+') as fp: commentjson.dump(messageJson, fp, indent=4, sort_keys=False)