Displaying replies to posts selected from the web interface

master
Bob Mottram 2019-08-02 19:57:06 +01:00
parent 49deddf1dc
commit bbae1dc77d
3 changed files with 27 additions and 36 deletions

View File

@ -848,7 +848,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.session, \ self.server.session, \
self.server.cachedWebfingers,self.server.personCache, \ self.server.cachedWebfingers,self.server.personCache, \
nickname,self.server.domain,self.server.port, \ nickname,self.server.domain,self.server.port, \
postJsonObject).encode('utf-8')) authorized,postJsonObject).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(postJsonObject).encode('utf-8')) self.wfile.write(json.dumps(postJsonObject).encode('utf-8'))
@ -1036,7 +1036,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.session, \ self.server.session, \
self.server.cachedWebfingers,self.server.personCache, \ self.server.cachedWebfingers,self.server.personCache, \
nickname,self.server.domain,self.server.port, \ nickname,self.server.domain,self.server.port, \
postJsonObject).encode('utf-8')) authorized,postJsonObject).encode('utf-8'))
else: else:
self._set_headers('application/json',None) self._set_headers('application/json',None)
self.wfile.write(json.dumps(postJsonObject).encode('utf-8')) self.wfile.write(json.dumps(postJsonObject).encode('utf-8'))
@ -1419,15 +1419,13 @@ class PubServer(BaseHTTPRequestHandler):
fields['replyTo'], fields['replyTo'],fields['subject']) fields['replyTo'], fields['replyTo'],fields['subject'])
if messageJson: if messageJson:
self.postToNickname=nickname self.postToNickname=nickname
result=self._postToOutbox(messageJson) if self._postToOutbox(messageJson):
print('_postToOutbox ********************************************** '+str(result)) populateReplies(self.server.baseDir, \
populateReplies(self.server.baseDir, \ self.server.httpPrefix, \
self.server.httpPrefix, \ self.server.domainFull, \
self.server.domainFull, \ messageJson, \
messageJson, \ self.server.maxReplies, \
self.server.maxReplies, \ self.server.debug)
self.server.debug)
if result:
return 1 return 1
else: else:
return -1 return -1

View File

@ -812,26 +812,19 @@ def populateReplies(baseDir :str,httpPrefix :str,domain :str, \
"""Updates the list of replies for a post on this domain if """Updates the list of replies for a post on this domain if
a reply to it arrives a reply to it arrives
""" """
print("Test1")
if not messageJson.get('id'): if not messageJson.get('id'):
return False return False
print("Test2")
if not messageJson.get('object'): if not messageJson.get('object'):
return False return False
print("Test3")
if not isinstance(messageJson['object'], dict): if not isinstance(messageJson['object'], dict):
return False return False
print("Test4")
if not messageJson['object'].get('inReplyTo'): if not messageJson['object'].get('inReplyTo'):
return False return False
print("Test5")
if not messageJson['object'].get('to'): if not messageJson['object'].get('to'):
return False return False
print("Test6")
replyTo=messageJson['object']['inReplyTo'] replyTo=messageJson['object']['inReplyTo']
if debug: if debug:
print('DEBUG: post contains a reply') print('DEBUG: post contains a reply')
print("Test7")
# is this a reply to a post on this domain? # is this a reply to a post on this domain?
if not replyTo.startswith(httpPrefix+'://'+domain+'/'): if not replyTo.startswith(httpPrefix+'://'+domain+'/'):
if debug: if debug:
@ -839,40 +832,33 @@ def populateReplies(baseDir :str,httpPrefix :str,domain :str, \
print(replyTo) print(replyTo)
print('Expected: '+httpPrefix+'://'+domain+'/') print('Expected: '+httpPrefix+'://'+domain+'/')
return False return False
print("Test8")
replyToNickname=getNicknameFromActor(replyTo) replyToNickname=getNicknameFromActor(replyTo)
if not replyToNickname: if not replyToNickname:
if debug: if debug:
print('DEBUG: no nickname found for '+replyTo) print('DEBUG: no nickname found for '+replyTo)
return False return False
print("Test9")
replyToDomain,replyToPort=getDomainFromActor(replyTo) replyToDomain,replyToPort=getDomainFromActor(replyTo)
if not replyToDomain: if not replyToDomain:
if debug: if debug:
print('DEBUG: no domain found for '+replyTo) print('DEBUG: no domain found for '+replyTo)
return False return False
print("Test10")
postFilename=locatePost(baseDir,replyToNickname,replyToDomain,replyTo) postFilename=locatePost(baseDir,replyToNickname,replyToDomain,replyTo)
if not postFilename: if not postFilename:
if debug: if debug:
print('DEBUG: post may have expired - '+replyTo) print('DEBUG: post may have expired - '+replyTo)
return False return False
print("Test11")
# populate a text file containing the ids of replies # populate a text file containing the ids of replies
postRepliesFilename=postFilename.replace('.json','.replies') postRepliesFilename=postFilename.replace('.json','.replies')
messageId=messageJson['id'].replace('/activity','') messageId=messageJson['id'].replace('/activity','')
if os.path.isfile(postRepliesFilename): if os.path.isfile(postRepliesFilename):
numLines = sum(1 for line in open(postRepliesFilename)) numLines = sum(1 for line in open(postRepliesFilename))
print("Test12 "+str(numLines))
if numLines>maxReplies: if numLines>maxReplies:
return False return False
print("Test13")
if messageId not in open(postRepliesFilename).read(): if messageId not in open(postRepliesFilename).read():
repliesFile=open(postRepliesFilename, "a") repliesFile=open(postRepliesFilename, "a")
repliesFile.write(messageId+'\n') repliesFile.write(messageId+'\n')
repliesFile.close() repliesFile.close()
else: else:
print("Test14")
repliesFile=open(postRepliesFilename, "w") repliesFile=open(postRepliesFilename, "w")
repliesFile.write(messageId+'\n') repliesFile.write(messageId+'\n')
repliesFile.close() repliesFile.close()

View File

@ -16,11 +16,13 @@ from pprint import pprint
from person import personBoxJson from person import personBoxJson
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from posts import getPersonBox from utils import locatePost
from follow import isFollowingActor from follow import isFollowingActor
from webfinger import webfingerHandle from webfinger import webfingerHandle
from posts import getPersonBox
from posts import getUserUrl from posts import getUserUrl
from posts import parseUserFeed from posts import parseUserFeed
from posts import populateRepliesJson
from session import getJson from session import getJson
from auth import createPassword from auth import createPassword
from like import likedByPerson from like import likedByPerson
@ -794,21 +796,26 @@ def htmlOutbox(pageNumber: int,itemsPerPage: int, \
nickname,domain,port,outboxJson,'outbox') nickname,domain,port,outboxJson,'outbox')
def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,postJsonObject: {}) -> str: nickname: str,domain: str,port: int,authorized: bool, \
postJsonObject: {}) -> str:
"""Show an individual post as html """Show an individual post as html
""" """
postStr= \ postStr= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,postJsonObject,None,True,False) nickname,domain,port,postJsonObject,None,True,False)
if postJsonObject.get('object'): postFilename=locatePost(baseDir,nickname,domain,postJsonObject['id'].replace('/activity',''))
if isinstance(postJsonObject['object'], dict): if postFilename:
if postJsonObject['object'].get('replies'): # is there a replies file for this post?
repliesJson=postJsonObject['object']['replies'] repliesFilename=postFilename.replace('.json','.replies')
if repliesJson.get('orderedItems'): if os.path.isfile(repliesFilename):
for item in repliesJson['orderedItems']: # get items from the replies file
postStr+= \ repliesJson={'orderedItems': []}
individualPostAsHtml(baseDir,session,wfRequest,personCache, \ populateRepliesJson(baseDir,nickname,domain,repliesFilename,authorized,repliesJson)
nickname,domain,port,item,None,True,False) # add items to the html output
for item in repliesJson['orderedItems']:
postStr+= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False)
return htmlHeader()+postStr+htmlFooter() return htmlHeader()+postStr+htmlFooter()
def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \ def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \