Add to fields to like activity

master
Bob Mottram 2019-08-18 17:49:35 +01:00
parent 3beab5e7c5
commit 115127c730
3 changed files with 15 additions and 3 deletions

View File

@ -409,6 +409,9 @@ class PubServer(BaseHTTPRequestHandler):
# For follow activities add a 'to' field, which is a copy of the object field
messageJson,toFieldExists=addToField('Follow',messageJson,self.server.debug)
# For like activities add a 'to' field, which is a copy of the actor within the object field
messageJson,toFieldExists=addToField('Like',messageJson,self.server.debug)
pprint(messageJson)

View File

@ -125,7 +125,7 @@ def inboxMessageHasParams(messageJson: {}) -> bool:
if not messageJson.get(param):
return False
if not messageJson.get('to'):
allowedWithoutToParam=['Follow','Request','Accept','Capability','Undo']
allowedWithoutToParam=['Like','Follow','Request','Accept','Capability','Undo']
if messageJson['type'] not in allowedWithoutToParam:
return False
return True

View File

@ -1270,7 +1270,10 @@ def addToField(activityType: str,postJsonObject: {},debug: bool) -> ({},bool):
isSameType=True
if debug:
print('DEBUG: "to" field assigned to Follow')
postJsonObject['to']=[postJsonObject['object']]
toAddress=postJsonObject['object']
if '/statuses/' in toAddress:
toAddress=toAddress.split('/statuses/')[0]
postJsonObject['to']=[toAddress]
toFieldAdded=True
elif isinstance(postJsonObject['object'], dict):
if postJsonObject['object'].get('type'):
@ -1279,7 +1282,10 @@ def addToField(activityType: str,postJsonObject: {},debug: bool) -> ({},bool):
if isinstance(postJsonObject['object']['object'], str):
if debug:
print('DEBUG: "to" field assigned to Follow')
postJsonObject['object']['to']=[postJsonObject['object']['object']]
toAddress=postJsonObject['object']['object']
if '/statuses/' in toAddress:
toAddress=toAddress.split('/statuses/')[0]
postJsonObject['object']['to']=[toAddress]
postJsonObject['to']=[postJsonObject['object']['object']]
toFieldAdded=True
@ -1319,6 +1325,9 @@ def sendToNamedAddresses(session,baseDir: str, \
recipientsObject=postJsonObject['object']
else:
postJsonObject,fieldAdded=addToField('Follow',postJsonObject,debug)
if not fieldAdded:
return
postJsonObject,fieldAdded=addToField('Like',postJsonObject,debug)
if not fieldAdded:
return
recipientsObject=postJsonObject