Snake case

main
Bob Mottram 2021-12-26 00:07:44 +00:00
parent 49308fbcb5
commit 81141ad35b
13 changed files with 135 additions and 132 deletions

View File

@ -75,8 +75,8 @@ def createReject(base_dir: str, federation_list: [],
http_prefix, objectJson, 'Reject') http_prefix, objectJson, 'Reject')
def _acceptFollow(base_dir: str, domain: str, message_json: {}, def _accept_follow(base_dir: str, domain: str, message_json: {},
federation_list: [], debug: bool) -> None: federation_list: [], debug: bool) -> None:
"""Receiving a follow Accept activity """Receiving a follow Accept activity
""" """
if not hasObjectStringType(message_json, debug): if not hasObjectStringType(message_json, debug):
@ -98,87 +98,89 @@ def _acceptFollow(base_dir: str, domain: str, message_json: {},
return return
if debug: if debug:
print('DEBUG: follow Accept received') print('DEBUG: follow Accept received')
thisActor = message_json['object']['actor'] this_actor = message_json['object']['actor']
nickname = getNicknameFromActor(thisActor) nickname = getNicknameFromActor(this_actor)
if not nickname: if not nickname:
print('WARN: no nickname found in ' + thisActor) print('WARN: no nickname found in ' + this_actor)
return return
acceptedDomain, acceptedPort = getDomainFromActor(thisActor) acceptedDomain, acceptedPort = getDomainFromActor(this_actor)
if not acceptedDomain: if not acceptedDomain:
if debug: if debug:
print('DEBUG: domain not found in ' + thisActor) print('DEBUG: domain not found in ' + this_actor)
return return
if not nickname: if not nickname:
if debug: if debug:
print('DEBUG: nickname not found in ' + thisActor) print('DEBUG: nickname not found in ' + this_actor)
return return
if acceptedPort: if acceptedPort:
if '/' + acceptedDomain + ':' + str(acceptedPort) + \ if '/' + acceptedDomain + ':' + str(acceptedPort) + \
'/users/' + nickname not in thisActor: '/users/' + nickname not in this_actor:
if debug: if debug:
print('Port: ' + str(acceptedPort)) print('Port: ' + str(acceptedPort))
print('Expected: /' + acceptedDomain + ':' + print('Expected: /' + acceptedDomain + ':' +
str(acceptedPort) + '/users/' + nickname) str(acceptedPort) + '/users/' + nickname)
print('Actual: ' + thisActor) print('Actual: ' + this_actor)
print('DEBUG: unrecognized actor ' + thisActor) print('DEBUG: unrecognized actor ' + this_actor)
return return
else: else:
if not '/' + acceptedDomain + '/users/' + nickname in thisActor: if not '/' + acceptedDomain + '/users/' + nickname in this_actor:
if debug: if debug:
print('Expected: /' + acceptedDomain + '/users/' + nickname) print('Expected: /' + acceptedDomain + '/users/' + nickname)
print('Actual: ' + thisActor) print('Actual: ' + this_actor)
print('DEBUG: unrecognized actor ' + thisActor) print('DEBUG: unrecognized actor ' + this_actor)
return return
followedActor = message_json['object']['object'] followed_actor = message_json['object']['object']
followedDomain, port = getDomainFromActor(followedActor) followed_domain, port = getDomainFromActor(followed_actor)
if not followedDomain: if not followed_domain:
print('DEBUG: no domain found within Follow activity object ' + print('DEBUG: no domain found within Follow activity object ' +
followedActor) followed_actor)
return return
followedDomainFull = followedDomain followed_domain_full = followed_domain
if port: if port:
followedDomainFull = followedDomain + ':' + str(port) followed_domain_full = followed_domain + ':' + str(port)
followedNickname = getNicknameFromActor(followedActor) followed_nickname = getNicknameFromActor(followed_actor)
if not followedNickname: if not followed_nickname:
print('DEBUG: no nickname found within Follow activity object ' + print('DEBUG: no nickname found within Follow activity object ' +
followedActor) followed_actor)
return return
acceptedDomainFull = acceptedDomain accepted_domain_full = acceptedDomain
if acceptedPort: if acceptedPort:
acceptedDomainFull = acceptedDomain + ':' + str(acceptedPort) accepted_domain_full = acceptedDomain + ':' + str(acceptedPort)
# has this person already been unfollowed? # has this person already been unfollowed?
unfollowedFilename = \ unfollowed_filename = \
acctDir(base_dir, nickname, acceptedDomainFull) + '/unfollowed.txt' acctDir(base_dir, nickname, accepted_domain_full) + '/unfollowed.txt'
if os.path.isfile(unfollowedFilename): if os.path.isfile(unfollowed_filename):
if followedNickname + '@' + followedDomainFull in \ if followed_nickname + '@' + followed_domain_full in \
open(unfollowedFilename).read(): open(unfollowed_filename).read():
if debug: if debug:
print('DEBUG: follow accept arrived for ' + print('DEBUG: follow accept arrived for ' +
nickname + '@' + acceptedDomainFull + nickname + '@' + accepted_domain_full +
' from ' + followedNickname + '@' + followedDomainFull + ' from ' +
followed_nickname + '@' + followed_domain_full +
' but they have been unfollowed') ' but they have been unfollowed')
return return
# does the url path indicate that this is a group actor # does the url path indicate that this is a group actor
groupAccount = hasGroupType(base_dir, followedActor, None, debug) group_account = hasGroupType(base_dir, followed_actor, None, debug)
if debug: if debug:
print('Accepted follow is a group: ' + str(groupAccount) + print('Accepted follow is a group: ' + str(group_account) +
' ' + followedActor + ' ' + base_dir) ' ' + followed_actor + ' ' + base_dir)
if followPerson(base_dir, if followPerson(base_dir,
nickname, acceptedDomainFull, nickname, accepted_domain_full,
followedNickname, followedDomainFull, followed_nickname, followed_domain_full,
federation_list, debug, groupAccount): federation_list, debug, group_account):
if debug: if debug:
print('DEBUG: ' + nickname + '@' + acceptedDomainFull + print('DEBUG: ' + nickname + '@' + accepted_domain_full +
' followed ' + followedNickname + '@' + followedDomainFull) ' followed ' +
followed_nickname + '@' + followed_domain_full)
else: else:
if debug: if debug:
print('DEBUG: Unable to create follow - ' + print('DEBUG: Unable to create follow - ' +
nickname + '@' + acceptedDomain + ' -> ' + nickname + '@' + acceptedDomain + ' -> ' +
followedNickname + '@' + followedDomain) followed_nickname + '@' + followed_domain)
def receiveAcceptReject(session, base_dir: str, def receiveAcceptReject(session, base_dir: str,
@ -198,7 +200,7 @@ def receiveAcceptReject(session, base_dir: str,
if debug: if debug:
print('DEBUG: "users" or "profile" missing from actor in ' + print('DEBUG: "users" or "profile" missing from actor in ' +
message_json['type'] + '. Assuming single user instance.') message_json['type'] + '. Assuming single user instance.')
domain, tempPort = getDomainFromActor(message_json['actor']) domain, _ = getDomainFromActor(message_json['actor'])
if not domainPermitted(domain, federation_list): if not domainPermitted(domain, federation_list):
if debug: if debug:
print('DEBUG: ' + message_json['type'] + print('DEBUG: ' + message_json['type'] +
@ -213,7 +215,7 @@ def receiveAcceptReject(session, base_dir: str,
' does not contain a nickname. ' + ' does not contain a nickname. ' +
'Assuming single user instance.') 'Assuming single user instance.')
# receive follow accept # receive follow accept
_acceptFollow(base_dir, domain, message_json, federation_list, debug) _accept_follow(base_dir, domain, message_json, federation_list, debug)
if debug: if debug:
print('DEBUG: Uh, ' + message_json['type'] + ', I guess') print('DEBUG: Uh, ' + message_json['type'] + ', I guess')
return True return True

View File

@ -163,7 +163,7 @@ def createAnnounce(session, base_dir: str, federation_list: [],
announceNickname = None announceNickname = None
announceDomain = None announceDomain = None
announcePort = None announcePort = None
groupAccount = False group_account = False
if hasUsersPath(objectUrl): if hasUsersPath(objectUrl):
announceNickname = getNicknameFromActor(objectUrl) announceNickname = getNicknameFromActor(objectUrl)
announceDomain, announcePort = getDomainFromActor(objectUrl) announceDomain, announcePort = getDomainFromActor(objectUrl)
@ -172,7 +172,7 @@ def createAnnounce(session, base_dir: str, federation_list: [],
objectUrl.split('/' + announceNickname + '/')[0] + \ objectUrl.split('/' + announceNickname + '/')[0] + \
'/' + announceNickname '/' + announceNickname
if hasGroupType(base_dir, announceActor, person_cache): if hasGroupType(base_dir, announceActor, person_cache):
groupAccount = True group_account = True
if announceNickname and announceDomain: if announceNickname and announceDomain:
sendSignedJson(newAnnounce, session, base_dir, sendSignedJson(newAnnounce, session, base_dir,
@ -180,7 +180,7 @@ def createAnnounce(session, base_dir: str, federation_list: [],
announceNickname, announceDomain, announcePort, None, announceNickname, announceDomain, announcePort, None,
http_prefix, True, client_to_server, federation_list, http_prefix, True, client_to_server, federation_list,
send_threads, postLog, cached_webfingers, person_cache, send_threads, postLog, cached_webfingers, person_cache,
debug, project_version, None, groupAccount, debug, project_version, None, group_account,
signing_priv_key_pem, 639633) signing_priv_key_pem, 639633)
return newAnnounce return newAnnounce

View File

@ -2954,13 +2954,13 @@ class PubServer(BaseHTTPRequestHandler):
} }
pathUsersSection = path.split('/users/')[1] pathUsersSection = path.split('/users/')[1]
self.postToNickname = pathUsersSection.split('/')[0] self.postToNickname = pathUsersSection.split('/')[0]
groupAccount = hasGroupType(self.server.base_dir, group_account = hasGroupType(self.server.base_dir,
followingActor, followingActor,
self.server.person_cache) self.server.person_cache)
unfollowAccount(self.server.base_dir, self.postToNickname, unfollowAccount(self.server.base_dir, self.postToNickname,
self.server.domain, self.server.domain,
followingNickname, followingDomainFull, followingNickname, followingDomainFull,
self.server.debug, groupAccount) self.server.debug, group_account)
self._postToOutboxThread(unfollowJson) self._postToOutboxThread(unfollowJson)
if callingDomain.endswith('.onion') and onion_domain: if callingDomain.endswith('.onion') and onion_domain:

View File

@ -209,12 +209,12 @@ def getMutualsOfPerson(base_dir: str,
def followerOfPerson(base_dir: str, nickname: str, domain: str, def followerOfPerson(base_dir: str, nickname: str, domain: str,
followerNickname: str, followerDomain: str, followerNickname: str, followerDomain: str,
federation_list: [], debug: bool, federation_list: [], debug: bool,
groupAccount: bool) -> bool: group_account: bool) -> bool:
"""Adds a follower of the given person """Adds a follower of the given person
""" """
return followPerson(base_dir, nickname, domain, return followPerson(base_dir, nickname, domain,
followerNickname, followerDomain, followerNickname, followerDomain,
federation_list, debug, groupAccount, 'followers.txt') federation_list, debug, group_account, 'followers.txt')
def getFollowerDomains(base_dir: str, nickname: str, domain: str) -> []: def getFollowerDomains(base_dir: str, nickname: str, domain: str) -> []:
@ -283,14 +283,14 @@ def isFollowerOfPerson(base_dir: str, nickname: str, domain: str,
def unfollowAccount(base_dir: str, nickname: str, domain: str, def unfollowAccount(base_dir: str, nickname: str, domain: str,
followNickname: str, followDomain: str, followNickname: str, followDomain: str,
debug: bool, groupAccount: bool, debug: bool, group_account: bool,
followFile: str = 'following.txt') -> bool: followFile: str = 'following.txt') -> bool:
"""Removes a person to the follow list """Removes a person to the follow list
""" """
domain = removeDomainPort(domain) domain = removeDomainPort(domain)
handle = nickname + '@' + domain handle = nickname + '@' + domain
handleToUnfollow = followNickname + '@' + followDomain handleToUnfollow = followNickname + '@' + followDomain
if groupAccount: if group_account:
handleToUnfollow = '!' + handleToUnfollow handleToUnfollow = '!' + handleToUnfollow
if not os.path.isdir(base_dir + '/accounts'): if not os.path.isdir(base_dir + '/accounts'):
os.mkdir(base_dir + '/accounts') os.mkdir(base_dir + '/accounts')
@ -348,12 +348,12 @@ def unfollowAccount(base_dir: str, nickname: str, domain: str,
def unfollowerOfAccount(base_dir: str, nickname: str, domain: str, def unfollowerOfAccount(base_dir: str, nickname: str, domain: str,
followerNickname: str, followerDomain: str, followerNickname: str, followerDomain: str,
debug: bool, groupAccount: bool) -> bool: debug: bool, group_account: bool) -> bool:
"""Remove a follower of a person """Remove a follower of a person
""" """
return unfollowAccount(base_dir, nickname, domain, return unfollowAccount(base_dir, nickname, domain,
followerNickname, followerDomain, followerNickname, followerDomain,
debug, groupAccount, 'followers.txt') debug, group_account, 'followers.txt')
def clearFollows(base_dir: str, nickname: str, domain: str, def clearFollows(base_dir: str, nickname: str, domain: str,
@ -624,7 +624,7 @@ def storeFollowRequest(base_dir: str,
nickname: str, domain: str, fromPort: int, nickname: str, domain: str, fromPort: int,
followJson: {}, followJson: {},
debug: bool, personUrl: str, debug: bool, personUrl: str,
groupAccount: bool) -> bool: group_account: bool) -> bool:
"""Stores the follow request for later use """Stores the follow request for later use
""" """
accountsDir = base_dir + '/accounts/' + \ accountsDir = base_dir + '/accounts/' + \
@ -635,7 +635,7 @@ def storeFollowRequest(base_dir: str,
domainFull = getFullDomain(domain, fromPort) domainFull = getFullDomain(domain, fromPort)
approveHandle = getFullDomain(nickname + '@' + domain, fromPort) approveHandle = getFullDomain(nickname + '@' + domain, fromPort)
if groupAccount: if group_account:
approveHandle = '!' + approveHandle approveHandle = '!' + approveHandle
followersFilename = accountsDir + '/followers.txt' followersFilename = accountsDir + '/followers.txt'
@ -683,7 +683,7 @@ def storeFollowRequest(base_dir: str,
approveHandleStored = approveHandle approveHandleStored = approveHandle
if '/users/' not in personUrl: if '/users/' not in personUrl:
approveHandleStored = personUrl approveHandleStored = personUrl
if groupAccount: if group_account:
approveHandle = '!' + approveHandle approveHandle = '!' + approveHandle
if os.path.isfile(approveFollowsFilename): if os.path.isfile(approveFollowsFilename):
@ -759,11 +759,11 @@ def followedAccountAccepts(session, base_dir: str, http_prefix: str,
print('EX: followedAccountAccepts unable to delete ' + print('EX: followedAccountAccepts unable to delete ' +
followActivityfilename) followActivityfilename)
groupAccount = False group_account = False
if followJson: if followJson:
if followJson.get('actor'): if followJson.get('actor'):
if hasGroupType(base_dir, followJson['actor'], person_cache): if hasGroupType(base_dir, followJson['actor'], person_cache):
groupAccount = True group_account = True
return sendSignedJson(acceptJson, session, base_dir, return sendSignedJson(acceptJson, session, base_dir,
nicknameToFollow, domainToFollow, port, nicknameToFollow, domainToFollow, port,
@ -772,7 +772,7 @@ def followedAccountAccepts(session, base_dir: str, http_prefix: str,
federation_list, federation_list,
send_threads, postLog, cached_webfingers, send_threads, postLog, cached_webfingers,
person_cache, debug, project_version, None, person_cache, debug, project_version, None,
groupAccount, signing_priv_key_pem, group_account, signing_priv_key_pem,
7856837) 7856837)
@ -820,9 +820,9 @@ def followedAccountRejects(session, base_dir: str, http_prefix: str,
nickname + '@' + domain + ' port ' + str(fromPort)) nickname + '@' + domain + ' port ' + str(fromPort))
client_to_server = False client_to_server = False
denyHandle = getFullDomain(nickname + '@' + domain, fromPort) denyHandle = getFullDomain(nickname + '@' + domain, fromPort)
groupAccount = False group_account = False
if hasGroupType(base_dir, personUrl, person_cache): if hasGroupType(base_dir, personUrl, person_cache):
groupAccount = True group_account = True
# remove from the follow requests file # remove from the follow requests file
removeFromFollowRequests(base_dir, nicknameToFollow, domainToFollow, removeFromFollowRequests(base_dir, nicknameToFollow, domainToFollow,
denyHandle, debug) denyHandle, debug)
@ -840,7 +840,7 @@ def followedAccountRejects(session, base_dir: str, http_prefix: str,
federation_list, federation_list,
send_threads, postLog, cached_webfingers, send_threads, postLog, cached_webfingers,
person_cache, debug, project_version, None, person_cache, debug, project_version, None,
groupAccount, signing_priv_key_pem, group_account, signing_priv_key_pem,
6393063) 6393063)
@ -869,12 +869,12 @@ def sendFollowRequest(session, base_dir: str,
statusNumber, published = getStatusNumber() statusNumber, published = getStatusNumber()
groupAccount = False group_account = False
if followNickname: if followNickname:
followedId = followedActor followedId = followedActor
followHandle = followNickname + '@' + requestDomain followHandle = followNickname + '@' + requestDomain
groupAccount = hasGroupType(base_dir, followedActor, person_cache) group_account = hasGroupType(base_dir, followedActor, person_cache)
if groupAccount: if group_account:
followHandle = '!' + followHandle followHandle = '!' + followHandle
print('Follow request being sent to group account') print('Follow request being sent to group account')
else: else:
@ -911,7 +911,7 @@ def sendFollowRequest(session, base_dir: str,
'actor': followActor, 'actor': followActor,
'object': followedId 'object': followedId
} }
if groupAccount: if group_account:
newFollowJson['to'] = followedId newFollowJson['to'] = followedId
print('Follow request: ' + str(newFollowJson)) print('Follow request: ' + str(newFollowJson))
@ -931,7 +931,7 @@ def sendFollowRequest(session, base_dir: str,
http_prefix, True, client_to_server, http_prefix, True, client_to_server,
federation_list, federation_list,
send_threads, postLog, cached_webfingers, person_cache, send_threads, postLog, cached_webfingers, person_cache,
debug, project_version, None, groupAccount, debug, project_version, None, group_account,
signing_priv_key_pem, 8234389) signing_priv_key_pem, 8234389)
return newFollowJson return newFollowJson
@ -1414,11 +1414,11 @@ def outboxUndoFollow(base_dir: str, message_json: {}, debug: bool) -> None:
getDomainFromActor(message_json['object']['object']) getDomainFromActor(message_json['object']['object'])
domainFollowingFull = getFullDomain(domainFollowing, portFollowing) domainFollowingFull = getFullDomain(domainFollowing, portFollowing)
groupAccount = \ group_account = \
hasGroupType(base_dir, message_json['object']['object'], None) hasGroupType(base_dir, message_json['object']['object'], None)
if unfollowAccount(base_dir, nicknameFollower, domainFollowerFull, if unfollowAccount(base_dir, nicknameFollower, domainFollowerFull,
nicknameFollowing, domainFollowingFull, nicknameFollowing, domainFollowingFull,
debug, groupAccount): debug, group_account):
if debug: if debug:
print('DEBUG: ' + nicknameFollower + ' unfollowed ' + print('DEBUG: ' + nicknameFollower + ' unfollowed ' +
nicknameFollowing + '@' + domainFollowingFull) nicknameFollowing + '@' + domainFollowingFull)

View File

@ -776,12 +776,12 @@ def _receiveUndoFollow(session, base_dir: str, http_prefix: str,
getDomainFromActor(message_json['object']['object']) getDomainFromActor(message_json['object']['object'])
domainFollowingFull = getFullDomain(domainFollowing, portFollowing) domainFollowingFull = getFullDomain(domainFollowing, portFollowing)
groupAccount = \ group_account = \
hasGroupType(base_dir, message_json['object']['actor'], None) hasGroupType(base_dir, message_json['object']['actor'], None)
if unfollowerOfAccount(base_dir, if unfollowerOfAccount(base_dir,
nicknameFollowing, domainFollowingFull, nicknameFollowing, domainFollowingFull,
nicknameFollower, domainFollowerFull, nicknameFollower, domainFollowerFull,
debug, groupAccount): debug, group_account):
print(nicknameFollowing + '@' + domainFollowingFull + ': ' print(nicknameFollowing + '@' + domainFollowingFull + ': '
'Follower ' + nicknameFollower + '@' + domainFollowerFull + 'Follower ' + nicknameFollower + '@' + domainFollowerFull +
' was removed') ' was removed')
@ -2823,10 +2823,10 @@ def _bounceDM(senderPostId: str, session, http_prefix: str,
lastBounceMessage[0] = currTime lastBounceMessage[0] = currTime
senderNickname = sendingHandle.split('@')[0] senderNickname = sendingHandle.split('@')[0]
groupAccount = False group_account = False
if sendingHandle.startswith('!'): if sendingHandle.startswith('!'):
sendingHandle = sendingHandle[1:] sendingHandle = sendingHandle[1:]
groupAccount = True group_account = True
senderDomain = sendingHandle.split('@')[1] senderDomain = sendingHandle.split('@')[1]
senderPort = port senderPort = port
if ':' in senderDomain: if ':' in senderDomain:
@ -2875,7 +2875,7 @@ def _bounceDM(senderPostId: str, session, http_prefix: str,
senderNickname, senderDomain, senderPort, cc, senderNickname, senderDomain, senderPort, cc,
http_prefix, False, False, federation_list, http_prefix, False, False, federation_list,
send_threads, postLog, cached_webfingers, send_threads, postLog, cached_webfingers,
person_cache, debug, __version__, None, groupAccount, person_cache, debug, __version__, None, group_account,
signing_priv_key_pem, 7238634) signing_priv_key_pem, 7238634)
return True return True
@ -3984,9 +3984,9 @@ def _receiveFollowRequest(session, base_dir: str, http_prefix: str,
print('Unable to obtain following actor: ' + print('Unable to obtain following actor: ' +
message_json['actor']) message_json['actor'])
groupAccount = \ group_account = \
hasGroupType(base_dir, message_json['actor'], person_cache) hasGroupType(base_dir, message_json['actor'], person_cache)
if groupAccount and isGroupAccount(base_dir, nickname, domain): if group_account and isGroupAccount(base_dir, nickname, domain):
print('Group cannot follow a group') print('Group cannot follow a group')
return False return False
@ -3995,7 +3995,7 @@ def _receiveFollowRequest(session, base_dir: str, http_prefix: str,
nicknameToFollow, domainToFollow, port, nicknameToFollow, domainToFollow, port,
nickname, domain, fromPort, nickname, domain, fromPort,
message_json, debug, message_json['actor'], message_json, debug, message_json['actor'],
groupAccount) group_account)
else: else:
print('Follow request does not require approval ' + approveHandle) print('Follow request does not require approval ' + approveHandle)
# update the followers # update the followers
@ -4026,13 +4026,13 @@ def _receiveFollowRequest(session, base_dir: str, http_prefix: str,
followersFilename + ' adding ' + approveHandle) followersFilename + ' adding ' + approveHandle)
if os.path.isfile(followersFilename): if os.path.isfile(followersFilename):
if approveHandle not in open(followersFilename).read(): if approveHandle not in open(followersFilename).read():
groupAccount = \ group_account = \
hasGroupType(base_dir, hasGroupType(base_dir,
message_json['actor'], person_cache) message_json['actor'], person_cache)
if debug: if debug:
print(approveHandle + ' / ' + message_json['actor'] + print(approveHandle + ' / ' + message_json['actor'] +
' is Group: ' + str(groupAccount)) ' is Group: ' + str(group_account))
if groupAccount and \ if group_account and \
isGroupAccount(base_dir, nickname, domain): isGroupAccount(base_dir, nickname, domain):
print('Group cannot follow a group') print('Group cannot follow a group')
return False return False
@ -4041,7 +4041,7 @@ def _receiveFollowRequest(session, base_dir: str, http_prefix: str,
content = followersFile.read() content = followersFile.read()
if approveHandle + '\n' not in content: if approveHandle + '\n' not in content:
followersFile.seek(0, 0) followersFile.seek(0, 0)
if not groupAccount: if not group_account:
followersFile.write(approveHandle + followersFile.write(approveHandle +
'\n' + content) '\n' + content)
else: else:

View File

@ -102,11 +102,11 @@ def _like(recentPostsCache: {},
likedPostNickname = None likedPostNickname = None
likedPostDomain = None likedPostDomain = None
likedPostPort = None likedPostPort = None
groupAccount = False group_account = False
if actorLiked: if actorLiked:
likedPostNickname = getNicknameFromActor(actorLiked) likedPostNickname = getNicknameFromActor(actorLiked)
likedPostDomain, likedPostPort = getDomainFromActor(actorLiked) likedPostDomain, likedPostPort = getDomainFromActor(actorLiked)
groupAccount = hasGroupType(base_dir, actorLiked, person_cache) group_account = hasGroupType(base_dir, actorLiked, person_cache)
else: else:
if hasUsersPath(objectUrl): if hasUsersPath(objectUrl):
likedPostNickname = getNicknameFromActor(objectUrl) likedPostNickname = getNicknameFromActor(objectUrl)
@ -115,7 +115,8 @@ def _like(recentPostsCache: {},
actorLiked = \ actorLiked = \
objectUrl.split('/' + likedPostNickname + '/')[0] + \ objectUrl.split('/' + likedPostNickname + '/')[0] + \
'/' + likedPostNickname '/' + likedPostNickname
groupAccount = hasGroupType(base_dir, actorLiked, person_cache) group_account = \
hasGroupType(base_dir, actorLiked, person_cache)
if likedPostNickname: if likedPostNickname:
postFilename = locatePost(base_dir, nickname, domain, objectUrl) postFilename = locatePost(base_dir, nickname, domain, objectUrl)
@ -137,7 +138,7 @@ def _like(recentPostsCache: {},
'https://www.w3.org/ns/activitystreams#Public', 'https://www.w3.org/ns/activitystreams#Public',
http_prefix, True, client_to_server, federation_list, http_prefix, True, client_to_server, federation_list,
send_threads, postLog, cached_webfingers, person_cache, send_threads, postLog, cached_webfingers, person_cache,
debug, project_version, None, groupAccount, debug, project_version, None, group_account,
signing_priv_key_pem, 7367374) signing_priv_key_pem, 7367374)
return newLikeJson return newLikeJson

View File

@ -151,9 +151,9 @@ def manualApproveFollowRequest(session, base_dir: str,
if approveHandle in approveFollowsStr: if approveHandle in approveFollowsStr:
exists = True exists = True
elif '@' in approveHandle: elif '@' in approveHandle:
groupAccount = False group_account = False
if approveHandle.startswith('!'): if approveHandle.startswith('!'):
groupAccount = True group_account = True
reqNick = approveHandle.split('@')[0].replace('!', '') reqNick = approveHandle.split('@')[0].replace('!', '')
reqDomain = approveHandle.split('@')[1].strip() reqDomain = approveHandle.split('@')[1].strip()
reqPrefix = http_prefix + '://' + reqDomain reqPrefix = http_prefix + '://' + reqDomain
@ -162,7 +162,7 @@ def manualApproveFollowRequest(session, base_dir: str,
if reqPrefix + userPath + reqNick in approveFollowsStr: if reqPrefix + userPath + reqNick in approveFollowsStr:
exists = True exists = True
approveHandleFull = reqPrefix + userPath + reqNick approveHandleFull = reqPrefix + userPath + reqNick
if groupAccount: if group_account:
approveHandleFull = '!' + approveHandleFull approveHandleFull = '!' + approveHandleFull
break break
if not exists: if not exists:

View File

@ -106,14 +106,14 @@ def _updateMovedHandle(base_dir: str, nickname: str, domain: str,
if movedToPort: if movedToPort:
if movedToPort != 80 and movedToPort != 443: if movedToPort != 80 and movedToPort != 443:
movedToDomainFull = movedToDomain + ':' + str(movedToPort) movedToDomainFull = movedToDomain + ':' + str(movedToPort)
groupAccount = hasGroupType(base_dir, movedToUrl, None) group_account = hasGroupType(base_dir, movedToUrl, None)
if isBlocked(base_dir, nickname, domain, if isBlocked(base_dir, nickname, domain,
movedToNickname, movedToDomain): movedToNickname, movedToDomain):
# someone that you follow has moved to a blocked domain # someone that you follow has moved to a blocked domain
# so just unfollow them # so just unfollow them
unfollowAccount(base_dir, nickname, domain, unfollowAccount(base_dir, nickname, domain,
movedToNickname, movedToDomainFull, movedToNickname, movedToDomainFull,
debug, groupAccount, 'following.txt') debug, group_account, 'following.txt')
return ctr return ctr
followingFilename = acctDir(base_dir, nickname, domain) + '/following.txt' followingFilename = acctDir(base_dir, nickname, domain) + '/following.txt'
@ -139,7 +139,7 @@ def _updateMovedHandle(base_dir: str, nickname: str, domain: str,
unfollowAccount(base_dir, nickname, domain, unfollowAccount(base_dir, nickname, domain,
handleNickname, handleNickname,
handleDomain, handleDomain,
debug, groupAccount, 'following.txt') debug, group_account, 'following.txt')
ctr += 1 ctr += 1
print('Unfollowed ' + handle + ' who has moved to ' + print('Unfollowed ' + handle + ' who has moved to ' +
movedToHandle) movedToHandle)

View File

@ -351,7 +351,7 @@ def getDefaultPersonContext() -> str:
def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int, def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int,
http_prefix: str, saveToFile: bool, http_prefix: str, saveToFile: bool,
manual_follower_approval: bool, manual_follower_approval: bool,
groupAccount: bool, group_account: bool,
password: str) -> (str, str, {}, {}): password: str) -> (str, str, {}, {}):
"""Returns the private key, public key, actor and webfinger endpoint """Returns the private key, public key, actor and webfinger endpoint
""" """
@ -359,7 +359,7 @@ def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int,
webfingerEndpoint = \ webfingerEndpoint = \
createWebfingerEndpoint(nickname, domain, port, createWebfingerEndpoint(nickname, domain, port,
http_prefix, publicKeyPem, http_prefix, publicKeyPem,
groupAccount) group_account)
if saveToFile: if saveToFile:
storeWebfingerEndpoint(nickname, domain, port, storeWebfingerEndpoint(nickname, domain, port,
base_dir, webfingerEndpoint) base_dir, webfingerEndpoint)
@ -369,7 +369,7 @@ def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int,
domain = getFullDomain(domain, port) domain = getFullDomain(domain, port)
personType = 'Person' personType = 'Person'
if groupAccount: if group_account:
personType = 'Group' personType = 'Group'
# Enable follower approval by default # Enable follower approval by default
approveFollowers = manual_follower_approval approveFollowers = manual_follower_approval
@ -595,7 +595,7 @@ def createPerson(base_dir: str, nickname: str, domain: str, port: int,
http_prefix: str, saveToFile: bool, http_prefix: str, saveToFile: bool,
manual_follower_approval: bool, manual_follower_approval: bool,
password: str, password: str,
groupAccount: bool = False) -> (str, str, {}, {}): group_account: bool = False) -> (str, str, {}, {}):
"""Returns the private key, public key, actor and webfinger endpoint """Returns the private key, public key, actor and webfinger endpoint
""" """
if not validNickname(domain, nickname): if not validNickname(domain, nickname):
@ -623,7 +623,7 @@ def createPerson(base_dir: str, nickname: str, domain: str, port: int,
http_prefix, http_prefix,
saveToFile, saveToFile,
manual_follower, manual_follower,
groupAccount, group_account,
password) password)
if not getConfigParam(base_dir, 'admin'): if not getConfigParam(base_dir, 'admin'):
if nickname != 'news': if nickname != 'news':
@ -1436,7 +1436,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
if debug: if debug:
print('getActorJson for ' + handle) print('getActorJson for ' + handle)
originalActor = handle originalActor = handle
groupAccount = False group_account = False
# try to determine the users path # try to determine the users path
detectedUsersPath = _detectUsersPath(handle) detectedUsersPath = _detectUsersPath(handle)
@ -1446,7 +1446,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
handle.startswith('hyper'): handle.startswith('hyper'):
groupPaths = getGroupPaths() groupPaths = getGroupPaths()
if detectedUsersPath in groupPaths: if detectedUsersPath in groupPaths:
groupAccount = True group_account = True
# format: https://domain/@nick # format: https://domain/@nick
originalHandle = handle originalHandle = handle
if not hasUsersPath(originalHandle): if not hasUsersPath(originalHandle):
@ -1488,7 +1488,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
elif handle.startswith('!'): elif handle.startswith('!'):
# handle for a group # handle for a group
handle = handle[1:] handle = handle[1:]
groupAccount = True group_account = True
if '@' not in handle: if '@' not in handle:
if not quiet: if not quiet:
print('getActorJsonSyntax: --actor nickname@domain') print('getActorJsonSyntax: --actor nickname@domain')
@ -1528,7 +1528,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
if debug: if debug:
print(originalActor + ' is an instance actor') print(originalActor + ' is an instance actor')
personUrl = originalActor personUrl = originalActor
elif '://' in originalActor and groupAccount: elif '://' in originalActor and group_account:
if debug: if debug:
print(originalActor + ' is a group actor') print(originalActor + ' is a group actor')
personUrl = originalActor personUrl = originalActor
@ -1537,7 +1537,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
wfRequest = webfingerHandle(session, handle, wfRequest = webfingerHandle(session, handle,
http_prefix, cached_webfingers, http_prefix, cached_webfingers,
hostDomain, __version__, debug, hostDomain, __version__, debug,
groupAccount, signing_priv_key_pem) group_account, signing_priv_key_pem)
if not wfRequest: if not wfRequest:
if not quiet: if not quiet:
print('getActorJson Unable to webfinger ' + handle) print('getActorJson Unable to webfinger ' + handle)
@ -1572,7 +1572,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
paths = getUserPaths() paths = getUserPaths()
for userPath in paths: for userPath in paths:
personUrl = personUrl.replace(userPath, '/actor/') personUrl = personUrl.replace(userPath, '/actor/')
if not personUrl and groupAccount: if not personUrl and group_account:
personUrl = http_prefix + '://' + domain + '/c/' + nickname personUrl = http_prefix + '://' + domain + '/c/' + nickname
if not personUrl: if not personUrl:
# try single user instance # try single user instance

View File

@ -2615,7 +2615,7 @@ def sendSignedJson(post_json_object: {}, session, base_dir: str,
federation_list: [], federation_list: [],
send_threads: [], postLog: [], cached_webfingers: {}, send_threads: [], postLog: [], cached_webfingers: {},
person_cache: {}, debug: bool, project_version: str, person_cache: {}, debug: bool, project_version: str,
sharedItemsToken: str, groupAccount: bool, sharedItemsToken: str, group_account: bool,
signing_priv_key_pem: str, signing_priv_key_pem: str,
sourceId: int) -> int: sourceId: int) -> int:
"""Sends a signed json object to an inbox/outbox """Sends a signed json object to an inbox/outbox
@ -2654,7 +2654,7 @@ def sendSignedJson(post_json_object: {}, session, base_dir: str,
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, http_prefix, wfRequest = webfingerHandle(session, handle, http_prefix,
cached_webfingers, cached_webfingers,
domain, project_version, debug, groupAccount, domain, project_version, debug, group_account,
signing_priv_key_pem) signing_priv_key_pem)
if not wfRequest: if not wfRequest:
if debug: if debug:
@ -2998,7 +2998,7 @@ def _sendToNamedAddresses(session, base_dir: str,
if sharedItemFederationTokens.get(fromDomainFull): if sharedItemFederationTokens.get(fromDomainFull):
sharedItemsToken = sharedItemFederationTokens[fromDomainFull] sharedItemsToken = sharedItemFederationTokens[fromDomainFull]
groupAccount = hasGroupType(base_dir, address, person_cache) group_account = hasGroupType(base_dir, address, person_cache)
sendSignedJson(post_json_object, session, base_dir, sendSignedJson(post_json_object, session, base_dir,
nickname, fromDomain, port, nickname, fromDomain, port,
@ -3007,7 +3007,7 @@ def _sendToNamedAddresses(session, base_dir: str,
federation_list, federation_list,
send_threads, postLog, cached_webfingers, send_threads, postLog, cached_webfingers,
person_cache, debug, project_version, person_cache, debug, project_version,
sharedItemsToken, groupAccount, sharedItemsToken, group_account,
signing_priv_key_pem, 34436782) signing_priv_key_pem, 34436782)
@ -3190,9 +3190,9 @@ def sendToFollowers(session, base_dir: str,
if withSharedInbox: if withSharedInbox:
toNickname = followerHandles[index].split('@')[0] toNickname = followerHandles[index].split('@')[0]
groupAccount = False group_account = False
if toNickname.startswith('!'): if toNickname.startswith('!'):
groupAccount = True group_account = True
toNickname = toNickname[1:] toNickname = toNickname[1:]
# if there are more than one followers on the domain # if there are more than one followers on the domain
@ -3217,7 +3217,7 @@ def sendToFollowers(session, base_dir: str,
federation_list, federation_list,
send_threads, postLog, cached_webfingers, send_threads, postLog, cached_webfingers,
person_cache, debug, project_version, person_cache, debug, project_version,
sharedItemsToken, groupAccount, sharedItemsToken, group_account,
signing_priv_key_pem, 639342) signing_priv_key_pem, 639342)
else: else:
# send to individual followers without using a shared inbox # send to individual followers without using a shared inbox
@ -3225,9 +3225,9 @@ def sendToFollowers(session, base_dir: str,
print('Sending post to followers ' + handle) print('Sending post to followers ' + handle)
toNickname = handle.split('@')[0] toNickname = handle.split('@')[0]
groupAccount = False group_account = False
if toNickname.startswith('!'): if toNickname.startswith('!'):
groupAccount = True group_account = True
toNickname = toNickname[1:] toNickname = toNickname[1:]
if post_json_object['type'] != 'Update': if post_json_object['type'] != 'Update':
@ -3246,7 +3246,7 @@ def sendToFollowers(session, base_dir: str,
federation_list, federation_list,
send_threads, postLog, cached_webfingers, send_threads, postLog, cached_webfingers,
person_cache, debug, project_version, person_cache, debug, project_version,
sharedItemsToken, groupAccount, sharedItemsToken, group_account,
signing_priv_key_pem, 634219) signing_priv_key_pem, 634219)
time.sleep(4) time.sleep(4)
@ -4082,16 +4082,16 @@ def getPublicPostsOfPerson(base_dir: str, nickname: str, domain: str,
person_cache = {} person_cache = {}
cached_webfingers = {} cached_webfingers = {}
federation_list = [] federation_list = []
groupAccount = False group_account = False
if nickname.startswith('!'): if nickname.startswith('!'):
nickname = nickname[1:] nickname = nickname[1:]
groupAccount = True group_account = True
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
handle = http_prefix + "://" + domainFull + "/@" + nickname handle = http_prefix + "://" + domainFull + "/@" + nickname
wfRequest = \ wfRequest = \
webfingerHandle(session, handle, http_prefix, cached_webfingers, webfingerHandle(session, handle, http_prefix, cached_webfingers,
originDomain, project_version, debug, groupAccount, originDomain, project_version, debug, group_account,
signing_priv_key_pem) signing_priv_key_pem)
if not wfRequest: if not wfRequest:
if debug: if debug:

View File

@ -99,12 +99,12 @@ def _reaction(recentPostsCache: {},
reactionPostNickname = None reactionPostNickname = None
reactionPostDomain = None reactionPostDomain = None
reactionPostPort = None reactionPostPort = None
groupAccount = False group_account = False
if actorReaction: if actorReaction:
reactionPostNickname = getNicknameFromActor(actorReaction) reactionPostNickname = getNicknameFromActor(actorReaction)
reactionPostDomain, reactionPostPort = \ reactionPostDomain, reactionPostPort = \
getDomainFromActor(actorReaction) getDomainFromActor(actorReaction)
groupAccount = hasGroupType(base_dir, actorReaction, person_cache) group_account = hasGroupType(base_dir, actorReaction, person_cache)
else: else:
if hasUsersPath(objectUrl): if hasUsersPath(objectUrl):
reactionPostNickname = getNicknameFromActor(objectUrl) reactionPostNickname = getNicknameFromActor(objectUrl)
@ -114,7 +114,7 @@ def _reaction(recentPostsCache: {},
actorReaction = \ actorReaction = \
objectUrl.split('/' + reactionPostNickname + '/')[0] + \ objectUrl.split('/' + reactionPostNickname + '/')[0] + \
'/' + reactionPostNickname '/' + reactionPostNickname
groupAccount = \ group_account = \
hasGroupType(base_dir, actorReaction, person_cache) hasGroupType(base_dir, actorReaction, person_cache)
if reactionPostNickname: if reactionPostNickname:
@ -139,7 +139,7 @@ def _reaction(recentPostsCache: {},
'https://www.w3.org/ns/activitystreams#Public', 'https://www.w3.org/ns/activitystreams#Public',
http_prefix, True, client_to_server, federation_list, http_prefix, True, client_to_server, federation_list,
send_threads, postLog, cached_webfingers, person_cache, send_threads, postLog, cached_webfingers, person_cache,
debug, project_version, None, groupAccount, debug, project_version, None, group_account,
signing_priv_key_pem, 7165392) signing_priv_key_pem, 7165392)
return newReactionJson return newReactionJson

View File

@ -1131,7 +1131,7 @@ def _setDefaultPetName(base_dir: str, nickname: str, domain: str,
def followPerson(base_dir: str, nickname: str, domain: str, def followPerson(base_dir: str, nickname: str, domain: str,
followNickname: str, followDomain: str, followNickname: str, followDomain: str,
federation_list: [], debug: bool, federation_list: [], debug: bool,
groupAccount: bool, group_account: bool,
followFile: str = 'following.txt') -> bool: followFile: str = 'following.txt') -> bool:
"""Adds a person to the follow list """Adds a person to the follow list
""" """
@ -1161,7 +1161,7 @@ def followPerson(base_dir: str, nickname: str, domain: str,
else: else:
handleToFollow = followNickname + '@' + followDomain handleToFollow = followNickname + '@' + followDomain
if groupAccount: if group_account:
handleToFollow = '!' + handleToFollow handleToFollow = '!' + handleToFollow
# was this person previously unfollowed? # was this person previously unfollowed?
@ -1181,7 +1181,7 @@ def followPerson(base_dir: str, nickname: str, domain: str,
if not os.path.isdir(base_dir + '/accounts'): if not os.path.isdir(base_dir + '/accounts'):
os.mkdir(base_dir + '/accounts') os.mkdir(base_dir + '/accounts')
handleToFollow = followNickname + '@' + followDomain handleToFollow = followNickname + '@' + followDomain
if groupAccount: if group_account:
handleToFollow = '!' + handleToFollow handleToFollow = '!' + handleToFollow
filename = base_dir + '/accounts/' + handle + '/' + followFile filename = base_dir + '/accounts/' + handle + '/' + followFile
if os.path.isfile(filename): if os.path.isfile(filename):

View File

@ -26,7 +26,7 @@ from utils import localActorUrl
def _parseHandle(handle: str) -> (str, str, bool): def _parseHandle(handle: str) -> (str, str, bool):
"""Parses a handle and returns nickname and domain """Parses a handle and returns nickname and domain
""" """
groupAccount = False group_account = False
if '.' not in handle: if '.' not in handle:
return None, None, False return None, None, False
prefixes = getProtocolPrefixes() prefixes = getProtocolPrefixes()
@ -43,9 +43,9 @@ def _parseHandle(handle: str) -> (str, str, bool):
if '@' in handle: if '@' in handle:
if handle.startswith('!'): if handle.startswith('!'):
handle = handle[1:] handle = handle[1:]
groupAccount = True group_account = True
nickname, domain = handle.split('@') nickname, domain = handle.split('@')
return nickname, domain, groupAccount return nickname, domain, group_account
# try for different /users/ paths # try for different /users/ paths
usersPaths = getUserPaths() usersPaths = getUserPaths()
@ -53,9 +53,9 @@ def _parseHandle(handle: str) -> (str, str, bool):
for possibleUsersPath in usersPaths: for possibleUsersPath in usersPaths:
if possibleUsersPath in handle: if possibleUsersPath in handle:
if possibleUsersPath in groupPaths: if possibleUsersPath in groupPaths:
groupAccount = True group_account = True
domain, nickname = handleStr.split(possibleUsersPath) domain, nickname = handleStr.split(possibleUsersPath)
return nickname, domain, groupAccount return nickname, domain, group_account
return None, None, False return None, None, False
@ -63,7 +63,7 @@ def _parseHandle(handle: str) -> (str, str, bool):
def webfingerHandle(session, handle: str, http_prefix: str, def webfingerHandle(session, handle: str, http_prefix: str,
cached_webfingers: {}, cached_webfingers: {},
fromDomain: str, project_version: str, fromDomain: str, project_version: str,
debug: bool, groupAccount: bool, debug: bool, group_account: bool,
signing_priv_key_pem: str) -> {}: signing_priv_key_pem: str) -> {}:
"""Gets webfinger result for the given ActivityPub handle """Gets webfinger result for the given ActivityPub handle
""" """
@ -132,7 +132,7 @@ def storeWebfingerEndpoint(nickname: str, domain: str, port: int,
def createWebfingerEndpoint(nickname: str, domain: str, port: int, def createWebfingerEndpoint(nickname: str, domain: str, port: int,
http_prefix: str, publicKeyPem: str, http_prefix: str, publicKeyPem: str,
groupAccount: bool) -> {}: group_account: bool) -> {}:
"""Creates a webfinger endpoint for a user """Creates a webfinger endpoint for a user
""" """
originalDomain = domain originalDomain = domain