mirror of https://gitlab.com/bashrc2/epicyon
Featured post collection
parent
a1b470b161
commit
87982e0af4
29
daemon.py
29
daemon.py
|
@ -69,7 +69,8 @@ from person import canRemovePost
|
||||||
from person import personSnooze
|
from person import personSnooze
|
||||||
from person import personUnsnooze
|
from person import personUnsnooze
|
||||||
from posts import pinPost
|
from posts import pinPost
|
||||||
from posts import unpinPost
|
from posts import jsonPinPost
|
||||||
|
from posts import undoPinnedPost
|
||||||
from posts import isModerator
|
from posts import isModerator
|
||||||
from posts import mutePost
|
from posts import mutePost
|
||||||
from posts import unmutePost
|
from posts import unmutePost
|
||||||
|
@ -9062,26 +9063,17 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _getFeaturedCollection(self, callingDomain: str,
|
def _getFeaturedCollection(self, callingDomain: str,
|
||||||
|
baseDir: str,
|
||||||
path: str,
|
path: str,
|
||||||
httpPrefix: str,
|
httpPrefix: str,
|
||||||
|
nickname: str, domain: str,
|
||||||
domainFull: str):
|
domainFull: str):
|
||||||
"""Returns the featured posts collections in
|
"""Returns the featured posts collections in
|
||||||
actor/collections/featured
|
actor/collections/featured
|
||||||
TODO add ability to set a featured post
|
|
||||||
"""
|
"""
|
||||||
featuredCollection = {
|
featuredCollection = \
|
||||||
'@context': ['https://www.w3.org/ns/activitystreams',
|
jsonPinPost(baseDir, httpPrefix,
|
||||||
{'atomUri': 'ostatus:atomUri',
|
nickname, domain, domainFull)
|
||||||
'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'
|
|
||||||
}
|
|
||||||
msg = json.dumps(featuredCollection,
|
msg = json.dumps(featuredCollection,
|
||||||
ensure_ascii=False).encode('utf-8')
|
ensure_ascii=False).encode('utf-8')
|
||||||
msglen = len(msg)
|
msglen = len(msg)
|
||||||
|
@ -10142,9 +10134,14 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
usersInPath = True
|
usersInPath = True
|
||||||
|
|
||||||
if usersInPath and self.path.endswith('/collections/featured'):
|
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._getFeaturedCollection(callingDomain,
|
||||||
|
self.server.baseDir,
|
||||||
self.path,
|
self.path,
|
||||||
self.server.httpPrefix,
|
self.server.httpPrefix,
|
||||||
|
nickname, self.server.domain,
|
||||||
self.server.domainFull)
|
self.server.domainFull)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -12236,7 +12233,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
# is the post message empty?
|
# is the post message empty?
|
||||||
if not fields['message']:
|
if not fields['message']:
|
||||||
# remove the pinned content from profile screen
|
# remove the pinned content from profile screen
|
||||||
unpinPost(self.server.baseDir,
|
undoPinnedPost(self.server.baseDir,
|
||||||
nickname, self.server.domain)
|
nickname, self.server.domain)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
64
posts.py
64
posts.py
|
@ -30,6 +30,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 fileLastModified
|
||||||
from utils import isPublicPost
|
from utils import isPublicPost
|
||||||
from utils import hasUsersPath
|
from utils import hasUsersPath
|
||||||
from utils import validPostDate
|
from utils import validPostDate
|
||||||
|
@ -1285,7 +1286,7 @@ def pinPost(baseDir: str, nickname: str, domain: str,
|
||||||
pinFile.close()
|
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
|
"""Removes pinned content for then given account
|
||||||
"""
|
"""
|
||||||
accountDir = baseDir + '/accounts/' + nickname + '@' + domain
|
accountDir = baseDir + '/accounts/' + nickname + '@' + domain
|
||||||
|
@ -1294,6 +1295,67 @@ def unpinPost(baseDir: str, nickname: str, domain: str) -> None:
|
||||||
os.remove(pinnedFilename)
|
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,
|
def createPublicPost(baseDir: str,
|
||||||
nickname: str, domain: str, port: int, httpPrefix: str,
|
nickname: str, domain: str, port: int, httpPrefix: str,
|
||||||
content: str, followersOnly: bool, saveToFile: bool,
|
content: str, followersOnly: bool, saveToFile: bool,
|
||||||
|
|
Loading…
Reference in New Issue