merge-requests/30/head
Bob Mottram 2021-10-11 10:42:43 +01:00
parent 7047fe4307
commit 179f36b529
3 changed files with 26 additions and 43 deletions

View File

@ -20,6 +20,23 @@ validContexts = (
) )
def getIndividualPostContext() -> []:
"""Returns the context for an individual post
"""
return [
'https://www.w3.org/ns/activitystreams',
{
"ostatus": "http://ostatus.org#",
"atomUri": "ostatus:atomUri",
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
"conversation": "ostatus:conversation",
"sensitive": "as:sensitive",
"toot": "http://joinmastodon.org/ns#",
"votersCount": "toot:votersCount"
}
]
def hasValidContext(postJsonObject: {}) -> bool: def hasValidContext(postJsonObject: {}) -> bool:
"""Are the links within the @context of a post recognised? """Are the links within the @context of a post recognised?
""" """

View File

@ -341,6 +341,7 @@ from filters import isFiltered
from filters import addGlobalFilter from filters import addGlobalFilter
from filters import removeGlobalFilter from filters import removeGlobalFilter
from context import hasValidContext from context import hasValidContext
from context import getIndividualPostContext
from speaker import getSSMLbox from speaker import getSSMLbox
from city import getSpoofedCity from city import getSpoofedCity
import os import os
@ -8757,18 +8758,8 @@ class PubServer(BaseHTTPRequestHandler):
postJsonObject['type'] == 'Create' and \ postJsonObject['type'] == 'Create' and \
hasObjectDict(postJsonObject): hasObjectDict(postJsonObject):
unwrappedJson = postJsonObject['object'] unwrappedJson = postJsonObject['object']
unwrappedJson['@context'] = [ unwrappedJson['@context'] = \
'https://www.w3.org/ns/activitystreams', getIndividualPostContext()
{
'atomUri': 'ostatus:atomUri',
'conversation': 'ostatus:conversation',
'inReplyToAtomUri': 'ostatus:inReplyToAtomUri',
'ostatus': 'http://ostatus.org#',
'sensitive': 'as:sensitive',
'toot': 'http://joinmastodon.org/ns#',
'votersCount': 'toot:votersCount'
}
]
msg = json.dumps(unwrappedJson, msg = json.dumps(unwrappedJson,
ensure_ascii=False) ensure_ascii=False)
else: else:
@ -10791,14 +10782,9 @@ class PubServer(BaseHTTPRequestHandler):
actor/collections/featuredTags actor/collections/featuredTags
TODO add ability to set a featured tags TODO add ability to set a featured tags
""" """
postContext = getIndividualPostContext()
featuredTagsCollection = { featuredTagsCollection = {
'@context': ['https://www.w3.org/ns/activitystreams', '@context': postContext,
{'atomUri': 'ostatus:atomUri',
'conversation': 'ostatus:conversation',
'inReplyToAtomUri': 'ostatus:inReplyToAtomUri',
'sensitive': 'as:sensitive',
'toot': 'http://joinmastodon.org/ns#',
'votersCount': 'toot:votersCount'}],
'id': httpPrefix + '://' + domainFull + path, 'id': httpPrefix + '://' + domainFull + path,
'orderedItems': [], 'orderedItems': [],
'totalItems': 0, 'totalItems': 0,

View File

@ -83,6 +83,7 @@ from git import convertPostToPatch
from linked_data_sig import generateJsonSignature from linked_data_sig import generateJsonSignature
from petnames import resolvePetnames from petnames import resolvePetnames
from video import convertVideoToNote from video import convertVideoToNote
from context import getIndividualPostContext
def isModerator(baseDir: str, nickname: str) -> bool: def isModerator(baseDir: str, nickname: str) -> bool:
@ -1382,18 +1383,7 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int,
summary, content, schedulePost, summary, content, schedulePost,
eventUUID, location, tags) eventUUID, location, tags)
postContext = [ postContext = getIndividualPostContext()
'https://www.w3.org/ns/activitystreams',
{
"ostatus": "http://ostatus.org#",
"atomUri": "ostatus:atomUri",
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
"conversation": "ostatus:conversation",
"sensitive": "as:sensitive",
"toot": "http://joinmastodon.org/ns#",
"votersCount": "toot:votersCount"
}
]
# make sure that CC doesn't also contain a To address # make sure that CC doesn't also contain a To address
# eg. To: [ "https://mydomain/users/foo/followers" ] # eg. To: [ "https://mydomain/users/foo/followers" ]
@ -1615,19 +1605,9 @@ def jsonPinPost(baseDir: str, httpPrefix: str,
itemsList = [pinnedPostJson] itemsList = [pinnedPostJson]
actor = localActorUrl(httpPrefix, nickname, domainFull) actor = localActorUrl(httpPrefix, nickname, domainFull)
postContext = getIndividualPostContext()
return { return {
'@context': [ '@context': postContext,
'https://www.w3.org/ns/activitystreams',
{
'atomUri': 'ostatus:atomUri',
'conversation': 'ostatus:conversation',
'inReplyToAtomUri': 'ostatus:inReplyToAtomUri',
'ostatus': 'http://ostatus.org#',
'sensitive': 'as:sensitive',
'toot': 'http://joinmastodon.org/ns#',
'votersCount': 'toot:votersCount'
}
],
'id': actor + '/collections/featured', 'id': actor + '/collections/featured',
'orderedItems': itemsList, 'orderedItems': itemsList,
'totalItems': len(itemsList), 'totalItems': len(itemsList),