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 postIsAddressedToPublic
from posts import sendToNamedAddresses from posts import sendToNamedAddresses
from posts import createPublicPost from posts import createPublicPost
from posts import createUnlistedPost
from posts import createFollowersOnlyPost from posts import createFollowersOnlyPost
from posts import createDirectMessagePost from posts import createDirectMessagePost
from inbox import inboxPermittedMessage from inbox import inboxPermittedMessage
@ -1147,6 +1148,20 @@ class PubServer(BaseHTTPRequestHandler):
if queueStatus==0: if queueStatus==0:
return True 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': if postType=='newfollowers':
messageJson= \ messageJson= \
createFollowersOnlyPost(self.server.baseDir, \ createFollowersOnlyPost(self.server.baseDir, \
@ -1175,10 +1190,6 @@ class PubServer(BaseHTTPRequestHandler):
if queueStatus==0: if queueStatus==0:
return True return True
if postType=='newunlisted':
# TODO
return True
if postType=='newshare': if postType=='newshare':
if not fields.get('itemType'): if not fields.get('itemType'):
return False return False

View File

@ -174,6 +174,8 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
federationList: [], \ federationList: [], \
personCache: {},raw: bool, \ personCache: {},raw: bool, \
simple: bool,debug: bool) -> {}: simple: bool,debug: bool) -> {}:
"""Gets public posts from an outbox
"""
personPosts={} personPosts={}
if not outboxUrl: if not outboxUrl:
return personPosts return personPosts
@ -219,6 +221,17 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
#pprint(item) #pprint(item)
published = item['object']['published'] published = item['object']['published']
if not personPosts.get(item['id']): 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'] content = item['object']['content']
mentions=[] mentions=[]
@ -602,6 +615,22 @@ def createPublicPost(baseDir: str,
attachImageFilename,imageDescription,useBlurhash, \ attachImageFilename,imageDescription,useBlurhash, \
inReplyTo, inReplyToAtomUri, subject) 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, def createFollowersOnlyPost(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,