mirror of https://gitlab.com/bashrc2/epicyon
Undo bookmark request via c2s
parent
f4c4e240a5
commit
6f196d5fc3
82
bookmarks.py
82
bookmarks.py
|
@ -535,3 +535,85 @@ def sendBookmarkViaServer(baseDir: str, session,
|
|||
print('DEBUG: c2s POST bookmark success')
|
||||
|
||||
return newBookmarkJson
|
||||
|
||||
|
||||
def sendUndoBookmarkViaServer(baseDir: str, session,
|
||||
nickname: str, password: str,
|
||||
domain: str, fromPort: int,
|
||||
httpPrefix: str, bookmarkUrl: str,
|
||||
cachedWebfingers: {}, personCache: {},
|
||||
debug: bool, projectVersion: str) -> {}:
|
||||
"""Removes a bookmark via c2s
|
||||
"""
|
||||
if not session:
|
||||
print('WARN: No session for sendUndoBookmarkViaServer')
|
||||
return 6
|
||||
|
||||
domainFull = getFullDomain(domain, fromPort)
|
||||
|
||||
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||
|
||||
newBookmarkJson = {
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"type": "Remove",
|
||||
"actor": actor,
|
||||
"object": {
|
||||
"type": "Document",
|
||||
"url": bookmarkUrl
|
||||
},
|
||||
"target": actor + "/tlbookmarks"
|
||||
}
|
||||
|
||||
handle = httpPrefix + '://' + domainFull + '/@' + nickname
|
||||
|
||||
# lookup the inbox for the To handle
|
||||
wfRequest = webfingerHandle(session, handle, httpPrefix,
|
||||
cachedWebfingers,
|
||||
domain, projectVersion, debug)
|
||||
if not wfRequest:
|
||||
if debug:
|
||||
print('DEBUG: unbookmark webfinger failed for ' + handle)
|
||||
return 1
|
||||
if not isinstance(wfRequest, dict):
|
||||
print('WARN: unbookmark 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, 52594)
|
||||
|
||||
if not inboxUrl:
|
||||
if debug:
|
||||
print('DEBUG: unbookmark no ' + postToBox +
|
||||
' was found for ' + handle)
|
||||
return 3
|
||||
if not fromPersonId:
|
||||
if debug:
|
||||
print('DEBUG: unbookmark no actor was found for ' + handle)
|
||||
return 4
|
||||
|
||||
authHeader = createBasicAuthHeader(nickname, password)
|
||||
|
||||
headers = {
|
||||
'host': domain,
|
||||
'Content-type': 'application/json',
|
||||
'Authorization': authHeader
|
||||
}
|
||||
postResult = postJson(session, newBookmarkJson, [], inboxUrl,
|
||||
headers, 30, True)
|
||||
if not postResult:
|
||||
if debug:
|
||||
print('WARN: POST unbookmark failed for c2s to ' + inboxUrl)
|
||||
return 5
|
||||
|
||||
if debug:
|
||||
print('DEBUG: c2s POST unbookmark success')
|
||||
|
||||
return newBookmarkJson
|
||||
|
|
|
@ -40,6 +40,7 @@ from pgp import pgpEncryptToActor
|
|||
from pgp import pgpPublicKeyUpload
|
||||
from like import noOfLikes
|
||||
from bookmarks import sendBookmarkViaServer
|
||||
from bookmarks import sendUndoBookmarkViaServer
|
||||
|
||||
|
||||
def _desktopHelp() -> None:
|
||||
|
@ -1207,6 +1208,37 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str,
|
|||
cachedWebfingers, personCache,
|
||||
False, __version__)
|
||||
print('')
|
||||
elif (commandStr == 'undo bookmark' or
|
||||
commandStr == 'undo bm' or
|
||||
commandStr == 'unbookmark' or
|
||||
commandStr == 'unbm' or
|
||||
commandStr.startswith('unbookmark ') or
|
||||
commandStr.startswith('unbm ')):
|
||||
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'):
|
||||
likeActor = postJsonObject['object']['attributedTo']
|
||||
sayStr = 'Unbookmarking post by ' + \
|
||||
getNicknameFromActor(likeActor)
|
||||
_sayCommand(sayStr, sayStr,
|
||||
screenreader,
|
||||
systemLanguage, espeak)
|
||||
sessionLike = createSession(proxyType)
|
||||
sendUndoBookmarkViaServer(baseDir, sessionLike,
|
||||
nickname, password,
|
||||
domain, port, httpPrefix,
|
||||
postJsonObject['id'],
|
||||
cachedWebfingers,
|
||||
personCache,
|
||||
False, __version__)
|
||||
print('')
|
||||
elif commandStr == 'unlike' or commandStr == 'undo like':
|
||||
currIndex = 0
|
||||
if ' ' in commandStr:
|
||||
|
|
Loading…
Reference in New Issue