mirror of https://gitlab.com/bashrc2/epicyon
Remove original announce post when unannouncing
parent
db3243724d
commit
bba25d8417
51
announce.py
51
announce.py
|
@ -6,6 +6,7 @@ __maintainer__ = "Bob Mottram"
|
||||||
__email__ = "bob@freedombone.net"
|
__email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
|
from utils import removeIdEnding
|
||||||
from utils import hasUsersPath
|
from utils import hasUsersPath
|
||||||
from utils import getFullDomain
|
from utils import getFullDomain
|
||||||
from utils import getStatusNumber
|
from utils import getStatusNumber
|
||||||
|
@ -334,3 +335,53 @@ def sendUndoAnnounceViaServer(baseDir: str, session,
|
||||||
print('DEBUG: c2s POST undo announce success')
|
print('DEBUG: c2s POST undo announce success')
|
||||||
|
|
||||||
return unAnnounceJson
|
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)
|
||||||
|
|
26
daemon.py
26
daemon.py
|
@ -6228,13 +6228,17 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
domain: str, domainFull: str, port: int,
|
domain: str, domainFull: str, port: int,
|
||||||
onionDomain: str, i2pDomain: str,
|
onionDomain: str, i2pDomain: str,
|
||||||
GETstartTime, GETtimings: {},
|
GETstartTime, GETtimings: {},
|
||||||
repeatPrivate: bool, debug: bool):
|
repeatPrivate: bool, debug: bool,
|
||||||
|
recentPostsCache: {}):
|
||||||
"""Undo announce/repeat button was pressed
|
"""Undo announce/repeat button was pressed
|
||||||
"""
|
"""
|
||||||
pageNumber = 1
|
pageNumber = 1
|
||||||
|
|
||||||
|
# the post which was referenced by the announce post
|
||||||
repeatUrl = path.split('?unrepeat=')[1]
|
repeatUrl = path.split('?unrepeat=')[1]
|
||||||
if '?' in repeatUrl:
|
if '?' in repeatUrl:
|
||||||
repeatUrl = repeatUrl.split('?')[0]
|
repeatUrl = repeatUrl.split('?')[0]
|
||||||
|
|
||||||
timelineBookmark = ''
|
timelineBookmark = ''
|
||||||
if '?bm=' in path:
|
if '?bm=' in path:
|
||||||
timelineBookmark = path.split('?bm=')[1]
|
timelineBookmark = path.split('?bm=')[1]
|
||||||
|
@ -6296,6 +6300,23 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
# clear the icon from the cache so that it gets updated
|
# clear the icon from the cache so that it gets updated
|
||||||
if self.server.iconsCache.get('repeat_inactive.png'):
|
if self.server.iconsCache.get('repeat_inactive.png'):
|
||||||
del self.server.iconsCache['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._postToOutboxThread(newUndoAnnounce)
|
||||||
self.server.GETbusy = False
|
self.server.GETbusy = False
|
||||||
actorAbsolute = self._getInstalceUrl(callingDomain) + actor
|
actorAbsolute = self._getInstalceUrl(callingDomain) + actor
|
||||||
|
@ -11942,7 +11963,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.i2pDomain,
|
self.server.i2pDomain,
|
||||||
GETstartTime, GETtimings,
|
GETstartTime, GETtimings,
|
||||||
repeatPrivate,
|
repeatPrivate,
|
||||||
self.server.debug)
|
self.server.debug,
|
||||||
|
self.server.recentPostsCache)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
|
|
@ -33,6 +33,7 @@ from media import getMediaPath
|
||||||
from media import createMediaDirs
|
from media import createMediaDirs
|
||||||
from inbox import inboxUpdateIndex
|
from inbox import inboxUpdateIndex
|
||||||
from announce import outboxAnnounce
|
from announce import outboxAnnounce
|
||||||
|
from announce import outboxUndoAnnounce
|
||||||
from follow import outboxUndoFollow
|
from follow import outboxUndoFollow
|
||||||
from roles import outboxDelegate
|
from roles import outboxDelegate
|
||||||
from skills import outboxSkills
|
from skills import outboxSkills
|
||||||
|
@ -483,6 +484,12 @@ def postMessageToOutbox(session, translate: {},
|
||||||
baseDir, httpPrefix,
|
baseDir, httpPrefix,
|
||||||
postToNickname, domain, port,
|
postToNickname, domain, port,
|
||||||
messageJson, debug)
|
messageJson, debug)
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: handle any undo announce requests')
|
||||||
|
outboxUndoAnnounce(recentPostsCache,
|
||||||
|
baseDir, httpPrefix,
|
||||||
|
postToNickname, domain, port,
|
||||||
|
messageJson, debug)
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: handle any bookmark requests')
|
print('DEBUG: handle any bookmark requests')
|
||||||
|
|
|
@ -388,6 +388,7 @@ def _getEditIconHtml(baseDir: str, nickname: str, domainFull: str,
|
||||||
def _getAnnounceIconHtml(isAnnounced: bool,
|
def _getAnnounceIconHtml(isAnnounced: bool,
|
||||||
postActor: str,
|
postActor: str,
|
||||||
nickname: str, domainFull: str,
|
nickname: str, domainFull: str,
|
||||||
|
announceJsonObject: {},
|
||||||
postJsonObject: {},
|
postJsonObject: {},
|
||||||
isPublicRepeat: bool,
|
isPublicRepeat: bool,
|
||||||
isModerationPost: bool,
|
isModerationPost: bool,
|
||||||
|
@ -413,6 +414,7 @@ def _getAnnounceIconHtml(isAnnounced: bool,
|
||||||
if not isPublicRepeat:
|
if not isPublicRepeat:
|
||||||
announceLink = 'repeatprivate'
|
announceLink = 'repeatprivate'
|
||||||
announceTitle = translate['Repeat this post']
|
announceTitle = translate['Repeat this post']
|
||||||
|
unannounceLinkStr = ''
|
||||||
|
|
||||||
if announcedByPerson(isAnnounced,
|
if announcedByPerson(isAnnounced,
|
||||||
postActor, nickname, domainFull):
|
postActor, nickname, domainFull):
|
||||||
|
@ -422,11 +424,15 @@ def _getAnnounceIconHtml(isAnnounced: bool,
|
||||||
if not isPublicRepeat:
|
if not isPublicRepeat:
|
||||||
announceLink = 'unrepeatprivate'
|
announceLink = 'unrepeatprivate'
|
||||||
announceTitle = translate['Undo the repeat']
|
announceTitle = translate['Undo the repeat']
|
||||||
|
if announceJsonObject:
|
||||||
|
unannounceLinkStr = '?unannounce=' + \
|
||||||
|
announceJsonObject['object']['id']
|
||||||
|
|
||||||
|
announceLinkStr = '?' + \
|
||||||
|
announceLink + '=' + postJsonObject['object']['id'] + pageNumberParam
|
||||||
announceStr = \
|
announceStr = \
|
||||||
' <a class="imageAnchor" href="/users/' + \
|
' <a class="imageAnchor" href="/users/' + \
|
||||||
nickname + '?' + announceLink + \
|
nickname + announceLinkStr + unannounceLinkStr + \
|
||||||
'=' + postJsonObject['object']['id'] + pageNumberParam + \
|
|
||||||
'?actor=' + postJsonObject['actor'] + \
|
'?actor=' + postJsonObject['actor'] + \
|
||||||
'?bm=' + timelinePostBookmark + \
|
'?bm=' + timelinePostBookmark + \
|
||||||
'?tl=' + boxName + '" title="' + announceTitle + '">\n'
|
'?tl=' + boxName + '" title="' + announceTitle + '">\n'
|
||||||
|
@ -1291,7 +1297,9 @@ def individualPostAsHtml(allowDownloads: bool,
|
||||||
titleStr = ''
|
titleStr = ''
|
||||||
galleryStr = ''
|
galleryStr = ''
|
||||||
isAnnounced = False
|
isAnnounced = False
|
||||||
|
announceJsonObject = None
|
||||||
if postJsonObject['type'] == 'Announce':
|
if postJsonObject['type'] == 'Announce':
|
||||||
|
announceJsonObject = postJsonObject.copy()
|
||||||
postJsonAnnounce = \
|
postJsonAnnounce = \
|
||||||
downloadAnnounce(session, baseDir, httpPrefix,
|
downloadAnnounce(session, baseDir, httpPrefix,
|
||||||
nickname, domain, postJsonObject,
|
nickname, domain, postJsonObject,
|
||||||
|
@ -1414,6 +1422,7 @@ def individualPostAsHtml(allowDownloads: bool,
|
||||||
_getAnnounceIconHtml(isAnnounced,
|
_getAnnounceIconHtml(isAnnounced,
|
||||||
postActor,
|
postActor,
|
||||||
nickname, domainFull,
|
nickname, domainFull,
|
||||||
|
announceJsonObject,
|
||||||
postJsonObject,
|
postJsonObject,
|
||||||
isPublicRepeat,
|
isPublicRepeat,
|
||||||
isModerationPost,
|
isModerationPost,
|
||||||
|
|
Loading…
Reference in New Issue