Move shared inbox posts to people who follow

master
Bob Mottram 2019-07-05 14:26:54 +01:00
parent a0499dc95b
commit cdddf40b26
2 changed files with 32 additions and 2 deletions

View File

@ -376,6 +376,7 @@ class PubServer(BaseHTTPRequestHandler):
if not inboxPermittedMessage(self.server.domain,messageJson,self.server.federationList): if not inboxPermittedMessage(self.server.domain,messageJson,self.server.federationList):
if self.server.debug: if self.server.debug:
# https://www.youtube.com/watch?v=K3PrSj9XEu4
print('DEBUG: Ah Ah Ah') print('DEBUG: Ah Ah Ah')
self.send_response(403) self.send_response(403)
self.end_headers() self.end_headers()

View File

@ -12,6 +12,7 @@ import datetime
import time import time
import json import json
import commentjson import commentjson
from shutil import copyfile
from utils import urlPermitted from utils import urlPermitted
from utils import createInboxQueueDir from utils import createInboxQueueDir
from httpsig import verifyPostHeaders from httpsig import verifyPostHeaders
@ -160,6 +161,7 @@ def runInboxQueue(baseDir: str,httpPrefix: str,personCache: {},queue: [],domain:
# Try a few times to obtain the public key # Try a few times to obtain the public key
pubKey=None pubKey=None
keyId=None
for tries in range(8): for tries in range(8):
keyId=None keyId=None
signatureParams=queueJson['headers'].split(',') signatureParams=queueJson['headers'].split(',')
@ -222,7 +224,34 @@ def runInboxQueue(baseDir: str,httpPrefix: str,personCache: {},queue: [],domain:
if debug: if debug:
print('DEBUG: Queue post accepted') print('DEBUG: Queue post accepted')
# move to the destination inbox if queueJson['sharedInbox']:
os.rename(queueFilename,queueJson['destination']) if '/users/' in keyId:
# Who is this from? Use the actor from the keyId where we obtained the public key
fromList=keyId.replace('https://','').replace('http://','').replace('dat://','').replace('#main-key','').split('/users/')
fromNickname=fromList[1]
fromDomain=fromList[0]
# get the followers of the sender
followList=getFollowersOfPerson(baseDir,fromNickname,fromDomain)
for followerHandle in followList:
followerDir=baseDir+'/accounts/'+followerHandle
if os.path.isdir(followerDir):
if not os.path.isdir(followerDir+'/inbox'):
os.mkdir(followerDir+'/inbox')
postId=queueJson['post']['id'].replace('/activity','')
destination=followerDir+'/inbox/'+postId.replace('/','#')+'.json'
if os.path.isfile(destination):
# post already exists in this person's inbox
continue
# We could do this in a more storage space efficient way
# by linking to the inbox of sharedinbox@domain
# However, this allows for easy deletion by individuals
# without affecting any other people
copyfile(queueFilename, destination)
# copy to followers
# remove item from shared inbox
os.remove(queueFilename)
else:
# move to the destination inbox
os.rename(queueFilename,queueJson['destination'])
queue.pop(0) queue.pop(0)
time.sleep(2) time.sleep(2)