mirror of https://gitlab.com/bashrc2/epicyon
Featured post collection
parent
a1b470b161
commit
87982e0af4
31
daemon.py
31
daemon.py
|
@ -69,7 +69,8 @@ from person import canRemovePost
|
|||
from person import personSnooze
|
||||
from person import personUnsnooze
|
||||
from posts import pinPost
|
||||
from posts import unpinPost
|
||||
from posts import jsonPinPost
|
||||
from posts import undoPinnedPost
|
||||
from posts import isModerator
|
||||
from posts import mutePost
|
||||
from posts import unmutePost
|
||||
|
@ -9062,26 +9063,17 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
return False
|
||||
|
||||
def _getFeaturedCollection(self, callingDomain: str,
|
||||
baseDir: str,
|
||||
path: str,
|
||||
httpPrefix: str,
|
||||
nickname: str, domain: str,
|
||||
domainFull: str):
|
||||
"""Returns the featured posts collections in
|
||||
actor/collections/featured
|
||||
TODO add ability to set a featured post
|
||||
"""
|
||||
featuredCollection = {
|
||||
'@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'}],
|
||||
'id': httpPrefix + '://' + domainFull + path,
|
||||
'orderedItems': [],
|
||||
'totalItems': 0,
|
||||
'type': 'OrderedCollection'
|
||||
}
|
||||
featuredCollection = \
|
||||
jsonPinPost(baseDir, httpPrefix,
|
||||
nickname, domain, domainFull)
|
||||
msg = json.dumps(featuredCollection,
|
||||
ensure_ascii=False).encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
@ -10142,9 +10134,14 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
usersInPath = True
|
||||
|
||||
if usersInPath and self.path.endswith('/collections/featured'):
|
||||
nickname = self.path.split('/users/')[1]
|
||||
if '/' in nickname:
|
||||
nickname = nickname.split('/')[0]
|
||||
self._getFeaturedCollection(callingDomain,
|
||||
self.server.baseDir,
|
||||
self.path,
|
||||
self.server.httpPrefix,
|
||||
nickname, self.server.domain,
|
||||
self.server.domainFull)
|
||||
return
|
||||
|
||||
|
@ -12236,8 +12233,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# is the post message empty?
|
||||
if not fields['message']:
|
||||
# remove the pinned content from profile screen
|
||||
unpinPost(self.server.baseDir,
|
||||
nickname, self.server.domain)
|
||||
undoPinnedPost(self.server.baseDir,
|
||||
nickname, self.server.domain)
|
||||
return 1
|
||||
|
||||
messageJson = \
|
||||
|
|
64
posts.py
64
posts.py
|
@ -30,6 +30,7 @@ from session import postJsonString
|
|||
from session import postImage
|
||||
from webfinger import webfingerHandle
|
||||
from httpsig import createSignedHeader
|
||||
from utils import fileLastModified
|
||||
from utils import isPublicPost
|
||||
from utils import hasUsersPath
|
||||
from utils import validPostDate
|
||||
|
@ -1285,7 +1286,7 @@ def pinPost(baseDir: str, nickname: str, domain: str,
|
|||
pinFile.close()
|
||||
|
||||
|
||||
def unpinPost(baseDir: str, nickname: str, domain: str) -> None:
|
||||
def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None:
|
||||
"""Removes pinned content for then given account
|
||||
"""
|
||||
accountDir = baseDir + '/accounts/' + nickname + '@' + domain
|
||||
|
@ -1294,6 +1295,67 @@ def unpinPost(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
|
||||
"""
|
||||
accountDir = baseDir + '/accounts/' + nickname + '@' + domain
|
||||
pinnedFilename = accountDir + '/pinToProfile.txt'
|
||||
itemsList = []
|
||||
pinnedPostJson = {}
|
||||
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||
if os.path.isfile(pinnedFilename):
|
||||
pinFile = open(pinnedFilename, "r")
|
||||
pinnedContent = None
|
||||
if pinFile:
|
||||
pinnedContent = pinFile.read()
|
||||
pinFile.close()
|
||||
if pinnedContent:
|
||||
pinnedPostJson = {
|
||||
'atomUri': actor + '/pinned',
|
||||
'attachment': [],
|
||||
'attributedTo': actor,
|
||||
'cc': [
|
||||
actor + '/followers'
|
||||
],
|
||||
'content': pinnedContent,
|
||||
'contentMap': {
|
||||
'en': pinnedContent
|
||||
},
|
||||
'id': actor + '/pinned',
|
||||
'inReplyTo': None,
|
||||
'inReplyToAtomUri': None,
|
||||
'published': fileLastModified(pinnedFilename),
|
||||
'replies': {},
|
||||
'sensitive': False,
|
||||
'summary': None,
|
||||
'tag': [],
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'type': 'Note',
|
||||
'url': actor.replace('/users/', '/@') + '/pinned'
|
||||
}
|
||||
itemsList = [pinnedPostJson]
|
||||
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'
|
||||
}
|
||||
],
|
||||
'id': actor + '/collections/featured',
|
||||
'orderedItems': itemsList,
|
||||
'totalItems': len(itemsList),
|
||||
'type': 'OrderedCollection'
|
||||
}
|
||||
|
||||
|
||||
def createPublicPost(baseDir: str,
|
||||
nickname: str, domain: str, port: int, httpPrefix: str,
|
||||
content: str, followersOnly: bool, saveToFile: bool,
|
||||
|
|
Loading…
Reference in New Issue