Remove original announce post when unannouncing

merge-requests/30/head
Bob Mottram 2021-05-08 14:14:52 +01:00
parent db3243724d
commit bba25d8417
4 changed files with 95 additions and 6 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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')

View File

@ -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 = \
' <a class="imageAnchor" href="/users/' + \
nickname + '?' + announceLink + \
'=' + postJsonObject['object']['id'] + pageNumberParam + \
nickname + announceLinkStr + unannounceLinkStr + \
'?actor=' + postJsonObject['actor'] + \
'?bm=' + timelinePostBookmark + \
'?tl=' + boxName + '" title="' + announceTitle + '">\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,