Check for group account when sending posts

merge-requests/30/head
Bob Mottram 2021-07-31 14:19:45 +01:00
parent bd0e462544
commit f4e479c423
5 changed files with 67 additions and 14 deletions

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production"
__module_group__ = "ActivityPub"
from utils import hasGroupType
from utils import removeDomainPort
from utils import hasObjectDict
from utils import removeIdEnding
@ -159,9 +160,16 @@ def createAnnounce(session, baseDir: str, federationList: [],
announceNickname = None
announceDomain = None
announcePort = None
groupAccount = False
if hasUsersPath(objectUrl):
announceNickname = getNicknameFromActor(objectUrl)
announceDomain, announcePort = getDomainFromActor(objectUrl)
if '/' + str(announceNickname) + '/' in objectUrl:
announceActor = \
objectUrl.split('/' + announceNickname + '/')[0] + \
'/' + announceNickname
if hasGroupType(baseDir, announceActor, personCache):
groupAccount = True
if announceNickname and announceDomain:
sendSignedJson(newAnnounce, session, baseDir,
@ -169,7 +177,7 @@ def createAnnounce(session, baseDir: str, federationList: [],
announceNickname, announceDomain, announcePort, None,
httpPrefix, True, clientToServer, federationList,
sendThreads, postLog, cachedWebfingers, personCache,
debug, projectVersion, None)
debug, projectVersion, None, groupAccount)
return newAnnounce

View File

@ -862,13 +862,20 @@ def followedAccountAccepts(session, baseDir: str, httpPrefix: str,
except BaseException:
pass
groupAccount = False
if followJson:
if followJson.get('actor'):
if hasGroupType(baseDir, followJson['actor'], personCache):
groupAccount = True
return sendSignedJson(acceptJson, session, baseDir,
nicknameToFollow, domainToFollow, port,
nickname, domain, fromPort, '',
httpPrefix, True, clientToServer,
federationList,
sendThreads, postLog, cachedWebfingers,
personCache, debug, projectVersion, None)
personCache, debug, projectVersion, None,
groupAccount)
def followedAccountRejects(session, baseDir: str, httpPrefix: str,
@ -914,6 +921,9 @@ def followedAccountRejects(session, baseDir: str, httpPrefix: str,
nickname + '@' + domain + ' port ' + str(fromPort))
clientToServer = False
denyHandle = getFullDomain(nickname + '@' + domain, fromPort)
groupAccount = False
if hasGroupType(baseDir, personUrl, personCache):
groupAccount = True
# remove from the follow requests file
removeFromFollowRequests(baseDir, nicknameToFollow, domainToFollow,
denyHandle, debug)
@ -929,7 +939,8 @@ def followedAccountRejects(session, baseDir: str, httpPrefix: str,
httpPrefix, True, clientToServer,
federationList,
sendThreads, postLog, cachedWebfingers,
personCache, debug, projectVersion, None)
personCache, debug, projectVersion, None,
groupAccount)
def sendFollowRequest(session, baseDir: str,
@ -992,7 +1003,7 @@ def sendFollowRequest(session, baseDir: str,
httpPrefix, True, clientToServer,
federationList,
sendThreads, postLog, cachedWebfingers, personCache,
debug, projectVersion, None)
debug, projectVersion, None, groupAccount)
return newFollowJson

View File

@ -1950,6 +1950,10 @@ def _sendToGroupMembers(session, baseDir: str, handle: str, port: int,
for memberHandle in groupMembers:
if memberHandle != handle:
memberNickname = memberHandle.split('@')[0]
groupAccount = False
if memberNickname.startswith('!'):
memberNickname = memberNickname[1:]
groupAccount = True
memberDomain = memberHandle.split('@')[1]
memberPort = port
if ':' in memberDomain:
@ -1960,7 +1964,8 @@ def _sendToGroupMembers(session, baseDir: str, handle: str, port: int,
memberNickname, memberDomain, memberPort, cc,
httpPrefix, False, False, federationList,
sendThreads, postLog, cachedWebfingers,
personCache, debug, __version__, None)
personCache, debug, __version__, None,
groupAccount)
def _inboxUpdateCalendar(baseDir: str, handle: str,
@ -2093,6 +2098,10 @@ def _bounceDM(senderPostId: str, session, httpPrefix: str,
lastBounceMessage[0] = currTime
senderNickname = sendingHandle.split('@')[0]
groupAccount = False
if sendingHandle.startswith('!'):
sendingHandle = sendingHandle[1:]
groupAccount = True
senderDomain = sendingHandle.split('@')[1]
senderPort = port
if ':' in senderDomain:
@ -2138,7 +2147,7 @@ def _bounceDM(senderPostId: str, session, httpPrefix: str,
senderNickname, senderDomain, senderPort, cc,
httpPrefix, False, False, federationList,
sendThreads, postLog, cachedWebfingers,
personCache, debug, __version__, None)
personCache, debug, __version__, None, groupAccount)
return True

10
like.py
View File

@ -18,6 +18,7 @@ from utils import getDomainFromActor
from utils import locatePost
from utils import updateLikesCollection
from utils import undoLikesCollectionEntry
from utils import hasGroupType
from posts import sendSignedJson
from session import postJson
from webfinger import webfingerHandle
@ -85,13 +86,20 @@ def _like(recentPostsCache: {},
likedPostNickname = None
likedPostDomain = None
likedPostPort = None
groupAccount = False
if actorLiked:
likedPostNickname = getNicknameFromActor(actorLiked)
likedPostDomain, likedPostPort = getDomainFromActor(actorLiked)
groupAccount = hasGroupType(baseDir, actorLiked, personCache)
else:
if hasUsersPath(objectUrl):
likedPostNickname = getNicknameFromActor(objectUrl)
likedPostDomain, likedPostPort = getDomainFromActor(objectUrl)
if '/' + str(likedPostNickname) + '/' in objectUrl:
actorLiked = \
objectUrl.split('/' + likedPostNickname + '/')[0] + \
'/' + likedPostNickname
groupAccount = hasGroupType(baseDir, actorLiked, personCache)
if likedPostNickname:
postFilename = locatePost(baseDir, nickname, domain, objectUrl)
@ -113,7 +121,7 @@ def _like(recentPostsCache: {},
'https://www.w3.org/ns/activitystreams#Public',
httpPrefix, True, clientToServer, federationList,
sendThreads, postLog, cachedWebfingers, personCache,
debug, projectVersion, None)
debug, projectVersion, None, groupAccount)
return newLikeJson

View File

@ -32,6 +32,7 @@ from webfinger import webfingerHandle
from httpsig import createSignedHeader
from siteactive import siteIsActive
from languages import understoodPostLanguage
from utils import hasGroupType
from utils import getBaseContentFromPost
from utils import removeDomainPort
from utils import getPortFromDomain
@ -1912,8 +1913,12 @@ def threadSendPost(session, postJsonStr: str, federationList: [],
if debug:
# save the log file
postLogFilename = baseDir + '/post.log'
with open(postLogFilename, 'a+') as logFile:
logFile.write(logStr + '\n')
if os.path.isfile(postLogFilename):
with open(postLogFilename, 'a+') as logFile:
logFile.write(logStr + '\n')
else:
with open(postLogFilename, 'w+') as logFile:
logFile.write(logStr + '\n')
if postResult:
if debug:
@ -2239,7 +2244,7 @@ def sendSignedJson(postJsonObject: {}, session, baseDir: str,
federationList: [],
sendThreads: [], postLog: [], cachedWebfingers: {},
personCache: {}, debug: bool, projectVersion: str,
sharedItemsToken: str) -> int:
sharedItemsToken: str, groupAccount: bool) -> int:
"""Sends a signed json object to an inbox/outbox
"""
if debug:
@ -2275,7 +2280,7 @@ def sendSignedJson(postJsonObject: {}, session, baseDir: str,
# lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
domain, projectVersion, debug, False)
domain, projectVersion, debug, groupAccount)
if not wfRequest:
if debug:
print('DEBUG: webfinger for ' + handle + ' failed')
@ -2603,6 +2608,8 @@ def sendToNamedAddresses(session, baseDir: str,
if sharedItemFederationTokens.get(fromDomain):
sharedItemsToken = sharedItemFederationTokens[fromDomain]
groupAccount = hasGroupType(baseDir, address, personCache)
sendSignedJson(postJsonObject, session, baseDir,
nickname, fromDomain, port,
toNickname, toDomain, toPort,
@ -2610,7 +2617,7 @@ def sendToNamedAddresses(session, baseDir: str,
federationList,
sendThreads, postLog, cachedWebfingers,
personCache, debug, projectVersion,
sharedItemsToken)
sharedItemsToken, groupAccount)
def _hasSharedInbox(session, httpPrefix: str, domain: str,
@ -2751,6 +2758,11 @@ def sendToFollowers(session, baseDir: str,
if withSharedInbox:
toNickname = followerHandles[index].split('@')[0]
groupAccount = False
if toNickname.startswith('!'):
groupAccount = True
toNickname = toNickname[1:]
# if there are more than one followers on the domain
# then send the post to the shared inbox
if len(followerHandles) > 1:
@ -2773,13 +2785,18 @@ def sendToFollowers(session, baseDir: str,
federationList,
sendThreads, postLog, cachedWebfingers,
personCache, debug, projectVersion,
sharedItemsToken)
sharedItemsToken, groupAccount)
else:
# send to individual followers without using a shared inbox
for handle in followerHandles:
print('Sending post to followers ' + handle)
toNickname = handle.split('@')[0]
groupAccount = False
if toNickname.startswith('!'):
groupAccount = True
toNickname = toNickname[1:]
if postJsonObject['type'] != 'Update':
print('Sending post to followers from ' +
nickname + '@' + domain + ' to ' +
@ -2796,7 +2813,7 @@ def sendToFollowers(session, baseDir: str,
federationList,
sendThreads, postLog, cachedWebfingers,
personCache, debug, projectVersion,
sharedItemsToken)
sharedItemsToken, groupAccount)
time.sleep(4)