From bba25d8417e39fd4aba292cb296ba5b370f750b9 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 8 May 2021 14:14:52 +0100 Subject: [PATCH 1/4] Remove original announce post when unannouncing --- announce.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ daemon.py | 30 +++++++++++++++++++++++++---- outbox.py | 7 +++++++ webapp_post.py | 13 +++++++++++-- 4 files changed, 95 insertions(+), 6 deletions(-) diff --git a/announce.py b/announce.py index 2b9a1cc64..238f25659 100644 --- a/announce.py +++ b/announce.py @@ -6,6 +6,7 @@ __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +from utils import removeIdEnding from utils import hasUsersPath from utils import getFullDomain from utils import getStatusNumber @@ -334,3 +335,53 @@ def sendUndoAnnounceViaServer(baseDir: str, session, print('DEBUG: c2s POST undo announce success') return unAnnounceJson + + +def outboxUndoAnnounce(recentPostsCache: {}, + baseDir: str, httpPrefix: str, + nickname: str, domain: str, port: int, + messageJson: {}, debug: bool) -> None: + """ When an undo announce is received by the outbox from c2s + """ + if not messageJson.get('type'): + return + if not messageJson['type'] == 'Undo': + return + if not messageJson.get('object'): + return + if not isinstance(messageJson['object'], dict): + if debug: + print('DEBUG: undo like object is not dict') + return + if not messageJson['object'].get('type'): + if debug: + print('DEBUG: undo like - no type') + return + if not messageJson['object']['type'] == 'Announce': + if debug: + print('DEBUG: not a undo announce') + return + if not messageJson['object'].get('object'): + if debug: + print('DEBUG: no object in undo announce') + return + if not isinstance(messageJson['object']['object'], str): + if debug: + print('DEBUG: undo announce object is not string') + return + if debug: + print('DEBUG: c2s undo announce request arrived in outbox') + + messageId = removeIdEnding(messageJson['object']['object']) + if ':' in domain: + domain = domain.split(':')[0] + postFilename = locatePost(baseDir, nickname, domain, messageId) + if not postFilename: + if debug: + print('DEBUG: c2s undo announce post not found in inbox or outbox') + print(messageId) + return True + undoAnnounceCollectionEntry(recentPostsCache, baseDir, postFilename, + messageJson['actor'], domain, debug) + if debug: + print('DEBUG: post undo announce via c2s - ' + postFilename) diff --git a/daemon.py b/daemon.py index 6724ce694..700d26a9d 100644 --- a/daemon.py +++ b/daemon.py @@ -6228,13 +6228,17 @@ class PubServer(BaseHTTPRequestHandler): domain: str, domainFull: str, port: int, onionDomain: str, i2pDomain: str, GETstartTime, GETtimings: {}, - repeatPrivate: bool, debug: bool): + repeatPrivate: bool, debug: bool, + recentPostsCache: {}): """Undo announce/repeat button was pressed """ pageNumber = 1 + + # the post which was referenced by the announce post repeatUrl = path.split('?unrepeat=')[1] if '?' in repeatUrl: repeatUrl = repeatUrl.split('?')[0] + timelineBookmark = '' if '?bm=' in path: timelineBookmark = path.split('?bm=')[1] @@ -6283,11 +6287,11 @@ class PubServer(BaseHTTPRequestHandler): "@context": "https://www.w3.org/ns/activitystreams", 'actor': undoAnnounceActor, 'type': 'Undo', - 'cc': [undoAnnounceActor+'/followers'], + 'cc': [undoAnnounceActor + '/followers'], 'to': [unRepeatToStr], 'object': { 'actor': undoAnnounceActor, - 'cc': [undoAnnounceActor+'/followers'], + 'cc': [undoAnnounceActor + '/followers'], 'object': repeatUrl, 'to': [unRepeatToStr], 'type': 'Announce' @@ -6296,6 +6300,23 @@ class PubServer(BaseHTTPRequestHandler): # clear the icon from the cache so that it gets updated if self.server.iconsCache.get('repeat_inactive.png'): del self.server.iconsCache['repeat_inactive.png'] + + # delete the announce post + if '?unannounce=' in path: + announceUrl = path.split('?unannounce=')[1] + if '?' in announceUrl: + announceUrl = announceUrl.split('?')[0] + postFilename = None + nickname = getNicknameFromActor(announceUrl) + if nickname: + if announceUrl.endswith(domainFull + '/users/' + nickname): + postFilename = \ + locatePost(baseDir, nickname, domain, announceUrl) + if postFilename: + deletePost(baseDir, httpPrefix, + nickname, domain, postFilename, + debug, recentPostsCache) + self._postToOutboxThread(newUndoAnnounce) self.server.GETbusy = False actorAbsolute = self._getInstalceUrl(callingDomain) + actor @@ -11942,7 +11963,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.i2pDomain, GETstartTime, GETtimings, repeatPrivate, - self.server.debug) + self.server.debug, + self.server.recentPostsCache) return self._benchmarkGETtimings(GETstartTime, GETtimings, diff --git a/outbox.py b/outbox.py index 9243c7aa6..8ad268251 100644 --- a/outbox.py +++ b/outbox.py @@ -33,6 +33,7 @@ from media import getMediaPath from media import createMediaDirs from inbox import inboxUpdateIndex from announce import outboxAnnounce +from announce import outboxUndoAnnounce from follow import outboxUndoFollow from roles import outboxDelegate from skills import outboxSkills @@ -483,6 +484,12 @@ def postMessageToOutbox(session, translate: {}, baseDir, httpPrefix, postToNickname, domain, port, messageJson, debug) + if debug: + print('DEBUG: handle any undo announce requests') + outboxUndoAnnounce(recentPostsCache, + baseDir, httpPrefix, + postToNickname, domain, port, + messageJson, debug) if debug: print('DEBUG: handle any bookmark requests') diff --git a/webapp_post.py b/webapp_post.py index fb91b929f..702d3ba03 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -388,6 +388,7 @@ def _getEditIconHtml(baseDir: str, nickname: str, domainFull: str, def _getAnnounceIconHtml(isAnnounced: bool, postActor: str, nickname: str, domainFull: str, + announceJsonObject: {}, postJsonObject: {}, isPublicRepeat: bool, isModerationPost: bool, @@ -413,6 +414,7 @@ def _getAnnounceIconHtml(isAnnounced: bool, if not isPublicRepeat: announceLink = 'repeatprivate' announceTitle = translate['Repeat this post'] + unannounceLinkStr = '' if announcedByPerson(isAnnounced, postActor, nickname, domainFull): @@ -422,11 +424,15 @@ def _getAnnounceIconHtml(isAnnounced: bool, if not isPublicRepeat: announceLink = 'unrepeatprivate' announceTitle = translate['Undo the repeat'] + if announceJsonObject: + unannounceLinkStr = '?unannounce=' + \ + announceJsonObject['object']['id'] + announceLinkStr = '?' + \ + announceLink + '=' + postJsonObject['object']['id'] + pageNumberParam announceStr = \ ' \n' @@ -1291,7 +1297,9 @@ def individualPostAsHtml(allowDownloads: bool, titleStr = '' galleryStr = '' isAnnounced = False + announceJsonObject = None if postJsonObject['type'] == 'Announce': + announceJsonObject = postJsonObject.copy() postJsonAnnounce = \ downloadAnnounce(session, baseDir, httpPrefix, nickname, domain, postJsonObject, @@ -1414,6 +1422,7 @@ def individualPostAsHtml(allowDownloads: bool, _getAnnounceIconHtml(isAnnounced, postActor, nickname, domainFull, + announceJsonObject, postJsonObject, isPublicRepeat, isModerationPost, From 9f83477dde7c00f83237d1c3e54ada60007fb2c9 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 8 May 2021 14:21:02 +0100 Subject: [PATCH 2/4] Announce link --- webapp_post.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp_post.py b/webapp_post.py index 702d3ba03..818759691 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -426,7 +426,7 @@ def _getAnnounceIconHtml(isAnnounced: bool, announceTitle = translate['Undo the repeat'] if announceJsonObject: unannounceLinkStr = '?unannounce=' + \ - announceJsonObject['object']['id'] + announceJsonObject['id'] announceLinkStr = '?' + \ announceLink + '=' + postJsonObject['object']['id'] + pageNumberParam From fdc683d005eca9d83dd944fd133365c8b38b8b72 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 8 May 2021 14:24:04 +0100 Subject: [PATCH 3/4] Remove id ending from announce --- webapp_post.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp_post.py b/webapp_post.py index 818759691..67b843669 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -426,7 +426,7 @@ def _getAnnounceIconHtml(isAnnounced: bool, announceTitle = translate['Undo the repeat'] if announceJsonObject: unannounceLinkStr = '?unannounce=' + \ - announceJsonObject['id'] + removeIdEnding(announceJsonObject['id']) announceLinkStr = '?' + \ announceLink + '=' + postJsonObject['object']['id'] + pageNumberParam From 8623be69392fec52ae1894f01b8b8a5bd6432948 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 8 May 2021 16:16:58 +0100 Subject: [PATCH 4/4] Locating announce --- daemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon.py b/daemon.py index 700d26a9d..e9746cdfa 100644 --- a/daemon.py +++ b/daemon.py @@ -6309,7 +6309,7 @@ class PubServer(BaseHTTPRequestHandler): postFilename = None nickname = getNicknameFromActor(announceUrl) if nickname: - if announceUrl.endswith(domainFull + '/users/' + nickname): + if domainFull + '/users/' + nickname + '/' in announceUrl: postFilename = \ locatePost(baseDir, nickname, domain, announceUrl) if postFilename: