From 511a8767a89e8cc5cdc592e18bb524df45903637 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 2 Aug 2019 17:49:42 +0100 Subject: [PATCH] Viewing replies to posts --- daemon.py | 28 ++++++++++++++++++++++++++-- webinterface.py | 26 +++++++++++++++++++++----- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/daemon.py b/daemon.py index f7416b9b..d114ad04 100644 --- a/daemon.py +++ b/daemon.py @@ -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')) diff --git a/webinterface.py b/webinterface.py index 50012690..f290db57 100644 --- a/webinterface.py +++ b/webinterface.py @@ -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()+"

Replies

"+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