forked from indymedia/epicyon
Move functions
parent
8dd64c187f
commit
032b168d03
166
blocking.py
166
blocking.py
|
@ -14,7 +14,6 @@ from utils import getDomainFromActor
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from session import postJson
|
from session import postJson
|
||||||
from auth import createBasicAuthHeader
|
from auth import createBasicAuthHeader
|
||||||
from posts import getPersonBox
|
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
|
|
||||||
|
|
||||||
|
@ -190,171 +189,6 @@ def isBlocked(baseDir: str, nickname: str, domain: str,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def sendBlockViaServer(baseDir: str, session,
|
|
||||||
fromNickname: str, password: str,
|
|
||||||
fromDomain: str, fromPort: int,
|
|
||||||
httpPrefix: str, blockedUrl: str,
|
|
||||||
cachedWebfingers: {}, personCache: {},
|
|
||||||
debug: bool, projectVersion: str) -> {}:
|
|
||||||
"""Creates a block via c2s
|
|
||||||
"""
|
|
||||||
if not session:
|
|
||||||
print('WARN: No session for sendBlockViaServer')
|
|
||||||
return 6
|
|
||||||
|
|
||||||
fromDomainFull = fromDomain
|
|
||||||
if fromPort:
|
|
||||||
if fromPort != 80 and fromPort != 443:
|
|
||||||
if ':' not in fromDomain:
|
|
||||||
fromDomainFull = fromDomain + ':' + str(fromPort)
|
|
||||||
|
|
||||||
toUrl = 'https://www.w3.org/ns/activitystreams#Public'
|
|
||||||
ccUrl = httpPrefix + '://' + fromDomainFull + '/users/' + \
|
|
||||||
fromNickname + '/followers'
|
|
||||||
|
|
||||||
blockActor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname
|
|
||||||
newBlockJson = {
|
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
|
||||||
'type': 'Block',
|
|
||||||
'actor': blockActor,
|
|
||||||
'object': blockedUrl,
|
|
||||||
'to': [toUrl],
|
|
||||||
'cc': [ccUrl]
|
|
||||||
}
|
|
||||||
|
|
||||||
handle = httpPrefix + '://' + fromDomainFull + '/@' + fromNickname
|
|
||||||
|
|
||||||
# lookup the inbox for the To handle
|
|
||||||
wfRequest = webfingerHandle(session, handle, httpPrefix,
|
|
||||||
cachedWebfingers,
|
|
||||||
fromDomain, projectVersion)
|
|
||||||
if not wfRequest:
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: announce webfinger failed for ' + handle)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
postToBox = 'outbox'
|
|
||||||
|
|
||||||
# get the actor inbox for the To handle
|
|
||||||
(inboxUrl, pubKeyId, pubKey,
|
|
||||||
fromPersonId, sharedInbox,
|
|
||||||
capabilityAcquisition, avatarUrl,
|
|
||||||
displayName) = getPersonBox(baseDir, session, wfRequest,
|
|
||||||
personCache,
|
|
||||||
projectVersion, httpPrefix, fromNickname,
|
|
||||||
fromDomain, postToBox)
|
|
||||||
|
|
||||||
if not inboxUrl:
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: No ' + postToBox + ' was found for ' + handle)
|
|
||||||
return 3
|
|
||||||
if not fromPersonId:
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: No actor was found for ' + handle)
|
|
||||||
return 4
|
|
||||||
|
|
||||||
authHeader = createBasicAuthHeader(fromNickname, password)
|
|
||||||
|
|
||||||
headers = {
|
|
||||||
'host': fromDomain,
|
|
||||||
'Content-type': 'application/json',
|
|
||||||
'Authorization': authHeader
|
|
||||||
}
|
|
||||||
postResult = postJson(session, newBlockJson, [], inboxUrl,
|
|
||||||
headers, "inbox:write")
|
|
||||||
if not postResult:
|
|
||||||
print('WARN: Unable to post block')
|
|
||||||
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: c2s POST block success')
|
|
||||||
|
|
||||||
return newBlockJson
|
|
||||||
|
|
||||||
|
|
||||||
def sendUndoBlockViaServer(baseDir: str, session,
|
|
||||||
fromNickname: str, password: str,
|
|
||||||
fromDomain: str, fromPort: int,
|
|
||||||
httpPrefix: str, blockedUrl: str,
|
|
||||||
cachedWebfingers: {}, personCache: {},
|
|
||||||
debug: bool, projectVersion: str) -> {}:
|
|
||||||
"""Creates a block via c2s
|
|
||||||
"""
|
|
||||||
if not session:
|
|
||||||
print('WARN: No session for sendBlockViaServer')
|
|
||||||
return 6
|
|
||||||
|
|
||||||
fromDomainFull = fromDomain
|
|
||||||
if fromPort:
|
|
||||||
if fromPort != 80 and fromPort != 443:
|
|
||||||
if ':' not in fromDomain:
|
|
||||||
fromDomainFull = fromDomain + ':' + str(fromPort)
|
|
||||||
|
|
||||||
toUrl = 'https://www.w3.org/ns/activitystreams#Public'
|
|
||||||
ccUrl = httpPrefix + '://' + fromDomainFull + '/users/' + \
|
|
||||||
fromNickname + '/followers'
|
|
||||||
|
|
||||||
blockActor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname
|
|
||||||
newBlockJson = {
|
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
|
||||||
'type': 'Undo',
|
|
||||||
'actor': blockActor,
|
|
||||||
'object': {
|
|
||||||
'type': 'Block',
|
|
||||||
'actor': blockActor,
|
|
||||||
'object': blockedUrl,
|
|
||||||
'to': [toUrl],
|
|
||||||
'cc': [ccUrl]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handle = httpPrefix + '://' + fromDomainFull + '/@' + fromNickname
|
|
||||||
|
|
||||||
# lookup the inbox for the To handle
|
|
||||||
wfRequest = webfingerHandle(session, handle, httpPrefix,
|
|
||||||
cachedWebfingers,
|
|
||||||
fromDomain, projectVersion)
|
|
||||||
if not wfRequest:
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: announce webfinger failed for ' + handle)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
postToBox = 'outbox'
|
|
||||||
|
|
||||||
# get the actor inbox for the To handle
|
|
||||||
(inboxUrl, pubKeyId, pubKey,
|
|
||||||
fromPersonId, sharedInbox,
|
|
||||||
capabilityAcquisition, avatarUrl,
|
|
||||||
displayName) = getPersonBox(baseDir, session, wfRequest, personCache,
|
|
||||||
projectVersion, httpPrefix, fromNickname,
|
|
||||||
fromDomain, postToBox)
|
|
||||||
|
|
||||||
if not inboxUrl:
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: No ' + postToBox + ' was found for ' + handle)
|
|
||||||
return 3
|
|
||||||
if not fromPersonId:
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: No actor was found for ' + handle)
|
|
||||||
return 4
|
|
||||||
|
|
||||||
authHeader = createBasicAuthHeader(fromNickname, password)
|
|
||||||
|
|
||||||
headers = {
|
|
||||||
'host': fromDomain,
|
|
||||||
'Content-type': 'application/json',
|
|
||||||
'Authorization': authHeader
|
|
||||||
}
|
|
||||||
postResult = postJson(session, newBlockJson, [], inboxUrl,
|
|
||||||
headers, "inbox:write")
|
|
||||||
if not postResult:
|
|
||||||
print('WARN: Unable to post block')
|
|
||||||
|
|
||||||
if debug:
|
|
||||||
print('DEBUG: c2s POST block success')
|
|
||||||
|
|
||||||
return newBlockJson
|
|
||||||
|
|
||||||
|
|
||||||
def outboxBlock(baseDir: str, httpPrefix: str,
|
def outboxBlock(baseDir: str, httpPrefix: str,
|
||||||
nickname: str, domain: str, port: int,
|
nickname: str, domain: str, port: int,
|
||||||
messageJson: {}, debug: bool) -> None:
|
messageJson: {}, debug: bool) -> None:
|
||||||
|
|
|
@ -20,6 +20,8 @@ from skills import setSkillLevel
|
||||||
from roles import setRole
|
from roles import setRole
|
||||||
from person import setOrganizationScheme
|
from person import setOrganizationScheme
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
|
from posts import sendBlockViaServer
|
||||||
|
from posts import sendUndoBlockViaServer
|
||||||
from posts import getPosts
|
from posts import getPosts
|
||||||
from posts import createPublicPost
|
from posts import createPublicPost
|
||||||
from posts import deleteAllPosts
|
from posts import deleteAllPosts
|
||||||
|
@ -69,8 +71,6 @@ from media import getAttachmentMediaType
|
||||||
from delete import sendDeleteViaServer
|
from delete import sendDeleteViaServer
|
||||||
from like import sendLikeViaServer
|
from like import sendLikeViaServer
|
||||||
from like import sendUndoLikeViaServer
|
from like import sendUndoLikeViaServer
|
||||||
from blocking import sendBlockViaServer
|
|
||||||
from blocking import sendUndoBlockViaServer
|
|
||||||
from roles import sendRoleViaServer
|
from roles import sendRoleViaServer
|
||||||
from skills import sendSkillViaServer
|
from skills import sendSkillViaServer
|
||||||
from availability import setAvailability
|
from availability import setAvailability
|
||||||
|
|
165
posts.py
165
posts.py
|
@ -2972,3 +2972,168 @@ def unmutePost(baseDir: str,nickname: str,domain: str,postId: str, \
|
||||||
if os.path.isfile(cachedPostFilename):
|
if os.path.isfile(cachedPostFilename):
|
||||||
os.remove(cachedPostFilename)
|
os.remove(cachedPostFilename)
|
||||||
removePostFromCache(postJsonObject,recentPostsCache)
|
removePostFromCache(postJsonObject,recentPostsCache)
|
||||||
|
|
||||||
|
|
||||||
|
def sendBlockViaServer(baseDir: str, session,
|
||||||
|
fromNickname: str, password: str,
|
||||||
|
fromDomain: str, fromPort: int,
|
||||||
|
httpPrefix: str, blockedUrl: str,
|
||||||
|
cachedWebfingers: {}, personCache: {},
|
||||||
|
debug: bool, projectVersion: str) -> {}:
|
||||||
|
"""Creates a block via c2s
|
||||||
|
"""
|
||||||
|
if not session:
|
||||||
|
print('WARN: No session for sendBlockViaServer')
|
||||||
|
return 6
|
||||||
|
|
||||||
|
fromDomainFull = fromDomain
|
||||||
|
if fromPort:
|
||||||
|
if fromPort != 80 and fromPort != 443:
|
||||||
|
if ':' not in fromDomain:
|
||||||
|
fromDomainFull = fromDomain + ':' + str(fromPort)
|
||||||
|
|
||||||
|
toUrl = 'https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
ccUrl = httpPrefix + '://' + fromDomainFull + '/users/' + \
|
||||||
|
fromNickname + '/followers'
|
||||||
|
|
||||||
|
blockActor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname
|
||||||
|
newBlockJson = {
|
||||||
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
|
'type': 'Block',
|
||||||
|
'actor': blockActor,
|
||||||
|
'object': blockedUrl,
|
||||||
|
'to': [toUrl],
|
||||||
|
'cc': [ccUrl]
|
||||||
|
}
|
||||||
|
|
||||||
|
handle = httpPrefix + '://' + fromDomainFull + '/@' + fromNickname
|
||||||
|
|
||||||
|
# lookup the inbox for the To handle
|
||||||
|
wfRequest = webfingerHandle(session, handle, httpPrefix,
|
||||||
|
cachedWebfingers,
|
||||||
|
fromDomain, projectVersion)
|
||||||
|
if not wfRequest:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: announce webfinger failed for ' + handle)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
postToBox = 'outbox'
|
||||||
|
|
||||||
|
# get the actor inbox for the To handle
|
||||||
|
(inboxUrl, pubKeyId, pubKey,
|
||||||
|
fromPersonId, sharedInbox,
|
||||||
|
capabilityAcquisition, avatarUrl,
|
||||||
|
displayName) = getPersonBox(baseDir, session, wfRequest,
|
||||||
|
personCache,
|
||||||
|
projectVersion, httpPrefix, fromNickname,
|
||||||
|
fromDomain, postToBox)
|
||||||
|
|
||||||
|
if not inboxUrl:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: No ' + postToBox + ' was found for ' + handle)
|
||||||
|
return 3
|
||||||
|
if not fromPersonId:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: No actor was found for ' + handle)
|
||||||
|
return 4
|
||||||
|
|
||||||
|
authHeader = createBasicAuthHeader(fromNickname, password)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'host': fromDomain,
|
||||||
|
'Content-type': 'application/json',
|
||||||
|
'Authorization': authHeader
|
||||||
|
}
|
||||||
|
postResult = postJson(session, newBlockJson, [], inboxUrl,
|
||||||
|
headers, "inbox:write")
|
||||||
|
if not postResult:
|
||||||
|
print('WARN: Unable to post block')
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: c2s POST block success')
|
||||||
|
|
||||||
|
return newBlockJson
|
||||||
|
|
||||||
|
|
||||||
|
def sendUndoBlockViaServer(baseDir: str, session,
|
||||||
|
fromNickname: str, password: str,
|
||||||
|
fromDomain: str, fromPort: int,
|
||||||
|
httpPrefix: str, blockedUrl: str,
|
||||||
|
cachedWebfingers: {}, personCache: {},
|
||||||
|
debug: bool, projectVersion: str) -> {}:
|
||||||
|
"""Creates a block via c2s
|
||||||
|
"""
|
||||||
|
if not session:
|
||||||
|
print('WARN: No session for sendBlockViaServer')
|
||||||
|
return 6
|
||||||
|
|
||||||
|
fromDomainFull = fromDomain
|
||||||
|
if fromPort:
|
||||||
|
if fromPort != 80 and fromPort != 443:
|
||||||
|
if ':' not in fromDomain:
|
||||||
|
fromDomainFull = fromDomain + ':' + str(fromPort)
|
||||||
|
|
||||||
|
toUrl = 'https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
ccUrl = httpPrefix + '://' + fromDomainFull + '/users/' + \
|
||||||
|
fromNickname + '/followers'
|
||||||
|
|
||||||
|
blockActor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname
|
||||||
|
newBlockJson = {
|
||||||
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
|
'type': 'Undo',
|
||||||
|
'actor': blockActor,
|
||||||
|
'object': {
|
||||||
|
'type': 'Block',
|
||||||
|
'actor': blockActor,
|
||||||
|
'object': blockedUrl,
|
||||||
|
'to': [toUrl],
|
||||||
|
'cc': [ccUrl]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle = httpPrefix + '://' + fromDomainFull + '/@' + fromNickname
|
||||||
|
|
||||||
|
# lookup the inbox for the To handle
|
||||||
|
wfRequest = webfingerHandle(session, handle, httpPrefix,
|
||||||
|
cachedWebfingers,
|
||||||
|
fromDomain, projectVersion)
|
||||||
|
if not wfRequest:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: announce webfinger failed for ' + handle)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
postToBox = 'outbox'
|
||||||
|
|
||||||
|
# get the actor inbox for the To handle
|
||||||
|
(inboxUrl, pubKeyId, pubKey,
|
||||||
|
fromPersonId, sharedInbox,
|
||||||
|
capabilityAcquisition, avatarUrl,
|
||||||
|
displayName) = getPersonBox(baseDir, session, wfRequest, personCache,
|
||||||
|
projectVersion, httpPrefix, fromNickname,
|
||||||
|
fromDomain, postToBox)
|
||||||
|
|
||||||
|
if not inboxUrl:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: No ' + postToBox + ' was found for ' + handle)
|
||||||
|
return 3
|
||||||
|
if not fromPersonId:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: No actor was found for ' + handle)
|
||||||
|
return 4
|
||||||
|
|
||||||
|
authHeader = createBasicAuthHeader(fromNickname, password)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'host': fromDomain,
|
||||||
|
'Content-type': 'application/json',
|
||||||
|
'Authorization': authHeader
|
||||||
|
}
|
||||||
|
postResult = postJson(session, newBlockJson, [], inboxUrl,
|
||||||
|
headers, "inbox:write")
|
||||||
|
if not postResult:
|
||||||
|
print('WARN: Unable to post block')
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: c2s POST block success')
|
||||||
|
|
||||||
|
return newBlockJson
|
||||||
|
|
Loading…
Reference in New Issue