2019-07-02 11:13:45 +00:00
|
|
|
__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
|
|
|
|
|
2019-07-03 09:40:27 +00:00
|
|
|
def like(baseDir: str,federationList: [],nickname: str,domain: str,port: int, \
|
2019-07-03 19:00:03 +00:00
|
|
|
toUrl: str,ccUrl: str,httpPrefix: str,objectUrl: str,saveToFile: bool) -> {}:
|
2019-07-02 11:13:45 +00:00
|
|
|
"""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
|
|
|
|
"""
|
2019-07-06 10:33:57 +00:00
|
|
|
if not urlPermitted(objectUrl,federationList,capsList,"inbox:write"):
|
2019-07-02 11:13:45 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
if port!=80 and port!=443:
|
|
|
|
domain=domain+':'+str(port)
|
|
|
|
|
|
|
|
newLike = {
|
|
|
|
'type': 'Like',
|
2019-07-03 19:00:03 +00:00
|
|
|
'actor': httpPrefix+'://'+domain+'/users/'+nickname,
|
2019-07-02 11:13:45 +00:00
|
|
|
'object': objectUrl,
|
|
|
|
'to': [toUrl],
|
2019-07-02 18:38:51 +00:00
|
|
|
'cc': []
|
2019-07-02 11:13:45 +00:00
|
|
|
}
|
|
|
|
if ccUrl:
|
|
|
|
if len(ccUrl)>0:
|
|
|
|
newLike['cc']=ccUrl
|
|
|
|
if saveToFile:
|
|
|
|
if ':' in domain:
|
|
|
|
domain=domain.split(':')[0]
|
|
|
|
# TODO update likes collection
|
|
|
|
return newLike
|
2019-07-02 14:02:58 +00:00
|
|
|
|
2019-07-02 20:54:22 +00:00
|
|
|
def likePost(baseDir: str,federationList: [], \
|
2019-07-03 19:00:03 +00:00
|
|
|
nickname: str, domain: str, port: int, httpPrefix: str, \n
|
2019-07-03 09:40:27 +00:00
|
|
|
likeNickname: str, likeDomain: str, likePort: int, likeHttps: bool, \n
|
2019-07-02 20:54:22 +00:00
|
|
|
likeStatusNumber: int,saveToFile: bool) -> {}:
|
2019-07-02 14:02:58 +00:00
|
|
|
"""Likes a given status post
|
|
|
|
"""
|
|
|
|
likeDomain=likeDomain
|
|
|
|
if likePort!=80 and likePort!=443:
|
|
|
|
likeDomain=likeDomain+':'+str(likePort)
|
|
|
|
|
2019-07-03 19:00:03 +00:00
|
|
|
objectUrl = httpPrefix + '://'+likeDomain+'/users/'+likeNickname+'/statuses/'+str(likeStatusNumber)
|
2019-07-02 14:02:58 +00:00
|
|
|
|
2019-07-03 19:00:03 +00:00
|
|
|
return like(baseDir,federationList,nickname,domain,port,toUrl,ccUrl,httpPrefix,objectUrl,saveToFile)
|