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.cachedWebfingers,self.server.personCache, \
nickname,self.server.domain,self.server.port, \
postJsonObject).encode('utf-8'))
authorized,postJsonObject).encode('utf-8'))
else:
self._set_headers('application/json',None)
self.wfile.write(json.dumps(postJsonObject).encode('utf-8'))
@ -1036,7 +1036,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.session, \
self.server.cachedWebfingers,self.server.personCache, \
nickname,self.server.domain,self.server.port, \
postJsonObject).encode('utf-8'))
authorized,postJsonObject).encode('utf-8'))
else:
self._set_headers('application/json',None)
self.wfile.write(json.dumps(postJsonObject).encode('utf-8'))
@ -1419,15 +1419,13 @@ class PubServer(BaseHTTPRequestHandler):
fields['replyTo'], fields['replyTo'],fields['subject'])
if messageJson:
self.postToNickname=nickname
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:
if self._postToOutbox(messageJson):
populateReplies(self.server.baseDir, \
self.server.httpPrefix, \
self.server.domainFull, \
messageJson, \
self.server.maxReplies, \
self.server.debug)
return 1
else:
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
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:
@ -839,40 +832,33 @@ def populateReplies(baseDir :str,httpPrefix :str,domain :str, \
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))
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()

View File

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