mirror of https://gitlab.com/bashrc2/epicyon
Undoing announces via c2s
parent
3795cb4ce4
commit
e65ad80d59
79
announce.py
79
announce.py
|
@ -266,3 +266,82 @@ def sendAnnounceViaServer(baseDir: str, session,
|
||||||
print('DEBUG: c2s POST announce success')
|
print('DEBUG: c2s POST announce success')
|
||||||
|
|
||||||
return newAnnounceJson
|
return newAnnounceJson
|
||||||
|
|
||||||
|
|
||||||
|
def sendUndoAnnounceViaServer(baseDir: str, session,
|
||||||
|
undoPostJsonObject: {},
|
||||||
|
nickname: str, password: str,
|
||||||
|
domain: str, port: int,
|
||||||
|
httpPrefix: str, repeatObjectUrl: str,
|
||||||
|
cachedWebfingers: {}, personCache: {},
|
||||||
|
debug: bool, projectVersion: str) -> {}:
|
||||||
|
"""Undo an announce message via c2s
|
||||||
|
"""
|
||||||
|
if not session:
|
||||||
|
print('WARN: No session for sendUndoAnnounceViaServer')
|
||||||
|
return 6
|
||||||
|
|
||||||
|
domainFull = getFullDomain(domain, port)
|
||||||
|
|
||||||
|
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||||
|
handle = actor.replace('/users/', '/@')
|
||||||
|
|
||||||
|
statusNumber, published = getStatusNumber()
|
||||||
|
unAnnounceJson = {
|
||||||
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
'id': actor + '/statuses/' + str(statusNumber) + '/undo',
|
||||||
|
'type': 'Undo',
|
||||||
|
'actor': actor,
|
||||||
|
'object': undoPostJsonObject['object']
|
||||||
|
}
|
||||||
|
|
||||||
|
# lookup the inbox for the To handle
|
||||||
|
wfRequest = webfingerHandle(session, handle, httpPrefix,
|
||||||
|
cachedWebfingers,
|
||||||
|
domain, projectVersion, debug)
|
||||||
|
if not wfRequest:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: undo announce webfinger failed for ' + handle)
|
||||||
|
return 1
|
||||||
|
if not isinstance(wfRequest, dict):
|
||||||
|
print('WARN: undo announce webfinger for ' + handle +
|
||||||
|
' did not return a dict. ' + str(wfRequest))
|
||||||
|
return 1
|
||||||
|
|
||||||
|
postToBox = 'outbox'
|
||||||
|
|
||||||
|
# get the actor inbox for the To handle
|
||||||
|
(inboxUrl, pubKeyId, pubKey, fromPersonId,
|
||||||
|
sharedInbox, avatarUrl,
|
||||||
|
displayName) = getPersonBox(baseDir, session, wfRequest,
|
||||||
|
personCache,
|
||||||
|
projectVersion, httpPrefix,
|
||||||
|
nickname, domain,
|
||||||
|
postToBox, 73528)
|
||||||
|
|
||||||
|
if not inboxUrl:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: undo announce no ' + postToBox +
|
||||||
|
' was found for ' + handle)
|
||||||
|
return 3
|
||||||
|
if not fromPersonId:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: undo announce no actor was found for ' + handle)
|
||||||
|
return 4
|
||||||
|
|
||||||
|
authHeader = createBasicAuthHeader(nickname, password)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'host': domain,
|
||||||
|
'Content-type': 'application/json',
|
||||||
|
'Authorization': authHeader
|
||||||
|
}
|
||||||
|
postResult = postJson(session, unAnnounceJson, [], inboxUrl,
|
||||||
|
headers, 30, True)
|
||||||
|
if not postResult:
|
||||||
|
print('WARN: undo announce not posted')
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: c2s POST undo announce success')
|
||||||
|
|
||||||
|
return unAnnounceJson
|
||||||
|
|
|
@ -32,6 +32,7 @@ from follow import sendUnfollowRequestViaServer
|
||||||
from posts import sendPostViaServer
|
from posts import sendPostViaServer
|
||||||
from posts import c2sBoxJson
|
from posts import c2sBoxJson
|
||||||
from announce import sendAnnounceViaServer
|
from announce import sendAnnounceViaServer
|
||||||
|
from announce import sendUndoAnnounceViaServer
|
||||||
from pgp import pgpDecrypt
|
from pgp import pgpDecrypt
|
||||||
from pgp import hasLocalPGPkey
|
from pgp import hasLocalPGPkey
|
||||||
from pgp import pgpEncryptToActor
|
from pgp import pgpEncryptToActor
|
||||||
|
@ -994,7 +995,15 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str,
|
||||||
screenreader, systemLanguage,
|
screenreader, systemLanguage,
|
||||||
espeak)
|
espeak)
|
||||||
print('')
|
print('')
|
||||||
elif commandStr == 'like':
|
elif commandStr == 'like' or commandStr.startswith('like '):
|
||||||
|
currIndex = 0
|
||||||
|
if ' ' in commandStr:
|
||||||
|
postIndex = commandStr.split(' ')[-1].strip()
|
||||||
|
if postIndex.isdigit():
|
||||||
|
currIndex = int(postIndex)
|
||||||
|
if currIndex > 0 and boxJson:
|
||||||
|
postJsonObject = \
|
||||||
|
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||||
if postJsonObject:
|
if postJsonObject:
|
||||||
if postJsonObject.get('id'):
|
if postJsonObject.get('id'):
|
||||||
likeActor = postJsonObject['object']['attributedTo']
|
likeActor = postJsonObject['object']['attributedTo']
|
||||||
|
@ -1012,6 +1021,14 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str,
|
||||||
False, __version__)
|
False, __version__)
|
||||||
print('')
|
print('')
|
||||||
elif commandStr == 'unlike' or commandStr == 'undo like':
|
elif commandStr == 'unlike' or commandStr == 'undo like':
|
||||||
|
currIndex = 0
|
||||||
|
if ' ' in commandStr:
|
||||||
|
postIndex = commandStr.split(' ')[-1].strip()
|
||||||
|
if postIndex.isdigit():
|
||||||
|
currIndex = int(postIndex)
|
||||||
|
if currIndex > 0 and boxJson:
|
||||||
|
postJsonObject = \
|
||||||
|
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||||
if postJsonObject:
|
if postJsonObject:
|
||||||
if postJsonObject.get('id'):
|
if postJsonObject.get('id'):
|
||||||
unlikeActor = postJsonObject['object']['attributedTo']
|
unlikeActor = postJsonObject['object']['attributedTo']
|
||||||
|
@ -1029,9 +1046,17 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str,
|
||||||
cachedWebfingers, personCache,
|
cachedWebfingers, personCache,
|
||||||
False, __version__)
|
False, __version__)
|
||||||
print('')
|
print('')
|
||||||
elif (commandStr == 'announce' or
|
elif (commandStr.startswith('announce') or
|
||||||
commandStr == 'boost' or
|
commandStr.startswith('boost') or
|
||||||
commandStr == 'retweet'):
|
commandStr.startswith('retweet')):
|
||||||
|
currIndex = 0
|
||||||
|
if ' ' in commandStr:
|
||||||
|
postIndex = commandStr.split(' ')[-1].strip()
|
||||||
|
if postIndex.isdigit():
|
||||||
|
currIndex = int(postIndex)
|
||||||
|
if currIndex > 0 and boxJson:
|
||||||
|
postJsonObject = \
|
||||||
|
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||||
if postJsonObject:
|
if postJsonObject:
|
||||||
if postJsonObject.get('id'):
|
if postJsonObject.get('id'):
|
||||||
postId = postJsonObject['id']
|
postId = postJsonObject['id']
|
||||||
|
@ -1050,6 +1075,39 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str,
|
||||||
cachedWebfingers, personCache,
|
cachedWebfingers, personCache,
|
||||||
True, __version__)
|
True, __version__)
|
||||||
print('')
|
print('')
|
||||||
|
elif (commandStr.startswith('unannounce') or
|
||||||
|
commandStr.startswith('undo announce') or
|
||||||
|
commandStr.startswith('unboost') or
|
||||||
|
commandStr.startswith('undo boost') or
|
||||||
|
commandStr.startswith('undo retweet')):
|
||||||
|
currIndex = 0
|
||||||
|
if ' ' in commandStr:
|
||||||
|
postIndex = commandStr.split(' ')[-1].strip()
|
||||||
|
if postIndex.isdigit():
|
||||||
|
currIndex = int(postIndex)
|
||||||
|
if currIndex > 0 and boxJson:
|
||||||
|
postJsonObject = \
|
||||||
|
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||||
|
if postJsonObject:
|
||||||
|
if postJsonObject.get('id'):
|
||||||
|
postId = postJsonObject['id']
|
||||||
|
announceActor = \
|
||||||
|
postJsonObject['object']['attributedTo']
|
||||||
|
sayStr = 'Undoing announce post by ' + \
|
||||||
|
getNicknameFromActor(announceActor)
|
||||||
|
_sayCommand(sayStr, sayStr,
|
||||||
|
screenreader,
|
||||||
|
systemLanguage, espeak)
|
||||||
|
sessionAnnounce = createSession(proxyType)
|
||||||
|
sendUndoAnnounceViaServer(baseDir, sessionAnnounce,
|
||||||
|
postJsonObject,
|
||||||
|
nickname, password,
|
||||||
|
domain, port,
|
||||||
|
httpPrefix, postId,
|
||||||
|
cachedWebfingers,
|
||||||
|
personCache,
|
||||||
|
True, __version__)
|
||||||
|
print('')
|
||||||
elif commandStr.startswith('follow '):
|
elif commandStr.startswith('follow '):
|
||||||
followHandle = commandStr.replace('follow ', '').strip()
|
followHandle = commandStr.replace('follow ', '').strip()
|
||||||
if followHandle.startswith('@'):
|
if followHandle.startswith('@'):
|
||||||
|
|
Loading…
Reference in New Issue