forked from indymedia/epicyon
Refactoring
parent
fd75e68be3
commit
49deddf1dc
59
daemon.py
59
daemon.py
|
@ -34,6 +34,7 @@ from posts import createPublicPost
|
|||
from posts import createUnlistedPost
|
||||
from posts import createFollowersOnlyPost
|
||||
from posts import createDirectMessagePost
|
||||
from posts import populateRepliesJson
|
||||
from inbox import inboxPermittedMessage
|
||||
from inbox import inboxMessageHasParams
|
||||
from inbox import runInboxQueue
|
||||
|
@ -916,57 +917,13 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
'type': 'OrderedCollectionPage'}
|
||||
|
||||
# populate the items list with replies
|
||||
repliesBoxes=['outbox','inbox']
|
||||
with open(postRepliesFilename,'r') as repliesFile:
|
||||
for messageId in repliesFile:
|
||||
replyFound=False
|
||||
# examine inbox and outbox
|
||||
for boxname in repliesBoxes:
|
||||
searchFilename= \
|
||||
self.server.baseDir+ \
|
||||
'/accounts/'+nickname+'@'+ \
|
||||
self.server.domain+'/'+ \
|
||||
boxname+'/'+ \
|
||||
messageId.replace('\n','').replace('/','#')+'.json'
|
||||
if os.path.isfile(searchFilename):
|
||||
if authorized or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read():
|
||||
with open(searchFilename, 'r') as fp:
|
||||
postJsonObject=commentjson.load(fp)
|
||||
if postJsonObject['object'].get('cc'):
|
||||
if authorized or \
|
||||
('https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['to'] or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['cc']):
|
||||
repliesJson['orderedItems'].append(postJsonObject)
|
||||
replyFound=True
|
||||
else:
|
||||
if authorized or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['to']:
|
||||
repliesJson['orderedItems'].append(postJsonObject)
|
||||
replyFound=True
|
||||
break
|
||||
# if not in either inbox or outbox then examine the shared inbox
|
||||
if not replyFound:
|
||||
searchFilename= \
|
||||
self.server.baseDir+ \
|
||||
'/accounts/inbox@'+ \
|
||||
self.server.domain+'/inbox/'+ \
|
||||
messageId.replace('\n','').replace('/','#')+'.json'
|
||||
if os.path.isfile(searchFilename):
|
||||
if authorized or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read():
|
||||
# get the json of the reply and append it to the collection
|
||||
with open(searchFilename, 'r') as fp:
|
||||
postJsonObject=commentjson.load(fp)
|
||||
if postJsonObject['object'].get('cc'):
|
||||
if authorized or \
|
||||
('https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['to'] or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['cc']):
|
||||
repliesJson['orderedItems'].append(postJsonObject)
|
||||
else:
|
||||
if authorized or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['to']:
|
||||
repliesJson['orderedItems'].append(postJsonObject)
|
||||
populateRepliesJson(self.server.baseDir, \
|
||||
nickname, \
|
||||
self.server.domain, \
|
||||
postRepliesFilename, \
|
||||
authorized, \
|
||||
repliesJson)
|
||||
|
||||
# send the replies json
|
||||
if 'text/html' in self.headers['Accept']:
|
||||
if not self.server.session:
|
||||
|
|
54
posts.py
54
posts.py
|
@ -1482,3 +1482,57 @@ def sendCapabilitiesUpdate(session,baseDir: str,httpPrefix: str, \
|
|||
federationList, \
|
||||
sendThreads,postLog,cachedWebfingers, \
|
||||
personCache,debug)
|
||||
|
||||
def populateRepliesJson(baseDir: str,nickname: str,domain: str,postRepliesFilename: str,authorized: bool,repliesJson: {}) -> None:
|
||||
# populate the items list with replies
|
||||
repliesBoxes=['outbox','inbox']
|
||||
with open(postRepliesFilename,'r') as repliesFile:
|
||||
for messageId in repliesFile:
|
||||
replyFound=False
|
||||
# examine inbox and outbox
|
||||
for boxname in repliesBoxes:
|
||||
searchFilename= \
|
||||
baseDir+ \
|
||||
'/accounts/'+nickname+'@'+ \
|
||||
domain+'/'+ \
|
||||
boxname+'/'+ \
|
||||
messageId.replace('\n','').replace('/','#')+'.json'
|
||||
if os.path.isfile(searchFilename):
|
||||
if authorized or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read():
|
||||
with open(searchFilename, 'r') as fp:
|
||||
postJsonObject=commentjson.load(fp)
|
||||
if postJsonObject['object'].get('cc'):
|
||||
if authorized or \
|
||||
('https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['to'] or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['cc']):
|
||||
repliesJson['orderedItems'].append(postJsonObject)
|
||||
replyFound=True
|
||||
else:
|
||||
if authorized or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['to']:
|
||||
repliesJson['orderedItems'].append(postJsonObject)
|
||||
replyFound=True
|
||||
break
|
||||
# if not in either inbox or outbox then examine the shared inbox
|
||||
if not replyFound:
|
||||
searchFilename= \
|
||||
baseDir+ \
|
||||
'/accounts/inbox@'+ \
|
||||
domain+'/inbox/'+ \
|
||||
messageId.replace('\n','').replace('/','#')+'.json'
|
||||
if os.path.isfile(searchFilename):
|
||||
if authorized or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read():
|
||||
# get the json of the reply and append it to the collection
|
||||
with open(searchFilename, 'r') as fp:
|
||||
postJsonObject=commentjson.load(fp)
|
||||
if postJsonObject['object'].get('cc'):
|
||||
if authorized or \
|
||||
('https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['to'] or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['cc']):
|
||||
repliesJson['orderedItems'].append(postJsonObject)
|
||||
else:
|
||||
if authorized or \
|
||||
'https://www.w3.org/ns/activitystreams#Public' in postJsonObject['object']['to']:
|
||||
repliesJson['orderedItems'].append(postJsonObject)
|
||||
|
|
Loading…
Reference in New Issue