From 115127c730204bf4e635ce43da1dded9605734de Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 18 Aug 2019 17:49:35 +0100 Subject: [PATCH] Add to fields to like activity --- daemon.py | 3 +++ inbox.py | 2 +- posts.py | 13 +++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/daemon.py b/daemon.py index 29892d49e..7fd67fdc5 100644 --- a/daemon.py +++ b/daemon.py @@ -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) diff --git a/inbox.py b/inbox.py index 4d3c20137..30cc2f3ed 100644 --- a/inbox.py +++ b/inbox.py @@ -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 diff --git a/posts.py b/posts.py index f7fd198a7..6df5e5af2 100644 --- a/posts.py +++ b/posts.py @@ -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