Obtaining actors for replies and announces

main2
Bob Mottram 2019-10-01 13:28:13 +01:00
parent f31a9b4fd1
commit 1d3c74bd21
1 changed files with 14 additions and 6 deletions

View File

@ -993,8 +993,12 @@ def receiveAnnounce(session,handle: str,baseDir: str, \
lookupActor=postJsonObject['object']['attributedTo'] lookupActor=postJsonObject['object']['attributedTo']
if lookupActor: if lookupActor:
if debug: if debug:
print('DEBUG: Obtaining actor for announce post '+lookupActor) print('DEBUG: Obtaining actor for announce post from cache '+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)
if debug: if debug:
print('DEBUG: announced/repeated post arrived in inbox') print('DEBUG: announced/repeated post arrived in inbox')
return True return True
@ -1162,7 +1166,7 @@ def validPostContent(messageJson: {},maxMentions: int) -> bool:
print('ACCEPT: post content is valid') print('ACCEPT: post content is valid')
return True 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 """Tries to obtain the actor for the person being replied to
so that their avatar can later be shown so that their avatar can later be shown
""" """
@ -1179,7 +1183,11 @@ def obtainAvatarForReplyPost(baseDir: str,personCache: {},postJsonObject: {},deb
if lookupActor: if lookupActor:
if debug: if debug:
print('DEBUG: Obtaining actor for reply post '+lookupActor) 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: {}, \ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
baseDir: str,httpPrefix: str,sendThreads: [], \ baseDir: str,httpPrefix: str,sendThreads: [], \
@ -1271,7 +1279,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
if messageJson.get('postNickname'): if messageJson.get('postNickname'):
if validPostContent(messageJson['post'],maxMentions): if validPostContent(messageJson['post'],maxMentions):
obtainAvatarForReplyPost(baseDir,personCache,messageJson['post'],debug) obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson['post'],debug)
try: try:
with open(destinationFilename, 'w+') as fp: with open(destinationFilename, 'w+') as fp:
commentjson.dump(messageJson['post'], fp, indent=4, sort_keys=False) commentjson.dump(messageJson['post'], fp, indent=4, sort_keys=False)
@ -1279,7 +1287,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
print(e) print(e)
else: else:
if validPostContent(messageJson,maxMentions): if validPostContent(messageJson,maxMentions):
obtainAvatarForReplyPost(baseDir,personCache,messageJson,debug) obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson,debug)
try: try:
with open(destinationFilename, 'w+') as fp: with open(destinationFilename, 'w+') as fp:
commentjson.dump(messageJson, fp, indent=4, sort_keys=False) commentjson.dump(messageJson, fp, indent=4, sort_keys=False)