Viewing replies to posts

master
Bob Mottram 2019-08-02 17:49:42 +01:00
parent e04db12604
commit 511a8767a8
2 changed files with 47 additions and 7 deletions

View File

@ -883,8 +883,20 @@ class PubServer(BaseHTTPRequestHandler):
'totalItems': 0,
'type': 'OrderedCollection'}
if 'text/html' in self.headers['Accept']:
if not self.server.session:
if self.server.debug:
print('DEBUG: creating new session')
self.server.session= \
createSession(self.server.domain,self.server.port,self.server.useTor)
self._set_headers('text/html',cookie)
self.wfile.write(htmlPostReplies(repliesJson).encode('utf-8'))
self.wfile.write(htmlPostReplies(self.server.baseDir, \
self.server.session, \
self.server.webfingerCache, \
self.server.personCache, \
nickname, \
self.server.domain, \
self.server.port, \
repliesJson).encode('utf-8'))
else:
self._set_headers('application/json',None)
self.wfile.write(json.dumps(repliesJson).encode('utf-8'))
@ -954,8 +966,20 @@ class PubServer(BaseHTTPRequestHandler):
repliesJson['orderedItems'].append(postJsonObject)
# send the replies json
if 'text/html' in self.headers['Accept']:
if not self.server.session:
if self.server.debug:
print('DEBUG: creating new session')
self.server.session= \
createSession(self.server.domain,self.server.port,self.server.useTor)
self._set_headers('text/html',cookie)
self.wfile.write(htmlPostReplies(repliesJson).encode('utf-8'))
self.wfile.write(htmlPostReplies(self.server.baseDir, \
self.server.session, \
self.server.webfingerCache, \
self.server.personCache, \
nickname, \
self.server.domain, \
self.server.port, \
repliesJson).encode('utf-8'))
else:
self._set_headers('application/json',None)
self.wfile.write(json.dumps(repliesJson).encode('utf-8'))

View File

@ -797,15 +797,31 @@ def htmlIndividualPost(baseDir: str,session,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,postJsonObject: {}) -> str:
"""Show an individual post as html
"""
return htmlHeader()+ \
postStr= \
individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,postJsonObject,None,True,False)+ \
htmlFooter()
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)
return htmlHeader()+postStr+htmlFooter()
def htmlPostReplies(postJsonObject: {}) -> str:
def htmlPostReplies(baseDir: str,session,wfRequest: {},personCache: {}, \
nickname: str,domain: str,port: int,repliesJson: {}) -> str:
"""Show the replies to an individual post as html
"""
return htmlHeader()+"<h1>Replies</h1>"+htmlFooter()
repliesStr=''
if repliesJson.get('orderedItems'):
for item in repliesJson['orderedItems']:
repliesStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \
nickname,domain,port,item,None,True,False)
return htmlHeader()+repliesStr+htmlFooter()
def htmlFollowConfirm(baseDir: str,originPathStr: str,followActor: str,followProfileUrl: str) -> str:
"""Asks to confirm a follow