diff --git a/daemon.py b/daemon.py index d114ad04..ea98c88e 100644 --- a/daemon.py +++ b/daemon.py @@ -38,6 +38,7 @@ from inbox import inboxPermittedMessage from inbox import inboxMessageHasParams from inbox import runInboxQueue from inbox import savePostToInboxQueue +from inbox import populateReplies from follow import getFollowingFeed from follow import outboxUndoFollow from follow import sendFollowRequest @@ -889,9 +890,11 @@ class PubServer(BaseHTTPRequestHandler): self.server.session= \ createSession(self.server.domain,self.server.port,self.server.useTor) self._set_headers('text/html',cookie) + print('----------------------------------------------------') + pprint(repliesJson) self.wfile.write(htmlPostReplies(self.server.baseDir, \ self.server.session, \ - self.server.webfingerCache, \ + self.server.cachedWebfingers, \ self.server.personCache, \ nickname, \ self.server.domain, \ @@ -974,7 +977,7 @@ class PubServer(BaseHTTPRequestHandler): self._set_headers('text/html',cookie) self.wfile.write(htmlPostReplies(self.server.baseDir, \ self.server.session, \ - self.server.webfingerCache, \ + self.server.cachedWebfingers, \ self.server.personCache, \ nickname, \ self.server.domain, \ @@ -1459,7 +1462,15 @@ class PubServer(BaseHTTPRequestHandler): fields['replyTo'], fields['replyTo'],fields['subject']) if messageJson: self.postToNickname=nickname - if self._postToOutbox(messageJson): + result=self._postToOutbox(messageJson) + print('_postToOutbox ********************************************** '+str(result)) + populateReplies(self.server.baseDir, \ + self.server.httpPrefix, \ + self.server.domainFull, \ + messageJson, \ + self.server.maxReplies, \ + self.server.debug) + if result: return 1 else: return -1 @@ -1476,6 +1487,12 @@ class PubServer(BaseHTTPRequestHandler): if messageJson: self.postToNickname=nickname if self._postToOutbox(messageJson): + populateReplies(self.server.baseDir, \ + self.server.httpPrefix, \ + self.server.domain, \ + messageJson, \ + self.server.maxReplies, \ + self.server.debug) return 1 else: return -1 @@ -1492,6 +1509,12 @@ class PubServer(BaseHTTPRequestHandler): if messageJson: self.postToNickname=nickname if self._postToOutbox(messageJson): + populateReplies(self.server.baseDir, \ + self.server.httpPrefix, \ + self.server.domain, \ + messageJson, \ + self.server.maxReplies, \ + self.server.debug) return 1 else: return -1 @@ -1508,6 +1531,12 @@ class PubServer(BaseHTTPRequestHandler): if messageJson: self.postToNickname=nickname if self._postToOutbox(messageJson): + populateReplies(self.server.baseDir, \ + self.server.httpPrefix, \ + self.server.domain, \ + messageJson, \ + self.server.maxReplies, \ + self.server.debug) return 1 else: return -1 @@ -2271,6 +2300,7 @@ def runDaemon(instanceId,clientToServer: bool, \ httpd.maxImageSize=10*1024*1024 httpd.allowDeletion=allowDeletion httpd.lastLoginTime=0 + httpd.maxReplies=maxReplies httpd.salts={} httpd.tokens={} httpd.tokensLookup={} diff --git a/inbox.py b/inbox.py index a89ff8a4..702f2327 100644 --- a/inbox.py +++ b/inbox.py @@ -812,51 +812,67 @@ def populateReplies(baseDir :str,httpPrefix :str,domain :str, \ """Updates the list of replies for a post on this domain if a reply to it arrives """ + print("Test1") if not messageJson.get('id'): return False + print("Test2") if not messageJson.get('object'): return False + print("Test3") if not isinstance(messageJson['object'], dict): return False + print("Test4") if not messageJson['object'].get('inReplyTo'): return False + print("Test5") if not messageJson['object'].get('to'): return False + print("Test6") replyTo=messageJson['object']['inReplyTo'] if debug: print('DEBUG: post contains a reply') + print("Test7") # is this a reply to a post on this domain? if not replyTo.startswith(httpPrefix+'://'+domain+'/'): if debug: print('DEBUG: post is a reply to another not on this domain') + print(replyTo) + print('Expected: '+httpPrefix+'://'+domain+'/') return False + print("Test8") replyToNickname=getNicknameFromActor(replyTo) if not replyToNickname: if debug: print('DEBUG: no nickname found for '+replyTo) return False + print("Test9") replyToDomain,replyToPort=getDomainFromActor(replyTo) if not replyToDomain: if debug: print('DEBUG: no domain found for '+replyTo) return False + print("Test10") postFilename=locatePost(baseDir,replyToNickname,replyToDomain,replyTo) if not postFilename: if debug: print('DEBUG: post may have expired - '+replyTo) return False + print("Test11") # populate a text file containing the ids of replies postRepliesFilename=postFilename.replace('.json','.replies') messageId=messageJson['id'].replace('/activity','') if os.path.isfile(postRepliesFilename): numLines = sum(1 for line in open(postRepliesFilename)) - if numlines>maxReplies: + print("Test12 "+str(numLines)) + if numLines>maxReplies: return False + print("Test13") if messageId not in open(postRepliesFilename).read(): repliesFile=open(postRepliesFilename, "a") repliesFile.write(messageId+'\n') repliesFile.close() else: + print("Test14") repliesFile=open(postRepliesFilename, "w") repliesFile.write(messageId+'\n') repliesFile.close() diff --git a/posts.py b/posts.py index d7433cce..01f079ca 100644 --- a/posts.py +++ b/posts.py @@ -1232,6 +1232,8 @@ def createBoxBase(baseDir: str,boxname: str, \ postsCtr=0 postsInPersonInbox=os.listdir(boxDir) for postFilename in postsInPersonInbox: + if not postFilename.endswith('.json'): + continue # extract the status number statusNumber=getStatusNumberFromPostFilename(postFilename) if statusNumber: