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

View File

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