Create id of object

master
Bob Mottram 2019-07-03 23:59:56 +01:00
parent 4ef93d01c5
commit 6602d0b78e
2 changed files with 28 additions and 15 deletions

View File

@ -107,16 +107,17 @@ class PubServer(BaseHTTPRequestHandler):
Client to server message post Client to server message post
https://www.w3.org/TR/activitypub/#client-to-server-outbox-delivery https://www.w3.org/TR/activitypub/#client-to-server-outbox-delivery
""" """
if not messageJson.get('object'): if not messageJson.get('type'):
if messageJson.get('type') and messageJson.get('content'): return False
if messageJson['type']!='Create': if not messageJson.get('object') and messageJson.get('content'):
# https://www.w3.org/TR/activitypub/#object-without-create if messageJson['type']!='Create':
if self.server.debug: # https://www.w3.org/TR/activitypub/#object-without-create
print('DEBUG POST to outbox: Adding Create wrapper') if self.server.debug:
messageJson= \ print('DEBUG POST to outbox: Adding Create wrapper')
outboxMessageCreateWrap(self.server.httpPrefix, \ messageJson= \
self.postToNickname, \ outboxMessageCreateWrap(self.server.httpPrefix, \
self.server.domain,messageJson) self.postToNickname, \
self.server.domain,messageJson)
if messageJson['type']=='Create': if messageJson['type']=='Create':
if not (messageJson.get('id') and \ if not (messageJson.get('id') and \
messageJson.get('type') and \ messageJson.get('type') and \
@ -134,7 +135,11 @@ class PubServer(BaseHTTPRequestHandler):
if self.server.debug: if self.server.debug:
print('DEBUG POST to outbox: '+messageJson['type']+' is not a permitted activity type') print('DEBUG POST to outbox: '+messageJson['type']+' is not a permitted activity type')
return False return False
savePostToOutbox(self.server.baseDir,messageJson['id'],self.postToNickname,self.server.domain,messageJson) if messageJson.get('id'):
postId=messageJson['id']
else:
postId=None
savePostToOutbox(self.server.baseDir,postId,self.postToNickname,self.server.domain,messageJson)
return True return True
def do_GET(self): def do_GET(self):

View File

@ -249,11 +249,19 @@ def deleteAllPosts(baseDir: str,nickname: str, domain: str) -> None:
except Exception as e: except Exception as e:
print(e) print(e)
def savePostToOutbox(baseDir: str,postId: str,nickname: str, domain: str,postJson: {}) -> None: def savePostToOutbox(baseDir: str,httpPrefix: str,postId: str,nickname: str, domain: str,postJson: {}) -> None:
"""Saves the give json to the outbox """Saves the give json to the outbox
""" """
if ':' in domain: if ':' in domain:
domain=domain.split(':')[0] domain=domain.split(':')[0]
if not postId:
statusNumber,published = getStatusNumber()
postId=httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber
postJson['id']=postId+'/activity'
if postJson.get('object'):
postJson['object']['id']=postId
postJson['object']['atomUri']=postId
outboxDir = createOutboxDir(nickname,domain,baseDir) outboxDir = createOutboxDir(nickname,domain,baseDir)
filename=outboxDir+'/'+postId.replace('/','#')+'.json' filename=outboxDir+'/'+postId.replace('/','#')+'.json'
with open(filename, 'w') as fp: with open(filename, 'w') as fp:
@ -301,7 +309,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
'to': [toUrl], 'to': [toUrl],
'cc': [], 'cc': [],
'sensitive': sensitive, 'sensitive': sensitive,
'atomUri': httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber, 'atomUri': newPostId,
'inReplyToAtomUri': inReplyToAtomUri, 'inReplyToAtomUri': inReplyToAtomUri,
'conversation': 'tag:'+domain+','+conversationDate+':objectId='+conversationId+':objectType=Conversation', 'conversation': 'tag:'+domain+','+conversationDate+':objectId='+conversationId+':objectType=Conversation',
'content': content, 'content': content,
@ -333,7 +341,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
'to': [toUrl], 'to': [toUrl],
'cc': [], 'cc': [],
'sensitive': sensitive, 'sensitive': sensitive,
'atomUri': httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber, 'atomUri': newPostId,
'inReplyToAtomUri': inReplyToAtomUri, 'inReplyToAtomUri': inReplyToAtomUri,
'conversation': 'tag:'+domain+','+conversationDate+':objectId='+conversationId+':objectType=Conversation', 'conversation': 'tag:'+domain+','+conversationDate+':objectId='+conversationId+':objectType=Conversation',
'content': content, 'content': content,
@ -349,7 +357,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
newPost['cc']=ccUrl newPost['cc']=ccUrl
newPost['object']['cc']=ccUrl newPost['object']['cc']=ccUrl
if saveToFile: if saveToFile:
savePostToOutbox(baseDir,newPostId,nickname,domain,newPost) savePostToOutbox(baseDir,httpPrefix,newPostId,nickname,domain,newPost)
return newPost return newPost
def outboxMessageCreateWrap(httpPrefix str,nickname: str,domain: str,messageJson: {}) -> {}: def outboxMessageCreateWrap(httpPrefix str,nickname: str,domain: str,messageJson: {}) -> {}: