Removing id endings

merge-requests/30/head
Bob Mottram 2021-09-28 11:28:42 +01:00
parent 131aabdc03
commit a317e69d31
6 changed files with 36 additions and 26 deletions

View File

@ -4247,8 +4247,8 @@ class PubServer(BaseHTTPRequestHandler):
print('ERROR: saving newswire state, ' + str(e)) print('ERROR: saving newswire state, ' + str(e))
# remove any previous cached news posts # remove any previous cached news posts
newsId = \ newsId = removeIdEnding(postJsonObject['object']['id'])
postJsonObject['object']['id'].replace('/', '#') newsId = newsId.replace('/', '#')
clearFromPostCaches(baseDir, self.server.recentPostsCache, clearFromPostCaches(baseDir, self.server.recentPostsCache,
newsId) newsId)
@ -12429,7 +12429,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.systemLanguage) self.server.systemLanguage)
messageJson = {} messageJson = {}
if pinnedPostJson: if pinnedPostJson:
postId = pinnedPostJson['id'] postId = removeIdEnding(pinnedPostJson['id'])
messageJson = \ messageJson = \
outboxMessageCreateWrap(self.server.httpPrefix, outboxMessageCreateWrap(self.server.httpPrefix,
nickname, nickname,

View File

@ -2190,7 +2190,7 @@ def _sendToGroupMembers(session, baseDir: str, handle: str, port: int,
savePostToBox(baseDir, httpPrefix, None, savePostToBox(baseDir, httpPrefix, None,
nickname, domain, postJsonObject, 'outbox') nickname, domain, postJsonObject, 'outbox')
postId = postJsonObject['object']['id'] postId = removeIdEnding(postJsonObject['object']['id'])
if debug: if debug:
print('Group announce: ' + postId) print('Group announce: ' + postId)
announceJson = \ announceJson = \
@ -2478,7 +2478,8 @@ def _isValidDM(baseDir: str, nickname: str, domain: str, port: int,
obj = postJsonObject['object'] obj = postJsonObject['object']
if isinstance(obj, dict): if isinstance(obj, dict):
if not obj.get('inReplyTo'): if not obj.get('inReplyTo'):
_bounceDM(postJsonObject['id'], bouncedId = removeIdEnding(postJsonObject['id'])
_bounceDM(bouncedId,
session, httpPrefix, session, httpPrefix,
baseDir, baseDir,
nickname, domain, nickname, domain,
@ -3444,7 +3445,7 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
# set the id to the same as the post filename # set the id to the same as the post filename
# This makes the filename and the id consistent # This makes the filename and the id consistent
# if queueJson['post'].get('id'): # if queueJson['post'].get('id'):
# queueJson['post']['id']=queueJson['id'] # queueJson['post']['id'] = queueJson['id']
if _receiveUndo(session, if _receiveUndo(session,
baseDir, httpPrefix, port, baseDir, httpPrefix, port,

View File

@ -32,6 +32,7 @@ from webfinger import webfingerHandle
from httpsig import createSignedHeader from httpsig import createSignedHeader
from siteactive import siteIsActive from siteactive import siteIsActive
from languages import understoodPostLanguage from languages import understoodPostLanguage
from utils import removeIdEnding
from utils import replaceUsersWithAt from utils import replaceUsersWithAt
from utils import hasGroupType from utils import hasGroupType
from utils import getBaseContentFromPost from utils import getBaseContentFromPost
@ -1989,7 +1990,8 @@ def createDirectMessagePost(baseDir: str,
messageJson['cc'] = [] messageJson['cc'] = []
messageJson['object']['cc'] = [] messageJson['object']['cc'] = []
if schedulePost: if schedulePost:
savePostToBox(baseDir, httpPrefix, messageJson['object']['id'], postId = removeIdEnding(messageJson['object']['id'])
savePostToBox(baseDir, httpPrefix, postId,
nickname, domain, messageJson, 'scheduled') nickname, domain, messageJson, 'scheduled')
return messageJson return messageJson
@ -4362,7 +4364,7 @@ def downloadAnnounce(session, baseDir: str, httpPrefix: str,
postId = None postId = None
if postJsonObject.get('id'): if postJsonObject.get('id'):
postId = postJsonObject['id'] postId = removeIdEnding(postJsonObject['id'])
announceFilename = \ announceFilename = \
announceCacheDir + '/' + \ announceCacheDir + '/' + \
postJsonObject['object'].replace('/', '#') + '.json' postJsonObject['object'].replace('/', '#') + '.json'

View File

@ -11,6 +11,7 @@ import os
import html import html
import random import random
import urllib.parse import urllib.parse
from utils import removeIdEnding
from utils import isDM from utils import isDM
from utils import isReply from utils import isReply
from utils import camelCaseSplit from utils import camelCaseSplit
@ -489,7 +490,7 @@ def _postToSpeakerJson(baseDir: str, httpPrefix: str,
announcedHandle + '. ' + content announcedHandle + '. ' + content
postId = None postId = None
if postJsonObject['object'].get('id'): if postJsonObject['object'].get('id'):
postId = postJsonObject['object']['id'] postId = removeIdEnding(postJsonObject['object']['id'])
followRequestsExist = False followRequestsExist = False
followRequestsList = [] followRequestsList = []

View File

@ -10,6 +10,7 @@ __module_group__ = "Timeline"
from utils import getFullDomain from utils import getFullDomain
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import removeIdEnding
from blocking import isBlocked from blocking import isBlocked
from filters import isFiltered from filters import isFiltered
@ -88,7 +89,7 @@ def convertVideoToNote(baseDir: str, nickname: str, domain: str,
content += '<p>' + postJsonObject['license']['name'] + '</p>' content += '<p>' + postJsonObject['license']['name'] + '</p>'
content += postJsonObject['content'] content += postJsonObject['content']
conversationId = postJsonObject['id'] conversationId = removeIdEnding(postJsonObject['id'])
mediaType = None mediaType = None
mediaUrl = None mediaUrl = None
@ -130,27 +131,28 @@ def convertVideoToNote(baseDir: str, nickname: str, domain: str,
content += '<a href="' + mediaMagnet + '">🧲</a>' content += '<a href="' + mediaMagnet + '">🧲</a>'
content += '</p>' content += '</p>'
newPostId = removeIdEnding(postJsonObject['id'])
newPost = { newPost = {
'@context': postJsonObject['@context'], '@context': postJsonObject['@context'],
'id': postJsonObject['id'] + '/activity', 'id': newPostId + '/activity',
'type': 'Create', 'type': 'Create',
'actor': attributedTo, 'actor': attributedTo,
'published': postJsonObject['published'], 'published': postJsonObject['published'],
'to': postJsonObject['to'], 'to': postJsonObject['to'],
'cc': postJsonObject['cc'], 'cc': postJsonObject['cc'],
'object': { 'object': {
'id': postJsonObject['id'], 'id': newPostId,
'conversation': conversationId, 'conversation': conversationId,
'type': 'Note', 'type': 'Note',
'summary': None, 'summary': None,
'inReplyTo': None, 'inReplyTo': None,
'published': postJsonObject['published'], 'published': postJsonObject['published'],
'url': postJsonObject['id'], 'url': newPostId,
'attributedTo': attributedTo, 'attributedTo': attributedTo,
'to': postJsonObject['to'], 'to': postJsonObject['to'],
'cc': postJsonObject['cc'], 'cc': postJsonObject['cc'],
'sensitive': postJsonObject['sensitive'], 'sensitive': postJsonObject['sensitive'],
'atomUri': postJsonObject['id'], 'atomUri': newPostId,
'inReplyToAtomUri': None, 'inReplyToAtomUri': None,
'commentsEnabled': postJsonObject['commentsEnabled'], 'commentsEnabled': postJsonObject['commentsEnabled'],
'rejectReplies': not postJsonObject['commentsEnabled'], 'rejectReplies': not postJsonObject['commentsEnabled'],
@ -162,11 +164,11 @@ def convertVideoToNote(baseDir: str, nickname: str, domain: str,
'attachment': attachment, 'attachment': attachment,
'tag': [], 'tag': [],
'replies': { 'replies': {
'id': postJsonObject['id'] + '/replies', 'id': newPostId + '/replies',
'type': 'Collection', 'type': 'Collection',
'first': { 'first': {
'type': 'CollectionPage', 'type': 'CollectionPage',
'partOf': postJsonObject['id'] + '/replies', 'partOf': newPostId + '/replies',
'items': [] 'items': []
} }
} }

View File

@ -297,7 +297,7 @@ def _getReplyIconHtml(baseDir: str, nickname: str, domain: str,
return replyStr return replyStr
# reply is permitted - create reply icon # reply is permitted - create reply icon
replyToLink = postJsonObject['object']['id'] replyToLink = removeIdEnding(postJsonObject['object']['id'])
# see Mike MacGirvin's replyTo suggestion # see Mike MacGirvin's replyTo suggestion
if postJsonObject['object'].get('replyTo'): if postJsonObject['object'].get('replyTo'):
@ -380,7 +380,7 @@ def _getEditIconHtml(baseDir: str, nickname: str, domainFull: str,
(isEditor(baseDir, nickname) and (isEditor(baseDir, nickname) and
actor.endswith('/' + domainFull + '/users/news'))): actor.endswith('/' + domainFull + '/users/news'))):
postId = postJsonObject['object']['id'] postId = removeIdEnding(postJsonObject['object']['id'])
if '/statuses/' not in postId: if '/statuses/' not in postId:
return editStr return editStr
@ -478,8 +478,9 @@ def _getAnnounceIconHtml(isAnnounced: bool,
unannounceLinkStr = '?unannounce=' + \ unannounceLinkStr = '?unannounce=' + \
removeIdEnding(announceJsonObject['id']) removeIdEnding(announceJsonObject['id'])
announcePostId = removeIdEnding(postJsonObject['object']['id'])
announceLinkStr = '?' + \ announceLinkStr = '?' + \
announceLink + '=' + postJsonObject['object']['id'] + pageNumberParam announceLink + '=' + announcePostId + pageNumberParam
announceStr = \ announceStr = \
' <a class="imageAnchor" href="/users/' + \ ' <a class="imageAnchor" href="/users/' + \
nickname + announceLinkStr + unannounceLinkStr + \ nickname + announceLinkStr + unannounceLinkStr + \
@ -544,9 +545,10 @@ def _getLikeIconHtml(nickname: str, domainFull: str,
likeStr += '<label class="likesCount">' likeStr += '<label class="likesCount">'
likeStr += likeCountStr.replace('(', '').replace(')', '').strip() likeStr += likeCountStr.replace('(', '').replace(')', '').strip()
likeStr += '</label>\n' likeStr += '</label>\n'
likePostId = removeIdEnding(postJsonObject['object']['id'])
likeStr += \ likeStr += \
' <a class="imageAnchor" href="/users/' + nickname + '?' + \ ' <a class="imageAnchor" href="/users/' + nickname + '?' + \
likeLink + '=' + postJsonObject['object']['id'] + \ likeLink + '=' + likePostId + \
pageNumberParam + \ pageNumberParam + \
'?actor=' + postJsonObject['actor'] + \ '?actor=' + postJsonObject['actor'] + \
'?bm=' + timelinePostBookmark + \ '?bm=' + timelinePostBookmark + \
@ -589,9 +591,10 @@ def _getBookmarkIconHtml(nickname: str, domainFull: str,
if translate.get(bookmarkTitle): if translate.get(bookmarkTitle):
bookmarkTitle = translate[bookmarkTitle] bookmarkTitle = translate[bookmarkTitle]
_logPostTiming(enableTimingLog, postStartTime, '12.6') _logPostTiming(enableTimingLog, postStartTime, '12.6')
bookmarkPostId = removeIdEnding(postJsonObject['object']['id'])
bookmarkStr = \ bookmarkStr = \
' <a class="imageAnchor" href="/users/' + nickname + '?' + \ ' <a class="imageAnchor" href="/users/' + nickname + '?' + \
bookmarkLink + '=' + postJsonObject['object']['id'] + \ bookmarkLink + '=' + bookmarkPostId + \
pageNumberParam + \ pageNumberParam + \
'?actor=' + postJsonObject['actor'] + \ '?actor=' + postJsonObject['actor'] + \
'?bm=' + timelinePostBookmark + \ '?bm=' + timelinePostBookmark + \
@ -777,13 +780,13 @@ def _announceUnattributedHtml(translate: {},
announcesStr = 'announces' announcesStr = 'announces'
if translate.get(announcesStr): if translate.get(announcesStr):
announcesStr = translate[announcesStr] announcesStr = translate[announcesStr]
postId = removeIdEnding(postJsonObject['object']['id'])
return ' <img loading="lazy" title="' + \ return ' <img loading="lazy" title="' + \
announcesStr + '" alt="' + \ announcesStr + '" alt="' + \
announcesStr + '" src="/icons' + \ announcesStr + '" src="/icons' + \
'/repeat_inactive.png" ' + \ '/repeat_inactive.png" ' + \
'class="announceOrReply"/>\n' + \ 'class="announceOrReply"/>\n' + \
' <a href="' + \ ' <a href="' + postId + \
postJsonObject['object']['id'] + \
'" class="announceOrReply">@unattributed</a>\n' '" class="announceOrReply">@unattributed</a>\n'
@ -795,13 +798,13 @@ def _announceWithDisplayNameHtml(translate: {},
announcesStr = 'announces' announcesStr = 'announces'
if translate.get(announcesStr): if translate.get(announcesStr):
announcesStr = translate[announcesStr] announcesStr = translate[announcesStr]
postId = removeIdEnding(postJsonObject['object']['id'])
return ' <img loading="lazy" title="' + \ return ' <img loading="lazy" title="' + \
announcesStr + '" alt="' + \ announcesStr + '" alt="' + \
announcesStr + '" src="/' + \ announcesStr + '" src="/' + \
'icons/repeat_inactive.png" ' + \ 'icons/repeat_inactive.png" ' + \
'class="announceOrReply"/>\n' + \ 'class="announceOrReply"/>\n' + \
' <a href="' + \ ' <a href="' + postId + '" ' + \
postJsonObject['object']['id'] + '" ' + \
'class="announceOrReply">' + announceDisplayName + '</a>\n' 'class="announceOrReply">' + announceDisplayName + '</a>\n'
@ -1361,7 +1364,8 @@ def individualPostAsHtml(signingPrivateKeyPem: str,
blockedCache) blockedCache)
if not postJsonAnnounce: if not postJsonAnnounce:
# if the announce could not be downloaded then mark it as rejected # if the announce could not be downloaded then mark it as rejected
rejectPostId(baseDir, nickname, domain, postJsonObject['id'], announcedPostId = removeIdEnding(postJsonObject['id'])
rejectPostId(baseDir, nickname, domain, announcedPostId,
recentPostsCache) recentPostsCache)
return '' return ''
postJsonObject = postJsonAnnounce postJsonObject = postJsonAnnounce