forked from indymedia/epicyon
move inbox items addressed to followers into the shared inbox
This avoids multiple copies and so reduces storage space and i/o bandwidth usemaster
parent
2558ec297d
commit
3396cb7c19
63
inbox.py
63
inbox.py
|
@ -240,11 +240,15 @@ def inboxPostRecipientsAdd(baseDir :str,httpPrefix :str,toList :[], \
|
||||||
followerRecipients=True
|
followerRecipients=True
|
||||||
return followerRecipients,recipientsDict
|
return followerRecipients,recipientsDict
|
||||||
|
|
||||||
def inboxPostRecipients(baseDir :str,postJsonObject :{},httpPrefix :str,domain : str,port :int) -> []:
|
def inboxPostRecipients(baseDir :str,postJsonObject :{},httpPrefix :str,domain : str,port :int) -> ([],[]):
|
||||||
|
"""Returns dictionaries containing the recipients of the given post
|
||||||
|
The shared dictionary contains followers
|
||||||
|
"""
|
||||||
recipientsDict={}
|
recipientsDict={}
|
||||||
|
recipientsDictFollowers={}
|
||||||
|
|
||||||
if not postJsonObject.get('actor'):
|
if not postJsonObject.get('actor'):
|
||||||
return recipientsDict
|
return recipientsDict,recipientsDictFollowers
|
||||||
|
|
||||||
if ':' in domain:
|
if ':' in domain:
|
||||||
domain=domain.split(':')[0]
|
domain=domain.split(':')[0]
|
||||||
|
@ -296,13 +300,13 @@ def inboxPostRecipients(baseDir :str,postJsonObject :{},httpPrefix :str,domain :
|
||||||
followerRecipients=True
|
followerRecipients=True
|
||||||
|
|
||||||
if not followerRecipients:
|
if not followerRecipients:
|
||||||
return recipientsDict
|
return recipientsDict,recipientsDictFollowers
|
||||||
|
|
||||||
# now resolve the followers
|
# now resolve the followers
|
||||||
recipientsDict= \
|
recipientsDictFollowers= \
|
||||||
getFollowersOfActor(baseDir,actor,recipientsDict)
|
getFollowersOfActor(baseDir,actor,recipientsDict)
|
||||||
|
|
||||||
return recipientsDict
|
return recipientsDict,recipientsDictFollowers
|
||||||
|
|
||||||
def receiveUpdate(session,baseDir: str, \
|
def receiveUpdate(session,baseDir: str, \
|
||||||
httpPrefix: str,domain :str,port: int, \
|
httpPrefix: str,domain :str,port: int, \
|
||||||
|
@ -425,6 +429,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: object capabilities passed')
|
print('DEBUG: object capabilities passed')
|
||||||
print('copy from '+queueFilename+' to '+destinationFilename)
|
print('copy from '+queueFilename+' to '+destinationFilename)
|
||||||
|
|
||||||
copyfile(queueFilename,destinationFilename)
|
copyfile(queueFilename,destinationFilename)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -557,12 +562,16 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# get recipients list
|
# get recipients list
|
||||||
recipientsDict=inboxPostRecipients(baseDir,queueJson['post'],httpPrefix,domain,port)
|
recipientsDict,recipientsDictFollowers= \
|
||||||
|
inboxPostRecipients(baseDir,queueJson['post'],httpPrefix,domain,port)
|
||||||
|
recipientsList=[recipientsDict,recipientsDictFollowers]
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('*************************************')
|
print('*************************************')
|
||||||
print('Resolved recipients list:')
|
print('Resolved recipients list:')
|
||||||
pprint(recipientsDict)
|
pprint(recipientsDict)
|
||||||
|
print('Resolved sollowers list:')
|
||||||
|
pprint(recipientsDictFollowers)
|
||||||
print('*************************************')
|
print('*************************************')
|
||||||
|
|
||||||
if queueJson['post'].get('capability'):
|
if queueJson['post'].get('capability'):
|
||||||
|
@ -573,8 +582,16 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache
|
||||||
queue.pop(0)
|
queue.pop(0)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for handle,capsId in recipientsDict.items():
|
# copy any posts addressed to followers into the shared inbox
|
||||||
|
# this avoid copying file multiple times to potentially many
|
||||||
|
# individual inboxes
|
||||||
|
if len(recipientsDictFollowers)>0:
|
||||||
|
copyfile(queueFilename, \
|
||||||
|
queueJson['destination'].replace(inboxHandle,inboxHandle))
|
||||||
|
|
||||||
|
# for posts addressed to specific accounts
|
||||||
|
for handle,capsId in recipientsDict.items():
|
||||||
|
destination=queueJson['destination'].replace(inboxHandle,handle)
|
||||||
# check that capabilities are accepted
|
# check that capabilities are accepted
|
||||||
if queueJson['post'].get('capability'):
|
if queueJson['post'].get('capability'):
|
||||||
capabilityIdList=queueJson['post']['capability']
|
capabilityIdList=queueJson['post']['capability']
|
||||||
|
@ -583,32 +600,36 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache
|
||||||
# Here the capability id begins with the handle, so this could also
|
# Here the capability id begins with the handle, so this could also
|
||||||
# be matched separately, but it's probably not necessary
|
# be matched separately, but it's probably not necessary
|
||||||
if capsId in capabilityIdList:
|
if capsId in capabilityIdList:
|
||||||
inboxAfterCapabilities(session,keyId,handle,queueJson['post'], \
|
inboxAfterCapabilities(session,keyId,handle, \
|
||||||
|
queueJson['post'], \
|
||||||
baseDir,httpPrefix, \
|
baseDir,httpPrefix, \
|
||||||
sendThreads,postLog,cachedWebfingers, \
|
sendThreads,postLog, \
|
||||||
personCache,queue,domain,port,useTor, \
|
cachedWebfingers, \
|
||||||
federationList,ocapAlways,debug, \
|
personCache,queue,domain, \
|
||||||
acceptedCaps,
|
port,useTor, \
|
||||||
queueFilename,queueJson['destination'].replace(inboxHandle,handle))
|
federationList,ocapAlways, \
|
||||||
|
debug,acceptedCaps, \
|
||||||
|
queueFilename,destination)
|
||||||
else:
|
else:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: object capabilities check failed')
|
print('DEBUG: object capabilities check failed')
|
||||||
pprint(queueJson['post'])
|
pprint(queueJson['post'])
|
||||||
else:
|
else:
|
||||||
if not ocapAlways:
|
if not ocapAlways:
|
||||||
if inboxAfterCapabilities(session,keyId,handle,queueJson['post'], \
|
inboxAfterCapabilities(session,keyId,handle, \
|
||||||
|
queueJson['post'], \
|
||||||
baseDir,httpPrefix, \
|
baseDir,httpPrefix, \
|
||||||
sendThreads,postLog,cachedWebfingers, \
|
sendThreads,postLog, \
|
||||||
personCache,queue,domain,port,useTor, \
|
cachedWebfingers, \
|
||||||
federationList,ocapAlways,debug, \
|
personCache,queue,domain, \
|
||||||
acceptedCaps, \
|
port,useTor, \
|
||||||
queueFilename,queueJson['destination'].replace(inboxHandle,handle)):
|
federationList,ocapAlways, \
|
||||||
continue
|
debug,acceptedCaps, \
|
||||||
|
queueFilename,destination)
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: object capabilities check failed')
|
print('DEBUG: object capabilities check failed')
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Queue post accepted')
|
print('DEBUG: Queue post accepted')
|
||||||
|
|
||||||
os.remove(queueFilename)
|
os.remove(queueFilename)
|
||||||
queue.pop(0)
|
queue.pop(0)
|
||||||
|
|
Loading…
Reference in New Issue