From e80750f289342b58d2fcfd9006d14d3dc9213cb5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 2 Jul 2019 12:13:45 +0100 Subject: [PATCH] like function --- like.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 like.py diff --git a/like.py b/like.py new file mode 100644 index 000000000..b65b3d5f6 --- /dev/null +++ b/like.py @@ -0,0 +1,45 @@ +__filename__ = "like.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "0.0.1" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" + +import json +import commentjson +from utils import urlPermitted + +def like(baseDir: str,federationList: [],username: str, domain: str, port: int,toUrl: str, ccUrl: str, https: bool, comment: str,objectUrl: str, saveToFile: bool) -> {}: + """Creates a like + Typically toUrl will be a followers collection + and ccUrl might be a specific person whose post was liked + objectUrl is typically the url of the message, corresponding to url or atomUri in createPostBase + """ + if not urlPermitted(objectUrl,federationList): + return None + + prefix='https' + if not https: + prefix='http' + + if port!=80 and port!=443: + domain=domain+':'+str(port) + + newLike = { + 'type': 'Like', + 'actor': prefix+'://'+domain+'/users/'+username, + 'name': comment, + 'object': objectUrl, + 'to': [toUrl], + 'cc': [], + 'published': published + } + if ccUrl: + if len(ccUrl)>0: + newLike['cc']=ccUrl + if saveToFile: + if ':' in domain: + domain=domain.split(':')[0] + # TODO update likes collection + return newLike