Pinned post endpoint

merge-requests/10/merge
Bob Mottram 2021-01-25 14:31:37 +00:00
parent 402206b85c
commit 2b1bb3e82f
2 changed files with 53 additions and 8 deletions

View File

@ -68,6 +68,8 @@ from person import removeAccount
from person import canRemovePost
from person import personSnooze
from person import personUnsnooze
from posts import outboxMessageCreateWrap
from posts import getPinnedPostAsJson
from posts import pinPost
from posts import jsonPinPost
from posts import undoPinnedPost
@ -10150,7 +10152,34 @@ class PubServer(BaseHTTPRequestHandler):
if '/users/' in self.path:
usersInPath = True
if usersInPath and self.path.endswith('/collections/featured'):
if not htmlGET and \
usersInPath and self.path.endswith('/pinned'):
nickname = self.path.split('/users/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
pinnedPostJson = \
getPinnedPostAsJson(self.server.baseDir,
self.server.httpPrefix,
nickname, self.server.domain,
self.server.domainFull)
messageJson = {}
if pinnedPostJson:
messageJson = \
outboxMessageCreateWrap(self.server.httpPrefix,
nickname,
self.server.domain,
self.server.port,
pinnedPostJson)
msg = json.dumps(messageJson,
ensure_ascii=False).encode('utf-8')
msglen = len(msg)
self._set_headers('application/json',
msglen, None, callingDomain)
self._write(msg)
return
if not htmlGET and \
usersInPath and self.path.endswith('/collections/featured'):
nickname = self.path.split('/users/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
@ -10162,7 +10191,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domainFull)
return
if usersInPath and self.path.endswith('/collections/featuredTags'):
if not htmlGET and \
usersInPath and self.path.endswith('/collections/featuredTags'):
self._getFeaturedTagsCollection(callingDomain,
self.path,
self.server.httpPrefix,

View File

@ -1298,14 +1298,13 @@ def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None:
os.remove(pinnedFilename)
def jsonPinPost(baseDir: str, httpPrefix: str,
nickname: str, domain: str,
domainFull: str) -> {}:
"""Returns a pinned post as json
def getPinnedPostAsJson(baseDir: str, httpPrefix: str,
nickname: str, domain: str,
domainFull: str) -> {}:
"""Returns the pinned profile post as json
"""
accountDir = baseDir + '/accounts/' + nickname + '@' + domain
pinnedFilename = accountDir + '/pinToProfile.txt'
itemsList = []
pinnedPostJson = {}
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
if os.path.isfile(pinnedFilename):
@ -1338,7 +1337,23 @@ def jsonPinPost(baseDir: str, httpPrefix: str,
'type': 'Note',
'url': actor.replace('/users/', '/@') + '/pinned'
}
itemsList = [pinnedPostJson]
return pinnedPostJson
def jsonPinPost(baseDir: str, httpPrefix: str,
nickname: str, domain: str,
domainFull: str) -> {}:
"""Returns a pinned post as json
"""
pinnedPostJson = \
getPinnedPostAsJson(baseDir, httpPrefix,
nickname, domain,
domainFull)
itemsList = []
if pinnedPostJson:
itemsList = [pinnedPostJson]
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
return {
'@context': [
'https://www.w3.org/ns/activitystreams',