forked from indymedia/epicyon
Remove id endings in a better way
parent
8151f32196
commit
86f2e9d8ab
|
@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from utils import removeIdEnding
|
||||||
from utils import isEvil
|
from utils import isEvil
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
from utils import evilIncarnate
|
from utils import evilIncarnate
|
||||||
|
@ -214,7 +215,7 @@ def outboxBlock(baseDir: str, httpPrefix: str,
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s block request arrived in outbox')
|
print('DEBUG: c2s block request arrived in outbox')
|
||||||
|
|
||||||
messageId = messageJson['object'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['object'])
|
||||||
if '/statuses/' not in messageId:
|
if '/statuses/' not in messageId:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s block object is not a status')
|
print('DEBUG: c2s block object is not a status')
|
||||||
|
@ -293,7 +294,7 @@ def outboxUndoBlock(baseDir: str, httpPrefix: str,
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s undo block request arrived in outbox')
|
print('DEBUG: c2s undo block request arrived in outbox')
|
||||||
|
|
||||||
messageId = messageJson['object']['object'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['object']['object'])
|
||||||
if '/statuses/' not in messageId:
|
if '/statuses/' not in messageId:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s undo block object is not a status')
|
print('DEBUG: c2s undo block object is not a status')
|
||||||
|
|
|
@ -8,6 +8,7 @@ __status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
from utils import removeIdEnding
|
||||||
from utils import removePostFromCache
|
from utils import removePostFromCache
|
||||||
from utils import urlPermitted
|
from utils import urlPermitted
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
|
@ -607,7 +608,7 @@ def outboxBookmark(recentPostsCache: {},
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s bookmark request arrived in outbox')
|
print('DEBUG: c2s bookmark request arrived in outbox')
|
||||||
|
|
||||||
messageId = messageJson['object'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['object'])
|
||||||
if ':' in domain:
|
if ':' in domain:
|
||||||
domain = domain.split(':')[0]
|
domain = domain.split(':')[0]
|
||||||
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
||||||
|
@ -667,7 +668,7 @@ def outboxUndoBookmark(recentPostsCache: {},
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s undo bookmark request arrived in outbox')
|
print('DEBUG: c2s undo bookmark request arrived in outbox')
|
||||||
|
|
||||||
messageId = messageJson['object']['object'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['object']['object'])
|
||||||
if ':' in domain:
|
if ':' in domain:
|
||||||
domain = domain.split(':')[0]
|
domain = domain.split(':')[0]
|
||||||
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
||||||
|
|
102
daemon.py
102
daemon.py
|
@ -127,6 +127,7 @@ from webinterface import htmlIndividualPost
|
||||||
from webinterface import htmlProfile
|
from webinterface import htmlProfile
|
||||||
from webinterface import htmlInbox
|
from webinterface import htmlInbox
|
||||||
from webinterface import htmlBookmarks
|
from webinterface import htmlBookmarks
|
||||||
|
from webinterface import htmlEvents
|
||||||
from webinterface import htmlShares
|
from webinterface import htmlShares
|
||||||
from webinterface import htmlOutbox
|
from webinterface import htmlOutbox
|
||||||
from webinterface import htmlModeration
|
from webinterface import htmlModeration
|
||||||
|
@ -154,6 +155,7 @@ from shares import getSharesFeedForPerson
|
||||||
from shares import addShare
|
from shares import addShare
|
||||||
from shares import removeShare
|
from shares import removeShare
|
||||||
from shares import expireShares
|
from shares import expireShares
|
||||||
|
from utils import removeIdEnding
|
||||||
from utils import updateLikesCollection
|
from utils import updateLikesCollection
|
||||||
from utils import undoLikesCollectionEntry
|
from utils import undoLikesCollectionEntry
|
||||||
from utils import deletePost
|
from utils import deletePost
|
||||||
|
@ -2734,10 +2736,9 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings, 32)
|
self._benchmarkGETtimings(GETstartTime, GETtimings, 32)
|
||||||
|
|
||||||
# unrepeatPrivate = False
|
|
||||||
if htmlGET and '?unrepeatprivate=' in self.path:
|
if htmlGET and '?unrepeatprivate=' in self.path:
|
||||||
self.path = self.path.replace('?unrepeatprivate=', '?unrepeat=')
|
self.path = self.path.replace('?unrepeatprivate=', '?unrepeat=')
|
||||||
# unrepeatPrivate = True
|
|
||||||
# undo an announce/repeat from the web interface
|
# undo an announce/repeat from the web interface
|
||||||
if htmlGET and '?unrepeat=' in self.path:
|
if htmlGET and '?unrepeat=' in self.path:
|
||||||
pageNumber = 1
|
pageNumber = 1
|
||||||
|
@ -4823,6 +4824,100 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.GETbusy = False
|
self.server.GETbusy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# get the events for a given person
|
||||||
|
if self.path.endswith('/tlevents') or \
|
||||||
|
'/tlevents?page=' in self.path or \
|
||||||
|
self.path.endswith('/events') or \
|
||||||
|
'/events?page=' in self.path:
|
||||||
|
if '/users/' in self.path:
|
||||||
|
if authorized:
|
||||||
|
eventsFeed = \
|
||||||
|
personBoxJson(self.server.recentPostsCache,
|
||||||
|
self.server.session,
|
||||||
|
self.server.baseDir,
|
||||||
|
self.server.domain,
|
||||||
|
self.server.port,
|
||||||
|
self.path,
|
||||||
|
self.server.httpPrefix,
|
||||||
|
maxPostsInFeed, 'tlevents',
|
||||||
|
authorized, self.server.ocapAlways)
|
||||||
|
if eventsFeed:
|
||||||
|
if self._requestHTTP():
|
||||||
|
nickname = self.path.replace('/users/', '')
|
||||||
|
nickname = nickname.replace('/tlevents', '')
|
||||||
|
nickname = nickname.replace('/events', '')
|
||||||
|
pageNumber = 1
|
||||||
|
if '?page=' in nickname:
|
||||||
|
pageNumber = nickname.split('?page=')[1]
|
||||||
|
nickname = nickname.split('?page=')[0]
|
||||||
|
if pageNumber.isdigit():
|
||||||
|
pageNumber = int(pageNumber)
|
||||||
|
else:
|
||||||
|
pageNumber = 1
|
||||||
|
if 'page=' not in self.path:
|
||||||
|
# if no page was specified then show the first
|
||||||
|
eventsFeed = \
|
||||||
|
personBoxJson(self.server.recentPostsCache,
|
||||||
|
self.server.session,
|
||||||
|
self.server.baseDir,
|
||||||
|
self.server.domain,
|
||||||
|
self.server.port,
|
||||||
|
self.path + '?page=1',
|
||||||
|
self.server.httpPrefix,
|
||||||
|
maxPostsInFeed,
|
||||||
|
'tlevents',
|
||||||
|
authorized,
|
||||||
|
self.server.ocapAlways)
|
||||||
|
msg = \
|
||||||
|
htmlEvents(self.server.defaultTimeline,
|
||||||
|
self.server.recentPostsCache,
|
||||||
|
self.server.maxRecentPosts,
|
||||||
|
self.server.translate,
|
||||||
|
pageNumber, maxPostsInFeed,
|
||||||
|
self.server.session,
|
||||||
|
self.server.baseDir,
|
||||||
|
self.server.cachedWebfingers,
|
||||||
|
self.server.personCache,
|
||||||
|
nickname,
|
||||||
|
self.server.domain,
|
||||||
|
self.server.port,
|
||||||
|
eventsFeed,
|
||||||
|
self.server.allowDeletion,
|
||||||
|
self.server.httpPrefix,
|
||||||
|
self.server.projectVersion,
|
||||||
|
self._isMinimal(nickname),
|
||||||
|
self.server.YTReplacementDomain)
|
||||||
|
msg = msg.encode('utf-8')
|
||||||
|
self._set_headers('text/html',
|
||||||
|
len(msg),
|
||||||
|
cookie, callingDomain)
|
||||||
|
self._write(msg)
|
||||||
|
else:
|
||||||
|
# don't need authenticated fetch here because
|
||||||
|
# there is already the authorization check
|
||||||
|
msg = json.dumps(inboxFeed,
|
||||||
|
ensure_ascii=False)
|
||||||
|
msg = msg.encode('utf-8')
|
||||||
|
self._set_headers('application/json',
|
||||||
|
len(msg),
|
||||||
|
None, callingDomain)
|
||||||
|
self._write(msg)
|
||||||
|
self.server.GETbusy = False
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
if self.server.debug:
|
||||||
|
nickname = self.path.replace('/users/', '')
|
||||||
|
nickname = nickname.replace('/tlevents', '')
|
||||||
|
nickname = nickname.replace('/events', '')
|
||||||
|
print('DEBUG: ' + nickname +
|
||||||
|
' was not authorized to access ' + self.path)
|
||||||
|
if self.server.debug:
|
||||||
|
print('DEBUG: GET access to events is unauthorized')
|
||||||
|
self.send_response(405)
|
||||||
|
self.end_headers()
|
||||||
|
self.server.GETbusy = False
|
||||||
|
return
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings, 47)
|
self._benchmarkGETtimings(GETstartTime, GETtimings, 47)
|
||||||
|
|
||||||
# get outbox feed for a person
|
# get outbox feed for a person
|
||||||
|
@ -8682,8 +8777,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if self.outboxAuthenticated:
|
if self.outboxAuthenticated:
|
||||||
if self._postToOutbox(messageJson, __version__):
|
if self._postToOutbox(messageJson, __version__):
|
||||||
if messageJson.get('id'):
|
if messageJson.get('id'):
|
||||||
locnStr = messageJson['id'].replace('/activity', '')
|
locnStr = removeIdEnding(messageJson['id'])
|
||||||
locnStr = locnStr.replace('/undo', '')
|
|
||||||
self.headers['Location'] = locnStr
|
self.headers['Location'] = locnStr
|
||||||
self.send_response(201)
|
self.send_response(201)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
|
@ -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 getStatusNumber
|
from utils import getStatusNumber
|
||||||
from utils import urlPermitted
|
from utils import urlPermitted
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
|
@ -257,7 +258,7 @@ def outboxDelete(baseDir: str, httpPrefix: str,
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: delete not permitted from other instances')
|
print('DEBUG: delete not permitted from other instances')
|
||||||
return
|
return
|
||||||
messageId = messageJson['object'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['object'])
|
||||||
if '/statuses/' not in messageId:
|
if '/statuses/' not in messageId:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s delete object is not a status')
|
print('DEBUG: c2s delete object is not a status')
|
||||||
|
|
27
inbox.py
27
inbox.py
|
@ -10,6 +10,7 @@ import json
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
from utils import removeIdEnding
|
||||||
from utils import getProtocolPrefixes
|
from utils import getProtocolPrefixes
|
||||||
from utils import isBlogPost
|
from utils import isBlogPost
|
||||||
from utils import removeAvatarFromCache
|
from utils import removeAvatarFromCache
|
||||||
|
@ -93,7 +94,7 @@ def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
||||||
continue
|
continue
|
||||||
tagName = tag['name'].replace('#', '').strip()
|
tagName = tag['name'].replace('#', '').strip()
|
||||||
tagsFilename = tagsDir + '/' + tagName + '.txt'
|
tagsFilename = tagsDir + '/' + tagName + '.txt'
|
||||||
postUrl = postJsonObject['id'].replace('/activity', '')
|
postUrl = removeIdEnding(postJsonObject['id'])
|
||||||
postUrl = postUrl.replace('/', '#')
|
postUrl = postUrl.replace('/', '#')
|
||||||
daysDiff = datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)
|
daysDiff = datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)
|
||||||
daysSinceEpoch = daysDiff.days
|
daysSinceEpoch = daysDiff.days
|
||||||
|
@ -354,15 +355,13 @@ def savePostToInboxQueue(baseDir: str, httpPrefix: str,
|
||||||
return None
|
return None
|
||||||
originalPostId = None
|
originalPostId = None
|
||||||
if postJsonObject.get('id'):
|
if postJsonObject.get('id'):
|
||||||
originalPostId = \
|
originalPostId = removeIdEnding(postJsonObject['id'])
|
||||||
postJsonObject['id'].replace('/activity', '').replace('/undo', '')
|
|
||||||
|
|
||||||
currTime = datetime.datetime.utcnow()
|
currTime = datetime.datetime.utcnow()
|
||||||
|
|
||||||
postId = None
|
postId = None
|
||||||
if postJsonObject.get('id'):
|
if postJsonObject.get('id'):
|
||||||
postId = postJsonObject['id'].replace('/activity', '')
|
postId = removeIdEnding(postJsonObject['id'])
|
||||||
postId = postId.replace('/undo', '')
|
|
||||||
published = currTime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
published = currTime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
if not postId:
|
if not postId:
|
||||||
statusNumber, published = getStatusNumber()
|
statusNumber, published = getStatusNumber()
|
||||||
|
@ -817,9 +816,7 @@ def receiveEventPost(recentPostsCache: {}, session, baseDir: str,
|
||||||
if port != 80 and port != 443:
|
if port != 80 and port != 443:
|
||||||
handle += ':' + str(port)
|
handle += ':' + str(port)
|
||||||
|
|
||||||
postId = \
|
postId = removeIdEnding(messageJson['id']).replace('/', '#')
|
||||||
messageJson['id'].replace('/activity', '').replace('/', '#')
|
|
||||||
postId = postId.replace('/event', '')
|
|
||||||
|
|
||||||
saveEventPost(baseDir, handle, postId, messageJson['object'])
|
saveEventPost(baseDir, handle, postId, messageJson['object'])
|
||||||
|
|
||||||
|
@ -910,7 +907,7 @@ def receiveUpdateToQuestion(recentPostsCache: {}, messageJson: {},
|
||||||
return
|
return
|
||||||
if not messageJson.get('actor'):
|
if not messageJson.get('actor'):
|
||||||
return
|
return
|
||||||
messageId = messageJson['id'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['id'])
|
||||||
if '#' in messageId:
|
if '#' in messageId:
|
||||||
messageId = messageId.split('#', 1)[0]
|
messageId = messageId.split('#', 1)[0]
|
||||||
# find the question post
|
# find the question post
|
||||||
|
@ -1367,8 +1364,7 @@ def receiveDelete(session, handle: str, isGroup: bool, baseDir: str,
|
||||||
if not os.path.isdir(baseDir + '/accounts/' + handle):
|
if not os.path.isdir(baseDir + '/accounts/' + handle):
|
||||||
print('DEBUG: unknown recipient of like - ' + handle)
|
print('DEBUG: unknown recipient of like - ' + handle)
|
||||||
# if this post in the outbox of the person?
|
# if this post in the outbox of the person?
|
||||||
messageId = messageJson['object'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['object'])
|
||||||
messageId = messageId.replace('/undo', '')
|
|
||||||
removeModerationPostFromIndex(baseDir, messageId, debug)
|
removeModerationPostFromIndex(baseDir, messageId, debug)
|
||||||
postFilename = locatePost(baseDir, handle.split('@')[0],
|
postFilename = locatePost(baseDir, handle.split('@')[0],
|
||||||
handle.split('@')[1], messageId)
|
handle.split('@')[1], messageId)
|
||||||
|
@ -1653,8 +1649,7 @@ def populateReplies(baseDir: str, httpPrefix: str, domain: str,
|
||||||
return False
|
return False
|
||||||
# populate a text file containing the ids of replies
|
# populate a text file containing the ids of replies
|
||||||
postRepliesFilename = postFilename.replace('.json', '.replies')
|
postRepliesFilename = postFilename.replace('.json', '.replies')
|
||||||
messageId = messageJson['id'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['id'])
|
||||||
messageId = messageId.replace('/undo', '')
|
|
||||||
if os.path.isfile(postRepliesFilename):
|
if os.path.isfile(postRepliesFilename):
|
||||||
numLines = sum(1 for line in open(postRepliesFilename))
|
numLines = sum(1 for line in open(postRepliesFilename))
|
||||||
if numLines > maxReplies:
|
if numLines > maxReplies:
|
||||||
|
@ -2070,8 +2065,7 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None:
|
||||||
actorNickname, actorDomain):
|
actorNickname, actorDomain):
|
||||||
return
|
return
|
||||||
|
|
||||||
postId = \
|
postId = removeIdEnding(postJsonObject['id']).replace('/', '#')
|
||||||
postJsonObject['id'].replace('/activity', '').replace('/', '#')
|
|
||||||
|
|
||||||
# look for events within the tags list
|
# look for events within the tags list
|
||||||
for tagDict in postJsonObject['object']['tag']:
|
for tagDict in postJsonObject['object']['tag']:
|
||||||
|
@ -2375,6 +2369,9 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
if isBlogPost(postJsonObject):
|
if isBlogPost(postJsonObject):
|
||||||
# blogs index will be updated
|
# blogs index will be updated
|
||||||
updateIndexList.append('tlblogs')
|
updateIndexList.append('tlblogs')
|
||||||
|
elif isEventPost(postJsonObject):
|
||||||
|
# events index will be updated
|
||||||
|
updateIndexList.append('tlevents')
|
||||||
|
|
||||||
# get the avatar for a reply/announce
|
# get the avatar for a reply/announce
|
||||||
obtainAvatarForReplyPost(session, baseDir,
|
obtainAvatarForReplyPost(session, baseDir,
|
||||||
|
|
5
like.py
5
like.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 urlPermitted
|
from utils import urlPermitted
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
|
@ -411,7 +412,7 @@ def outboxLike(recentPostsCache: {},
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s like request arrived in outbox')
|
print('DEBUG: c2s like request arrived in outbox')
|
||||||
|
|
||||||
messageId = messageJson['object'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['object'])
|
||||||
if ':' in domain:
|
if ':' in domain:
|
||||||
domain = domain.split(':')[0]
|
domain = domain.split(':')[0]
|
||||||
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
||||||
|
@ -462,7 +463,7 @@ def outboxUndoLike(recentPostsCache: {},
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s undo like request arrived in outbox')
|
print('DEBUG: c2s undo like request arrived in outbox')
|
||||||
|
|
||||||
messageId = messageJson['object']['object'].replace('/activity', '')
|
messageId = removeIdEnding(messageJson['object']['object'])
|
||||||
if ':' in domain:
|
if ':' in domain:
|
||||||
domain = domain.split(':')[0]
|
domain = domain.split(':')[0]
|
||||||
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
postFilename = locatePost(baseDir, nickname, domain, messageId)
|
||||||
|
|
11
outbox.py
11
outbox.py
|
@ -13,6 +13,7 @@ from posts import outboxMessageCreateWrap
|
||||||
from posts import savePostToBox
|
from posts import savePostToBox
|
||||||
from posts import sendToFollowersThread
|
from posts import sendToFollowersThread
|
||||||
from posts import sendToNamedAddresses
|
from posts import sendToNamedAddresses
|
||||||
|
from utils import removeIdEnding
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
from blocking import isBlockedDomain
|
from blocking import isBlockedDomain
|
||||||
from blocking import outboxBlock
|
from blocking import outboxBlock
|
||||||
|
@ -159,8 +160,7 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str,
|
||||||
' is not a permitted activity type')
|
' is not a permitted activity type')
|
||||||
return False
|
return False
|
||||||
if messageJson.get('id'):
|
if messageJson.get('id'):
|
||||||
postId = \
|
postId = removeIdEnding(messageJson['id'])
|
||||||
messageJson['id'].replace('/activity', '').replace('/undo', '')
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: id attribute exists within POST to outbox')
|
print('DEBUG: id attribute exists within POST to outbox')
|
||||||
else:
|
else:
|
||||||
|
@ -172,13 +172,15 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str,
|
||||||
if messageJson['type'] != 'Upgrade':
|
if messageJson['type'] != 'Upgrade':
|
||||||
outboxName = 'outbox'
|
outboxName = 'outbox'
|
||||||
|
|
||||||
# if this is a blog post then save to its own box
|
# if this is a blog post or an event then save to its own box
|
||||||
if messageJson['type'] == 'Create':
|
if messageJson['type'] == 'Create':
|
||||||
if messageJson.get('object'):
|
if messageJson.get('object'):
|
||||||
if isinstance(messageJson['object'], dict):
|
if isinstance(messageJson['object'], dict):
|
||||||
if messageJson['object'].get('type'):
|
if messageJson['object'].get('type'):
|
||||||
if messageJson['object']['type'] == 'Article':
|
if messageJson['object']['type'] == 'Article':
|
||||||
outboxName = 'tlblogs'
|
outboxName = 'tlblogs'
|
||||||
|
elif messageJson['object']['type'] == 'Event':
|
||||||
|
outboxName = 'tlevents'
|
||||||
|
|
||||||
savedFilename = \
|
savedFilename = \
|
||||||
savePostToBox(baseDir,
|
savePostToBox(baseDir,
|
||||||
|
@ -196,7 +198,8 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str,
|
||||||
messageJson['type'] == 'Announce':
|
messageJson['type'] == 'Announce':
|
||||||
indexes = [outboxName, "inbox"]
|
indexes = [outboxName, "inbox"]
|
||||||
for boxNameIndex in indexes:
|
for boxNameIndex in indexes:
|
||||||
if boxNameIndex == 'inbox' and outboxName == 'tlblogs':
|
if ((boxNameIndex == 'inbox') and
|
||||||
|
(outboxName == 'tlblogs' or outboxName == 'tlevents')):
|
||||||
continue
|
continue
|
||||||
selfActor = \
|
selfActor = \
|
||||||
httpPrefix + '://' + domainFull + \
|
httpPrefix + '://' + domainFull + \
|
||||||
|
|
|
@ -25,6 +25,7 @@ from posts import createRepliesTimeline
|
||||||
from posts import createMediaTimeline
|
from posts import createMediaTimeline
|
||||||
from posts import createBlogsTimeline
|
from posts import createBlogsTimeline
|
||||||
from posts import createBookmarksTimeline
|
from posts import createBookmarksTimeline
|
||||||
|
from posts import createEventsTimeline
|
||||||
from posts import createInbox
|
from posts import createInbox
|
||||||
from posts import createOutbox
|
from posts import createOutbox
|
||||||
from posts import createModeration
|
from posts import createModeration
|
||||||
|
@ -598,7 +599,8 @@ def personBoxJson(recentPostsCache: {},
|
||||||
boxname != 'tlreplies' and boxname != 'tlmedia' and \
|
boxname != 'tlreplies' and boxname != 'tlmedia' and \
|
||||||
boxname != 'tlblogs' and \
|
boxname != 'tlblogs' and \
|
||||||
boxname != 'outbox' and boxname != 'moderation' and \
|
boxname != 'outbox' and boxname != 'moderation' and \
|
||||||
boxname != 'tlbookmarks' and boxname != 'bookmarks':
|
boxname != 'tlbookmarks' and boxname != 'bookmarks' and \
|
||||||
|
boxname != 'tlevents' and boxname != 'events':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not '/' + boxname in path:
|
if not '/' + boxname in path:
|
||||||
|
@ -646,6 +648,11 @@ def personBoxJson(recentPostsCache: {},
|
||||||
port, httpPrefix,
|
port, httpPrefix,
|
||||||
noOfItems, headerOnly, ocapAlways,
|
noOfItems, headerOnly, ocapAlways,
|
||||||
pageNumber)
|
pageNumber)
|
||||||
|
elif boxname == 'tlevents' or boxname == 'events':
|
||||||
|
return createEventsTimeline(session, baseDir, nickname, domain,
|
||||||
|
port, httpPrefix,
|
||||||
|
noOfItems, headerOnly, ocapAlways,
|
||||||
|
pageNumber)
|
||||||
elif boxname == 'tlreplies':
|
elif boxname == 'tlreplies':
|
||||||
return createRepliesTimeline(session, baseDir, nickname, domain,
|
return createRepliesTimeline(session, baseDir, nickname, domain,
|
||||||
port, httpPrefix,
|
port, httpPrefix,
|
||||||
|
|
42
posts.py
42
posts.py
|
@ -29,6 +29,7 @@ from session import postJsonString
|
||||||
from session import postImage
|
from session import postImage
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from httpsig import createSignedHeader
|
from httpsig import createSignedHeader
|
||||||
|
from utils import removeIdEnding
|
||||||
from utils import siteIsActive
|
from utils import siteIsActive
|
||||||
from utils import removePostFromCache
|
from utils import removePostFromCache
|
||||||
from utils import getCachedPostFilename
|
from utils import getCachedPostFilename
|
||||||
|
@ -502,7 +503,8 @@ def deleteAllPosts(baseDir: str,
|
||||||
nickname: str, domain: str, boxname: str) -> None:
|
nickname: str, domain: str, boxname: str) -> None:
|
||||||
"""Deletes all posts for a person from inbox or outbox
|
"""Deletes all posts for a person from inbox or outbox
|
||||||
"""
|
"""
|
||||||
if boxname != 'inbox' and boxname != 'outbox' and boxname != 'tlblogs':
|
if boxname != 'inbox' and boxname != 'outbox' and \
|
||||||
|
boxname != 'tlblogs' and boxname != 'tlevents':
|
||||||
return
|
return
|
||||||
boxDir = createPersonDir(nickname, domain, baseDir, boxname)
|
boxDir = createPersonDir(nickname, domain, baseDir, boxname)
|
||||||
for deleteFilename in os.scandir(boxDir):
|
for deleteFilename in os.scandir(boxDir):
|
||||||
|
@ -524,7 +526,8 @@ def savePostToBox(baseDir: str, httpPrefix: str, postId: str,
|
||||||
Returns the filename
|
Returns the filename
|
||||||
"""
|
"""
|
||||||
if boxname != 'inbox' and boxname != 'outbox' and \
|
if boxname != 'inbox' and boxname != 'outbox' and \
|
||||||
boxname != 'tlblogs' and boxname != 'scheduled':
|
boxname != 'tlblogs' and boxname != 'tlevents' and \
|
||||||
|
boxname != 'scheduled':
|
||||||
return None
|
return None
|
||||||
originalDomain = domain
|
originalDomain = domain
|
||||||
if ':' in domain:
|
if ':' in domain:
|
||||||
|
@ -977,12 +980,15 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
|
||||||
'date and time values')
|
'date and time values')
|
||||||
return newPost
|
return newPost
|
||||||
elif saveToFile:
|
elif saveToFile:
|
||||||
if not isArticle:
|
if isArticle:
|
||||||
savePostToBox(baseDir, httpPrefix, newPostId,
|
|
||||||
nickname, domain, newPost, 'outbox')
|
|
||||||
else:
|
|
||||||
savePostToBox(baseDir, httpPrefix, newPostId,
|
savePostToBox(baseDir, httpPrefix, newPostId,
|
||||||
nickname, domain, newPost, 'tlblogs')
|
nickname, domain, newPost, 'tlblogs')
|
||||||
|
elif eventUUID:
|
||||||
|
savePostToBox(baseDir, httpPrefix, newPostId,
|
||||||
|
nickname, domain, newPost, 'tlevents')
|
||||||
|
else:
|
||||||
|
savePostToBox(baseDir, httpPrefix, newPostId,
|
||||||
|
nickname, domain, newPost, 'outbox')
|
||||||
return newPost
|
return newPost
|
||||||
|
|
||||||
|
|
||||||
|
@ -1474,7 +1480,8 @@ def createReportPost(baseDir: str,
|
||||||
|
|
||||||
# update the inbox index with the report filename
|
# update the inbox index with the report filename
|
||||||
# indexFilename = baseDir+'/accounts/'+handle+'/inbox.index'
|
# indexFilename = baseDir+'/accounts/'+handle+'/inbox.index'
|
||||||
# indexEntry=postJsonObject['id'].replace('/activity','').replace('/','#')+'.json'
|
# indexEntry = \
|
||||||
|
# removeIdEnding(postJsonObject['id']).replace('/','#') + '.json'
|
||||||
# if indexEntry not in open(indexFilename).read():
|
# if indexEntry not in open(indexFilename).read():
|
||||||
# try:
|
# try:
|
||||||
# with open(indexFilename, 'a+') as fp:
|
# with open(indexFilename, 'a+') as fp:
|
||||||
|
@ -2419,6 +2426,16 @@ def createBookmarksTimeline(session, baseDir: str, nickname: str, domain: str,
|
||||||
True, ocapAlways, pageNumber)
|
True, ocapAlways, pageNumber)
|
||||||
|
|
||||||
|
|
||||||
|
def createEventsTimeline(session, baseDir: str, nickname: str, domain: str,
|
||||||
|
port: int, httpPrefix: str, itemsPerPage: int,
|
||||||
|
headerOnly: bool, ocapAlways: bool,
|
||||||
|
pageNumber=None) -> {}:
|
||||||
|
return createBoxIndexed({}, session, baseDir, 'tlevents',
|
||||||
|
nickname, domain,
|
||||||
|
port, httpPrefix, itemsPerPage, headerOnly,
|
||||||
|
True, ocapAlways, pageNumber)
|
||||||
|
|
||||||
|
|
||||||
def createDMTimeline(session, baseDir: str, nickname: str, domain: str,
|
def createDMTimeline(session, baseDir: str, nickname: str, domain: str,
|
||||||
port: int, httpPrefix: str, itemsPerPage: int,
|
port: int, httpPrefix: str, itemsPerPage: int,
|
||||||
headerOnly: bool, ocapAlways: bool,
|
headerOnly: bool, ocapAlways: bool,
|
||||||
|
@ -2791,14 +2808,19 @@ def createBoxIndexed(recentPostsCache: {},
|
||||||
boxname != 'tlreplies' and boxname != 'tlmedia' and \
|
boxname != 'tlreplies' and boxname != 'tlmedia' and \
|
||||||
boxname != 'tlblogs' and \
|
boxname != 'tlblogs' and \
|
||||||
boxname != 'outbox' and boxname != 'tlbookmarks' and \
|
boxname != 'outbox' and boxname != 'tlbookmarks' and \
|
||||||
boxname != 'bookmarks':
|
boxname != 'bookmarks' and \
|
||||||
|
boxname != 'tlevents' and boxname != 'events':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# bookmarks timeline is like the inbox but has its own separate index
|
# bookmarks and events timelines are like the inbox
|
||||||
|
# but have their own separate index
|
||||||
indexBoxName = boxname
|
indexBoxName = boxname
|
||||||
if boxname == "tlbookmarks":
|
if boxname == "tlbookmarks":
|
||||||
boxname = "bookmarks"
|
boxname = "bookmarks"
|
||||||
indexBoxName = boxname
|
indexBoxName = boxname
|
||||||
|
elif boxname == "tlevents":
|
||||||
|
boxname = "events"
|
||||||
|
indexBoxName = boxname
|
||||||
|
|
||||||
if port:
|
if port:
|
||||||
if port != 80 and port != 443:
|
if port != 80 and port != 443:
|
||||||
|
@ -3489,7 +3511,7 @@ def mutePost(baseDir: str, nickname: str, domain: str, postId: str,
|
||||||
# if the post is in the recent posts cache then mark it as muted
|
# if the post is in the recent posts cache then mark it as muted
|
||||||
if recentPostsCache.get('index'):
|
if recentPostsCache.get('index'):
|
||||||
postId = \
|
postId = \
|
||||||
postJsonObject['id'].replace('/activity', '').replace('/', '#')
|
removeIdEnding(postJsonObject['id']).replace('/', '#')
|
||||||
if postId in recentPostsCache['index']:
|
if postId in recentPostsCache['index']:
|
||||||
print('MUTE: ' + postId + ' is in recent posts cache')
|
print('MUTE: ' + postId + ' is in recent posts cache')
|
||||||
if recentPostsCache['json'].get(postId):
|
if recentPostsCache['json'].get(postId):
|
||||||
|
|
30
tests.py
30
tests.py
|
@ -31,6 +31,7 @@ from follow import clearFollows
|
||||||
from follow import clearFollowers
|
from follow import clearFollowers
|
||||||
from follow import sendFollowRequestViaServer
|
from follow import sendFollowRequestViaServer
|
||||||
from follow import sendUnfollowRequestViaServer
|
from follow import sendUnfollowRequestViaServer
|
||||||
|
from utils import removeIdEnding
|
||||||
from utils import siteIsActive
|
from utils import siteIsActive
|
||||||
from utils import updateRecentPostsCache
|
from utils import updateRecentPostsCache
|
||||||
from utils import followPerson
|
from utils import followPerson
|
||||||
|
@ -1364,7 +1365,7 @@ def testClientToServer():
|
||||||
outboxPostFilename = outboxPath + '/' + name
|
outboxPostFilename = outboxPath + '/' + name
|
||||||
postJsonObject = loadJson(outboxPostFilename, 0)
|
postJsonObject = loadJson(outboxPostFilename, 0)
|
||||||
if postJsonObject:
|
if postJsonObject:
|
||||||
outboxPostId = postJsonObject['id'].replace('/activity', '')
|
outboxPostId = removeIdEnding(postJsonObject['id'])
|
||||||
assert outboxPostId
|
assert outboxPostId
|
||||||
print('message id obtained: ' + outboxPostId)
|
print('message id obtained: ' + outboxPostId)
|
||||||
assert validInbox(bobDir, 'bob', bobDomain)
|
assert validInbox(bobDir, 'bob', bobDomain)
|
||||||
|
@ -2014,8 +2015,35 @@ def testJsonPostAllowsComments():
|
||||||
assert not jsonPostAllowsComments(postJsonObject)
|
assert not jsonPostAllowsComments(postJsonObject)
|
||||||
|
|
||||||
|
|
||||||
|
def testRemoveIdEnding():
|
||||||
|
print('testRemoveIdEnding')
|
||||||
|
testStr = 'https://activitypub.somedomain.net'
|
||||||
|
resultStr = removeIdEnding(testStr)
|
||||||
|
assert resultStr == 'https://activitypub.somedomain.net'
|
||||||
|
|
||||||
|
testStr = \
|
||||||
|
'https://activitypub.somedomain.net/users/foo/' + \
|
||||||
|
'statuses/34544814814/activity'
|
||||||
|
resultStr = removeIdEnding(testStr)
|
||||||
|
assert resultStr == \
|
||||||
|
'https://activitypub.somedomain.net/users/foo/statuses/34544814814'
|
||||||
|
|
||||||
|
testStr = \
|
||||||
|
'https://undo.somedomain.net/users/foo/statuses/34544814814/undo'
|
||||||
|
resultStr = removeIdEnding(testStr)
|
||||||
|
assert resultStr == \
|
||||||
|
'https://undo.somedomain.net/users/foo/statuses/34544814814'
|
||||||
|
|
||||||
|
testStr = \
|
||||||
|
'https://event.somedomain.net/users/foo/statuses/34544814814/event'
|
||||||
|
resultStr = removeIdEnding(testStr)
|
||||||
|
assert resultStr == \
|
||||||
|
'https://event.somedomain.net/users/foo/statuses/34544814814'
|
||||||
|
|
||||||
|
|
||||||
def runAllTests():
|
def runAllTests():
|
||||||
print('Running tests...')
|
print('Running tests...')
|
||||||
|
testRemoveIdEnding()
|
||||||
testJsonPostAllowsComments()
|
testJsonPostAllowsComments()
|
||||||
runHtmlReplaceQuoteMarks()
|
runHtmlReplaceQuoteMarks()
|
||||||
testDangerousMarkup()
|
testDangerousMarkup()
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "ملاحظات",
|
"Notes": "ملاحظات",
|
||||||
"Allow replies.": "السماح بالردود.",
|
"Allow replies.": "السماح بالردود.",
|
||||||
"Event": "حدث",
|
"Event": "حدث",
|
||||||
|
"Events": "الأحداث",
|
||||||
"Create an event": "أنشئ حدثًا",
|
"Create an event": "أنشئ حدثًا",
|
||||||
"Describe the event": "صف الحدث",
|
"Describe the event": "صف الحدث",
|
||||||
"Start Date": "تاريخ البدء",
|
"Start Date": "تاريخ البدء",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Notes",
|
"Notes": "Notes",
|
||||||
"Allow replies.": "Permetre respostes.",
|
"Allow replies.": "Permetre respostes.",
|
||||||
"Event": "Esdeveniment",
|
"Event": "Esdeveniment",
|
||||||
|
"Events": "Esdeveniments",
|
||||||
"Create an event": "Crea un esdeveniment",
|
"Create an event": "Crea un esdeveniment",
|
||||||
"Describe the event": "Descriviu l’esdeveniment",
|
"Describe the event": "Descriviu l’esdeveniment",
|
||||||
"Start Date": "Data d'inici",
|
"Start Date": "Data d'inici",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Nodiadau",
|
"Notes": "Nodiadau",
|
||||||
"Allow replies.": "Caniatáu atebion.",
|
"Allow replies.": "Caniatáu atebion.",
|
||||||
"Event": "Digwyddiad",
|
"Event": "Digwyddiad",
|
||||||
|
"Events": "Digwyddiadau",
|
||||||
"Create an event": "Creu digwyddiad",
|
"Create an event": "Creu digwyddiad",
|
||||||
"Describe the event": "Disgrifiwch y digwyddiad",
|
"Describe the event": "Disgrifiwch y digwyddiad",
|
||||||
"Start Date": "Dyddiad cychwyn",
|
"Start Date": "Dyddiad cychwyn",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Anmerkungen",
|
"Notes": "Anmerkungen",
|
||||||
"Allow replies.": "Antworten zulassen.",
|
"Allow replies.": "Antworten zulassen.",
|
||||||
"Event": "Veranstaltung",
|
"Event": "Veranstaltung",
|
||||||
|
"Events": "Veranstaltungen",
|
||||||
"Create an event": "Erstellen Sie ein Ereignis",
|
"Create an event": "Erstellen Sie ein Ereignis",
|
||||||
"Describe the event": "Beschreiben Sie das Ereignis",
|
"Describe the event": "Beschreiben Sie das Ereignis",
|
||||||
"Start Date": "Anfangsdatum",
|
"Start Date": "Anfangsdatum",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Notes",
|
"Notes": "Notes",
|
||||||
"Allow replies.": "Allow replies.",
|
"Allow replies.": "Allow replies.",
|
||||||
"Event": "Event",
|
"Event": "Event",
|
||||||
|
"Events": "Events",
|
||||||
"Create an event": "Create an event",
|
"Create an event": "Create an event",
|
||||||
"Describe the event": "Describe the event",
|
"Describe the event": "Describe the event",
|
||||||
"Start Date": "Start Date",
|
"Start Date": "Start Date",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Notas",
|
"Notes": "Notas",
|
||||||
"Allow replies.": "Permitir respuestas.",
|
"Allow replies.": "Permitir respuestas.",
|
||||||
"Event": "Evento",
|
"Event": "Evento",
|
||||||
|
"Events": "Eventos",
|
||||||
"Create an event": "Crea un evento",
|
"Create an event": "Crea un evento",
|
||||||
"Describe the event": "Describe el evento",
|
"Describe the event": "Describe el evento",
|
||||||
"Start Date": "Fecha de inicio",
|
"Start Date": "Fecha de inicio",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Remarques",
|
"Notes": "Remarques",
|
||||||
"Allow replies.": "Autoriser les réponses.",
|
"Allow replies.": "Autoriser les réponses.",
|
||||||
"Event": "un événement",
|
"Event": "un événement",
|
||||||
|
"Events": "Événements",
|
||||||
"Create an event": "Créer un événement",
|
"Create an event": "Créer un événement",
|
||||||
"Describe the event": "Décrivez l'événement",
|
"Describe the event": "Décrivez l'événement",
|
||||||
"Start Date": "Date de début",
|
"Start Date": "Date de début",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Nótaí",
|
"Notes": "Nótaí",
|
||||||
"Allow replies.": "Ceadaigh freagraí.",
|
"Allow replies.": "Ceadaigh freagraí.",
|
||||||
"Event": "Imeacht",
|
"Event": "Imeacht",
|
||||||
|
"Events": "Imeachtaí",
|
||||||
"Create an event": "Cruthaigh imeacht",
|
"Create an event": "Cruthaigh imeacht",
|
||||||
"Describe the event": "Déan cur síos ar an ócáid",
|
"Describe the event": "Déan cur síos ar an ócáid",
|
||||||
"Start Date": "Dáta tosaigh",
|
"Start Date": "Dáta tosaigh",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "टिप्पणियाँ",
|
"Notes": "टिप्पणियाँ",
|
||||||
"Allow replies.": "जवाब दें।",
|
"Allow replies.": "जवाब दें।",
|
||||||
"Event": "प्रतिस्पर्धा",
|
"Event": "प्रतिस्पर्धा",
|
||||||
|
"Events": "आयोजन",
|
||||||
"Create an event": "एक घटना बनाएँ",
|
"Create an event": "एक घटना बनाएँ",
|
||||||
"Describe the event": "घटना का वर्णन करें",
|
"Describe the event": "घटना का वर्णन करें",
|
||||||
"Start Date": "आरंभ करने की तिथि",
|
"Start Date": "आरंभ करने की तिथि",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Appunti",
|
"Notes": "Appunti",
|
||||||
"Allow replies.": "Consenti risposte.",
|
"Allow replies.": "Consenti risposte.",
|
||||||
"Event": "Evento",
|
"Event": "Evento",
|
||||||
|
"Events": "Eventi",
|
||||||
"Create an event": "Crea un evento",
|
"Create an event": "Crea un evento",
|
||||||
"Describe the event": "Descrivi l'evento",
|
"Describe the event": "Descrivi l'evento",
|
||||||
"Start Date": "Data d'inizio",
|
"Start Date": "Data d'inizio",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "ノート",
|
"Notes": "ノート",
|
||||||
"Allow replies.": "返信を許可します。",
|
"Allow replies.": "返信を許可します。",
|
||||||
"Event": "イベント",
|
"Event": "イベント",
|
||||||
|
"Events": "イベント",
|
||||||
"Create an event": "イベントを作成する",
|
"Create an event": "イベントを作成する",
|
||||||
"Describe the event": "イベントについて説明する",
|
"Describe the event": "イベントについて説明する",
|
||||||
"Start Date": "開始日",
|
"Start Date": "開始日",
|
||||||
|
|
|
@ -254,6 +254,7 @@
|
||||||
"Notes": "Notes",
|
"Notes": "Notes",
|
||||||
"Allow replies.": "Allow replies.",
|
"Allow replies.": "Allow replies.",
|
||||||
"Event": "Event",
|
"Event": "Event",
|
||||||
|
"Events": "Events",
|
||||||
"Create an event": "Create an event",
|
"Create an event": "Create an event",
|
||||||
"Describe the event": "Describe the event",
|
"Describe the event": "Describe the event",
|
||||||
"Start Date": "Start Date",
|
"Start Date": "Start Date",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Notas",
|
"Notes": "Notas",
|
||||||
"Allow replies.": "Permitir respostas.",
|
"Allow replies.": "Permitir respostas.",
|
||||||
"Event": "Evento",
|
"Event": "Evento",
|
||||||
|
"Events": "Eventos",
|
||||||
"Create an event": "Crie um evento",
|
"Create an event": "Crie um evento",
|
||||||
"Describe the event": "Descreva o evento",
|
"Describe the event": "Descreva o evento",
|
||||||
"Start Date": "Data de início",
|
"Start Date": "Data de início",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "Ноты",
|
"Notes": "Ноты",
|
||||||
"Allow replies.": "Разрешить ответы.",
|
"Allow replies.": "Разрешить ответы.",
|
||||||
"Event": "Мероприятие",
|
"Event": "Мероприятие",
|
||||||
|
"Events": "События",
|
||||||
"Create an event": "Создать мероприятие",
|
"Create an event": "Создать мероприятие",
|
||||||
"Describe the event": "Опишите событие",
|
"Describe the event": "Опишите событие",
|
||||||
"Start Date": "Дата начала",
|
"Start Date": "Дата начала",
|
||||||
|
|
|
@ -258,6 +258,7 @@
|
||||||
"Notes": "笔记",
|
"Notes": "笔记",
|
||||||
"Allow replies.": "允许回复。",
|
"Allow replies.": "允许回复。",
|
||||||
"Event": "事件",
|
"Event": "事件",
|
||||||
|
"Events": "大事记",
|
||||||
"Create an event": "建立活动",
|
"Create an event": "建立活动",
|
||||||
"Describe the event": "描述事件",
|
"Describe the event": "描述事件",
|
||||||
"Start Date": "开始日期",
|
"Start Date": "开始日期",
|
||||||
|
|
35
utils.py
35
utils.py
|
@ -19,6 +19,18 @@ from calendar import monthrange
|
||||||
from followingCalendar import addPersonToCalendar
|
from followingCalendar import addPersonToCalendar
|
||||||
|
|
||||||
|
|
||||||
|
def removeIdEnding(idStr: str) -> str:
|
||||||
|
"""Removes endings such as /activity and /undo
|
||||||
|
"""
|
||||||
|
if idStr.endswith('/activity'):
|
||||||
|
idStr = idStr[:-len('/activity')]
|
||||||
|
elif idStr.endswith('/undo'):
|
||||||
|
idStr = idStr[:-len('/undo')]
|
||||||
|
elif idStr.endswith('/event'):
|
||||||
|
idStr = idStr[:-len('/event')]
|
||||||
|
return idStr
|
||||||
|
|
||||||
|
|
||||||
def getProtocolPrefixes() -> []:
|
def getProtocolPrefixes() -> []:
|
||||||
"""Returns a list of valid prefixes
|
"""Returns a list of valid prefixes
|
||||||
"""
|
"""
|
||||||
|
@ -384,13 +396,13 @@ def locatePost(baseDir: str, nickname: str, domain: str,
|
||||||
extension = 'replies'
|
extension = 'replies'
|
||||||
|
|
||||||
# if this post in the shared inbox?
|
# if this post in the shared inbox?
|
||||||
postUrl = postUrl.replace('/', '#').replace('/activity', '').strip()
|
postUrl = removeIdEnding(postUrl.strip()).replace('/', '#')
|
||||||
|
|
||||||
# add the extension
|
# add the extension
|
||||||
postUrl = postUrl + '.' + extension
|
postUrl = postUrl + '.' + extension
|
||||||
|
|
||||||
# search boxes
|
# search boxes
|
||||||
boxes = ('inbox', 'outbox', 'tlblogs')
|
boxes = ('inbox', 'outbox', 'tlblogs', 'tlevents')
|
||||||
accountDir = baseDir + '/accounts/' + nickname + '@' + domain + '/'
|
accountDir = baseDir + '/accounts/' + nickname + '@' + domain + '/'
|
||||||
for boxName in boxes:
|
for boxName in boxes:
|
||||||
postFilename = accountDir + boxName + '/' + postUrl
|
postFilename = accountDir + boxName + '/' + postUrl
|
||||||
|
@ -435,7 +447,7 @@ def removeModerationPostFromIndex(baseDir: str, postUrl: str,
|
||||||
moderationIndexFile = baseDir + '/accounts/moderation.txt'
|
moderationIndexFile = baseDir + '/accounts/moderation.txt'
|
||||||
if not os.path.isfile(moderationIndexFile):
|
if not os.path.isfile(moderationIndexFile):
|
||||||
return
|
return
|
||||||
postId = postUrl.replace('/activity', '')
|
postId = removeIdEnding(postUrl)
|
||||||
if postId in open(moderationIndexFile).read():
|
if postId in open(moderationIndexFile).read():
|
||||||
with open(moderationIndexFile, "r") as f:
|
with open(moderationIndexFile, "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
@ -463,7 +475,7 @@ def isReplyToBlogPost(baseDir: str, nickname: str, domain: str,
|
||||||
nickname + '@' + domain + '/tlblogs.index'
|
nickname + '@' + domain + '/tlblogs.index'
|
||||||
if not os.path.isfile(blogsIndexFilename):
|
if not os.path.isfile(blogsIndexFilename):
|
||||||
return False
|
return False
|
||||||
postId = postJsonObject['object']['inReplyTo'].replace('/activity', '')
|
postId = removeIdEnding(postJsonObject['object']['inReplyTo'])
|
||||||
postId = postId.replace('/', '#')
|
postId = postId.replace('/', '#')
|
||||||
if postId in open(blogsIndexFilename).read():
|
if postId in open(blogsIndexFilename).read():
|
||||||
return True
|
return True
|
||||||
|
@ -494,7 +506,7 @@ def deletePost(baseDir: str, httpPrefix: str,
|
||||||
# remove from recent posts cache in memory
|
# remove from recent posts cache in memory
|
||||||
if recentPostsCache:
|
if recentPostsCache:
|
||||||
postId = \
|
postId = \
|
||||||
postJsonObject['id'].replace('/activity', '').replace('/', '#')
|
removeIdEnding(postJsonObject['id']).replace('/', '#')
|
||||||
if recentPostsCache.get('index'):
|
if recentPostsCache.get('index'):
|
||||||
if postId in recentPostsCache['index']:
|
if postId in recentPostsCache['index']:
|
||||||
recentPostsCache['index'].remove(postId)
|
recentPostsCache['index'].remove(postId)
|
||||||
|
@ -526,7 +538,7 @@ def deletePost(baseDir: str, httpPrefix: str,
|
||||||
if isinstance(postJsonObject['object'], dict):
|
if isinstance(postJsonObject['object'], dict):
|
||||||
if postJsonObject['object'].get('moderationStatus'):
|
if postJsonObject['object'].get('moderationStatus'):
|
||||||
if postJsonObject.get('id'):
|
if postJsonObject.get('id'):
|
||||||
postId = postJsonObject['id'].replace('/activity', '')
|
postId = removeIdEnding(postJsonObject['id'])
|
||||||
removeModerationPostFromIndex(baseDir, postId, debug)
|
removeModerationPostFromIndex(baseDir, postId, debug)
|
||||||
|
|
||||||
# remove any hashtags index entries
|
# remove any hashtags index entries
|
||||||
|
@ -540,8 +552,7 @@ def deletePost(baseDir: str, httpPrefix: str,
|
||||||
if postJsonObject['object'].get('id') and \
|
if postJsonObject['object'].get('id') and \
|
||||||
postJsonObject['object'].get('tag'):
|
postJsonObject['object'].get('tag'):
|
||||||
# get the id of the post
|
# get the id of the post
|
||||||
postId = \
|
postId = removeIdEnding(postJsonObject['object']['id'])
|
||||||
postJsonObject['object']['id'].replace('/activity', '')
|
|
||||||
for tag in postJsonObject['object']['tag']:
|
for tag in postJsonObject['object']['tag']:
|
||||||
if tag['type'] != 'Hashtag':
|
if tag['type'] != 'Hashtag':
|
||||||
continue
|
continue
|
||||||
|
@ -710,7 +721,7 @@ def getCachedPostFilename(baseDir: str, nickname: str, domain: str,
|
||||||
return None
|
return None
|
||||||
cachedPostFilename = \
|
cachedPostFilename = \
|
||||||
cachedPostDir + \
|
cachedPostDir + \
|
||||||
'/' + postJsonObject['id'].replace('/activity', '').replace('/', '#')
|
'/' + removeIdEnding(postJsonObject['id']).replace('/', '#')
|
||||||
cachedPostFilename = cachedPostFilename + '.html'
|
cachedPostFilename = cachedPostFilename + '.html'
|
||||||
return cachedPostFilename
|
return cachedPostFilename
|
||||||
|
|
||||||
|
@ -727,7 +738,7 @@ def removePostFromCache(postJsonObject: {}, recentPostsCache: {}):
|
||||||
postId = postJsonObject['id']
|
postId = postJsonObject['id']
|
||||||
if '#' in postId:
|
if '#' in postId:
|
||||||
postId = postId.split('#', 1)[0]
|
postId = postId.split('#', 1)[0]
|
||||||
postId = postId.replace('/activity', '').replace('/', '#')
|
postId = removeIdEnding(postId).replace('/', '#')
|
||||||
if postId not in recentPostsCache['index']:
|
if postId not in recentPostsCache['index']:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -747,7 +758,7 @@ def updateRecentPostsCache(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
postId = postJsonObject['id']
|
postId = postJsonObject['id']
|
||||||
if '#' in postId:
|
if '#' in postId:
|
||||||
postId = postId.split('#', 1)[0]
|
postId = postId.split('#', 1)[0]
|
||||||
postId = postId.replace('/activity', '').replace('/', '#')
|
postId = removeIdEnding(postId).replace('/', '#')
|
||||||
if recentPostsCache.get('index'):
|
if recentPostsCache.get('index'):
|
||||||
if postId in recentPostsCache['index']:
|
if postId in recentPostsCache['index']:
|
||||||
return
|
return
|
||||||
|
@ -1071,7 +1082,7 @@ def updateAnnounceCollection(recentPostsCache: {},
|
||||||
return
|
return
|
||||||
if not isinstance(postJsonObject['object'], dict):
|
if not isinstance(postJsonObject['object'], dict):
|
||||||
return
|
return
|
||||||
postUrl = postJsonObject['id'].replace('/activity', '') + '/shares'
|
postUrl = removeIdEnding(postJsonObject['id']) + '/shares'
|
||||||
if not postJsonObject['object'].get('shares'):
|
if not postJsonObject['object'].get('shares'):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Adding initial shares (announcements) to ' +
|
print('DEBUG: Adding initial shares (announcements) to ' +
|
||||||
|
|
|
@ -25,6 +25,7 @@ from ssb import getSSBAddress
|
||||||
from tox import getToxAddress
|
from tox import getToxAddress
|
||||||
from matrix import getMatrixAddress
|
from matrix import getMatrixAddress
|
||||||
from donate import getDonationUrl
|
from donate import getDonationUrl
|
||||||
|
from utils import removeIdEnding
|
||||||
from utils import getProtocolPrefixes
|
from utils import getProtocolPrefixes
|
||||||
from utils import getFileCaseInsensitive
|
from utils import getFileCaseInsensitive
|
||||||
from utils import searchBoxPosts
|
from utils import searchBoxPosts
|
||||||
|
@ -3313,7 +3314,7 @@ def insertQuestion(baseDir: str, translate: {},
|
||||||
return content
|
return content
|
||||||
if len(postJsonObject['object']['oneOf']) == 0:
|
if len(postJsonObject['object']['oneOf']) == 0:
|
||||||
return content
|
return content
|
||||||
messageId = postJsonObject['id'].replace('/activity', '')
|
messageId = removeIdEnding(postJsonObject['id'])
|
||||||
if '#' in messageId:
|
if '#' in messageId:
|
||||||
messageId = messageId.split('#', 1)[0]
|
messageId = messageId.split('#', 1)[0]
|
||||||
pageNumberStr = ''
|
pageNumberStr = ''
|
||||||
|
@ -3781,7 +3782,7 @@ def individualPostAsHtml(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
avatarPosition = ''
|
avatarPosition = ''
|
||||||
messageId = ''
|
messageId = ''
|
||||||
if postJsonObject.get('id'):
|
if postJsonObject.get('id'):
|
||||||
messageId = postJsonObject['id'].replace('/activity', '')
|
messageId = removeIdEnding(postJsonObject['id'])
|
||||||
|
|
||||||
messageIdStr = ''
|
messageIdStr = ''
|
||||||
if messageId:
|
if messageId:
|
||||||
|
@ -3870,7 +3871,7 @@ def individualPostAsHtml(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
if boxName == 'tlbookmarks' or boxName == 'bookmarks':
|
if boxName == 'tlbookmarks' or boxName == 'bookmarks':
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
timelinePostBookmark = postJsonObject['id'].replace('/activity', '')
|
timelinePostBookmark = removeIdEnding(postJsonObject['id'])
|
||||||
timelinePostBookmark = timelinePostBookmark.replace('://', '-')
|
timelinePostBookmark = timelinePostBookmark.replace('://', '-')
|
||||||
timelinePostBookmark = timelinePostBookmark.replace('/', '-')
|
timelinePostBookmark = timelinePostBookmark.replace('/', '-')
|
||||||
|
|
||||||
|
@ -4007,8 +4008,8 @@ def individualPostAsHtml(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
|
|
||||||
editStr = ''
|
editStr = ''
|
||||||
if fullDomain + '/users/' + nickname in postJsonObject['actor']:
|
if fullDomain + '/users/' + nickname in postJsonObject['actor']:
|
||||||
if isBlogPost(postJsonObject):
|
|
||||||
if '/statuses/' in postJsonObject['object']['id']:
|
if '/statuses/' in postJsonObject['object']['id']:
|
||||||
|
if isBlogPost(postJsonObject):
|
||||||
editStr += \
|
editStr += \
|
||||||
'<a class="imageAnchor" href="/users/' + nickname + \
|
'<a class="imageAnchor" href="/users/' + nickname + \
|
||||||
'/tlblogs?editblogpost=' + \
|
'/tlblogs?editblogpost=' + \
|
||||||
|
@ -4629,6 +4630,7 @@ def htmlTimeline(defaultTimeline: str,
|
||||||
repliesButton = 'buttonhighlighted'
|
repliesButton = 'buttonhighlighted'
|
||||||
mediaButton = 'button'
|
mediaButton = 'button'
|
||||||
bookmarksButton = 'button'
|
bookmarksButton = 'button'
|
||||||
|
eventsButton = 'button'
|
||||||
sentButton = 'button'
|
sentButton = 'button'
|
||||||
sharesButton = 'button'
|
sharesButton = 'button'
|
||||||
if newShare:
|
if newShare:
|
||||||
|
@ -4662,6 +4664,8 @@ def htmlTimeline(defaultTimeline: str,
|
||||||
sharesButton = 'buttonselectedhighlighted'
|
sharesButton = 'buttonselectedhighlighted'
|
||||||
elif boxName == 'tlbookmarks' or boxName == 'bookmarks':
|
elif boxName == 'tlbookmarks' or boxName == 'bookmarks':
|
||||||
bookmarksButton = 'buttonselected'
|
bookmarksButton = 'buttonselected'
|
||||||
|
elif boxName == 'tlevents' or boxName == 'events':
|
||||||
|
eventsButton = 'buttonselected'
|
||||||
|
|
||||||
fullDomain = domain
|
fullDomain = domain
|
||||||
if port != 80 and port != 443:
|
if port != 80 and port != 443:
|
||||||
|
@ -4702,6 +4706,7 @@ def htmlTimeline(defaultTimeline: str,
|
||||||
|
|
||||||
sharesButtonStr = ''
|
sharesButtonStr = ''
|
||||||
bookmarksButtonStr = ''
|
bookmarksButtonStr = ''
|
||||||
|
eventsButtonStr = ''
|
||||||
if not minimal:
|
if not minimal:
|
||||||
sharesButtonStr = \
|
sharesButtonStr = \
|
||||||
'<a href="' + usersPath + '/tlshares"><button class="' + \
|
'<a href="' + usersPath + '/tlshares"><button class="' + \
|
||||||
|
@ -4714,6 +4719,11 @@ def htmlTimeline(defaultTimeline: str,
|
||||||
bookmarksButton + '"><span>' + translate['Bookmarks'] + \
|
bookmarksButton + '"><span>' + translate['Bookmarks'] + \
|
||||||
' </span></button></a>\n'
|
' </span></button></a>\n'
|
||||||
|
|
||||||
|
eventsButtonStr = \
|
||||||
|
'<a href="' + usersPath + '/tlevents"><button class="' + \
|
||||||
|
eventsButton + '"><span>' + translate['Events'] + \
|
||||||
|
' </span></button></a>\n'
|
||||||
|
|
||||||
tlStr = htmlHeader(cssFilename, profileStyle)
|
tlStr = htmlHeader(cssFilename, profileStyle)
|
||||||
|
|
||||||
if boxName != 'dm':
|
if boxName != 'dm':
|
||||||
|
@ -4835,7 +4845,7 @@ def htmlTimeline(defaultTimeline: str,
|
||||||
sentButton+'"><span>' + translate['Outbox'] + \
|
sentButton+'"><span>' + translate['Outbox'] + \
|
||||||
'</span></button></a>\n'
|
'</span></button></a>\n'
|
||||||
tlStr += \
|
tlStr += \
|
||||||
sharesButtonStr + bookmarksButtonStr + \
|
sharesButtonStr + bookmarksButtonStr + eventsButtonStr + \
|
||||||
moderationButtonStr + newPostButtonStr
|
moderationButtonStr + newPostButtonStr
|
||||||
tlStr += \
|
tlStr += \
|
||||||
' <a class="imageAnchor" href="' + usersPath + \
|
' <a class="imageAnchor" href="' + usersPath + \
|
||||||
|
@ -4963,7 +4973,7 @@ def htmlTimeline(defaultTimeline: str,
|
||||||
if boxName != 'tlmedia' and \
|
if boxName != 'tlmedia' and \
|
||||||
recentPostsCache.get('index'):
|
recentPostsCache.get('index'):
|
||||||
postId = \
|
postId = \
|
||||||
item['id'].replace('/activity', '').replace('/', '#')
|
removeIdEnding(item['id']).replace('/', '#')
|
||||||
if postId in recentPostsCache['index']:
|
if postId in recentPostsCache['index']:
|
||||||
if not item.get('muted'):
|
if not item.get('muted'):
|
||||||
if recentPostsCache['html'].get(postId):
|
if recentPostsCache['html'].get(postId):
|
||||||
|
@ -5075,6 +5085,28 @@ def htmlBookmarks(defaultTimeline: str,
|
||||||
minimal, YTReplacementDomain)
|
minimal, YTReplacementDomain)
|
||||||
|
|
||||||
|
|
||||||
|
def htmlEvents(defaultTimeline: str,
|
||||||
|
recentPostsCache: {}, maxRecentPosts: int,
|
||||||
|
translate: {}, pageNumber: int, itemsPerPage: int,
|
||||||
|
session, baseDir: str, wfRequest: {}, personCache: {},
|
||||||
|
nickname: str, domain: str, port: int, bookmarksJson: {},
|
||||||
|
allowDeletion: bool,
|
||||||
|
httpPrefix: str, projectVersion: str,
|
||||||
|
minimal: bool, YTReplacementDomain: str) -> str:
|
||||||
|
"""Show the events as html
|
||||||
|
"""
|
||||||
|
manuallyApproveFollowers = \
|
||||||
|
followerApprovalActive(baseDir, nickname, domain)
|
||||||
|
|
||||||
|
return htmlTimeline(defaultTimeline, recentPostsCache, maxRecentPosts,
|
||||||
|
translate, pageNumber,
|
||||||
|
itemsPerPage, session, baseDir, wfRequest, personCache,
|
||||||
|
nickname, domain, port, bookmarksJson,
|
||||||
|
'tlevents', allowDeletion,
|
||||||
|
httpPrefix, projectVersion, manuallyApproveFollowers,
|
||||||
|
minimal, YTReplacementDomain)
|
||||||
|
|
||||||
|
|
||||||
def htmlInboxDMs(defaultTimeline: str,
|
def htmlInboxDMs(defaultTimeline: str,
|
||||||
recentPostsCache: {}, maxRecentPosts: int,
|
recentPostsCache: {}, maxRecentPosts: int,
|
||||||
translate: {}, pageNumber: int, itemsPerPage: int,
|
translate: {}, pageNumber: int, itemsPerPage: int,
|
||||||
|
@ -5238,7 +5270,7 @@ def htmlIndividualPost(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
httpPrefix, projectVersion, 'inbox',
|
httpPrefix, projectVersion, 'inbox',
|
||||||
YTReplacementDomain,
|
YTReplacementDomain,
|
||||||
False, authorized, False, False, False)
|
False, authorized, False, False, False)
|
||||||
messageId = postJsonObject['id'].replace('/activity', '')
|
messageId = removeIdEnding(postJsonObject['id'])
|
||||||
|
|
||||||
# show the previous posts
|
# show the previous posts
|
||||||
if isinstance(postJsonObject['object'], dict):
|
if isinstance(postJsonObject['object'], dict):
|
||||||
|
|
Loading…
Reference in New Issue