Handle unlisted posts

master
Bob Mottram 2019-07-28 12:08:14 +01:00
parent 6f37df2135
commit 1c2e073d0c
2 changed files with 44 additions and 4 deletions

View File

@ -31,6 +31,7 @@ from posts import sendToFollowers
from posts import postIsAddressedToPublic
from posts import sendToNamedAddresses
from posts import createPublicPost
from posts import createUnlistedPost
from posts import createFollowersOnlyPost
from posts import createDirectMessagePost
from inbox import inboxPermittedMessage
@ -1147,6 +1148,20 @@ class PubServer(BaseHTTPRequestHandler):
if queueStatus==0:
return True
if postType=='newunlisted':
messageJson= \
createUnlistedPost(self.server.baseDir, \
nickname, \
self.server.domain,self.server.port, \
self.server.httpPrefix, \
fields['message'],False,False,False, \
filename,fields['imageDescription'],True, \
fields['replyTo'], fields['replyTo'],fields['subject'])
if messageJson:
queueStatus=self._updateInboxQueue(nickname,messageJson)
if queueStatus==0:
return True
if postType=='newfollowers':
messageJson= \
createFollowersOnlyPost(self.server.baseDir, \
@ -1175,10 +1190,6 @@ class PubServer(BaseHTTPRequestHandler):
if queueStatus==0:
return True
if postType=='newunlisted':
# TODO
return True
if postType=='newshare':
if not fields.get('itemType'):
return False

View File

@ -174,6 +174,8 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
federationList: [], \
personCache: {},raw: bool, \
simple: bool,debug: bool) -> {}:
"""Gets public posts from an outbox
"""
personPosts={}
if not outboxUrl:
return personPosts
@ -219,6 +221,17 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
#pprint(item)
published = item['object']['published']
if not personPosts.get(item['id']):
# check that this is a public post
# #Public should appear in the "to" list
if item['object'].get('to'):
isPublic=False
for recipient in item['object']['to']:
if recipient.endswith('#Public'):
isPublic=True
break
if not isPublic:
continue
content = item['object']['content']
mentions=[]
@ -602,6 +615,22 @@ def createPublicPost(baseDir: str,
attachImageFilename,imageDescription,useBlurhash, \
inReplyTo, inReplyToAtomUri, subject)
def createUnlistedPost(baseDir: str,
nickname: str, domain: str, port: int,httpPrefix: str, \
content: str, followersOnly: bool, saveToFile: bool,
clientToServer: bool,\
attachImageFilename: str,imageDescription: str,useBlurhash: bool, \
inReplyTo=None, inReplyToAtomUri=None, subject=None) -> {}:
"""Unlisted post. This has the #Public and followers links inverted.
"""
return createPostBase(baseDir,nickname, domain, port, \
httpPrefix+'://'+domain+'/users/'+nickname+'/followers', \
'https://www.w3.org/ns/activitystreams#Public', \
httpPrefix, content, followersOnly, saveToFile, \
clientToServer, \
attachImageFilename,imageDescription,useBlurhash, \
inReplyTo, inReplyToAtomUri, subject)
def createFollowersOnlyPost(baseDir: str,
nickname: str, domain: str, port: int,httpPrefix: str, \
content: str, followersOnly: bool, saveToFile: bool,