Fix displaying posts

master
Bob Mottram 2019-07-19 17:56:55 +01:00
parent 0f28decf20
commit c24dfc6347
2 changed files with 46 additions and 9 deletions

View File

@ -253,7 +253,8 @@ if args.posts:
sys.exit() sys.exit()
nickname=args.posts.split('@')[0] nickname=args.posts.split('@')[0]
domain=args.posts.split('@')[1] domain=args.posts.split('@')[1]
getPublicPostsOfPerson(nickname,domain,False,True,args.tor,args.port,httpPrefix) getPublicPostsOfPerson(nickname,domain,False,True, \
args.tor,args.port,httpPrefix,debug)
sys.exit() sys.exit()
if args.postsraw: if args.postsraw:
@ -262,7 +263,8 @@ if args.postsraw:
sys.exit() sys.exit()
nickname=args.postsraw.split('@')[0] nickname=args.postsraw.split('@')[0]
domain=args.postsraw.split('@')[1] domain=args.postsraw.split('@')[1]
getPublicPostsOfPerson(nickname,domain,False,False,args.tor,args.port,httpPrefix) getPublicPostsOfPerson(nickname,domain,False,False, \
args.tor,args.port,httpPrefix,debug)
sys.exit() sys.exit()
baseDir=args.baseDir baseDir=args.baseDir

View File

@ -160,10 +160,12 @@ def getPersonBox(session,wfRequest: {},personCache: {}, \
return boxJson,pubKeyId,pubKey,personId,sharedInbox,capabilityAcquisition return boxJson,pubKeyId,pubKey,personId,sharedInbox,capabilityAcquisition
def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \ def getPosts(session,outboxUrl: str,maxPosts: int, \
maxMentions: int, \
maxEmoji: int,maxAttachments: int, \ maxEmoji: int,maxAttachments: int, \
federationList: [],\ federationList: [], \
personCache: {},raw: bool,simple: bool) -> {}: personCache: {},raw: bool, \
simple: bool,debug: bool) -> {}:
personPosts={} personPosts={}
if not outboxUrl: if not outboxUrl:
return personPosts return personPosts
@ -182,14 +184,33 @@ def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \
i = 0 i = 0
for item in parseUserFeed(session,outboxUrl,asHeader): for item in parseUserFeed(session,outboxUrl,asHeader):
if not item.get('id'):
if debug:
print('No id')
continue
if not item.get('type'): if not item.get('type'):
if debug:
print('No type')
continue continue
if item['type'] != 'Create': if item['type'] != 'Create':
if debug:
print('Not Create type')
continue continue
if not item.get('object'): if not item.get('object'):
if debug:
print('No object')
continue continue
if not isinstance(item['object'], dict):
if debug:
print('item object is not a dict')
continue
if not item['object'].get('published'):
if debug:
print('No published attribute')
continue
#pprint(item)
published = item['object']['published'] published = item['object']['published']
if not personPosts.get(published): if not personPosts.get(item['id']):
content = item['object']['content'] content = item['object']['content']
mentions=[] mentions=[]
@ -207,13 +228,20 @@ def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \
emojiName=tagItem['name'] emojiName=tagItem['name']
emojiIcon=tagItem['icon']['url'] emojiIcon=tagItem['icon']['url']
emoji[emojiName]=emojiIcon emoji[emojiName]=emojiIcon
else:
if debug:
print('url not permitted '+tagItem['icon']['url'])
if tagType=='mention': if tagType=='mention':
if tagItem.get('name'): if tagItem.get('name'):
if tagItem['name'] not in mentions: if tagItem['name'] not in mentions:
mentions.append(tagItem['name']) mentions.append(tagItem['name'])
if len(mentions)>maxMentions: if len(mentions)>maxMentions:
if debug:
print('max mentions reached')
continue continue
if len(emoji)>maxEmoji: if len(emoji)>maxEmoji:
if debug:
print('max emojis reached')
continue continue
summary = '' summary = ''
@ -228,6 +256,8 @@ def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \
if not urlPermitted(item['object']['inReplyTo'], \ if not urlPermitted(item['object']['inReplyTo'], \
federationList, \ federationList, \
"objects:read"): "objects:read"):
if debug:
print('url not permitted '+item['object']['inReplyTo'])
continue continue
inReplyTo = item['object']['inReplyTo'] inReplyTo = item['object']['inReplyTo']
@ -249,6 +279,9 @@ def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \
federationList, \ federationList, \
"objects:read"): "objects:read"):
attachment.append([attach['name'],attach['url']]) attachment.append([attach['name'],attach['url']])
else:
if debug:
print('url not permitted '+attach['url'])
sensitive = False sensitive = False
if item['object'].get('sensitive'): if item['object'].get('sensitive'):
@ -257,7 +290,8 @@ def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \
if simple: if simple:
print(cleanHtml(content)+'\n') print(cleanHtml(content)+'\n')
else: else:
personPosts[published] = { pprint(item)
personPosts[item['id']] = {
"sensitive": sensitive, "sensitive": sensitive,
"inreplyto": inReplyTo, "inreplyto": inReplyTo,
"summary": summary, "summary": summary,
@ -1263,7 +1297,8 @@ def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str
def getPublicPostsOfPerson(nickname: str,domain: str, \ def getPublicPostsOfPerson(nickname: str,domain: str, \
raw: bool,simple: bool,useTor: bool, \ raw: bool,simple: bool,useTor: bool, \
port: int,httpPrefix: str) -> None: port: int,httpPrefix: str, \
debug: bool) -> None:
""" This is really just for test purposes """ This is really just for test purposes
""" """
session = createSession(domain,port,useTor) session = createSession(domain,port,useTor)
@ -1289,7 +1324,7 @@ def getPublicPostsOfPerson(nickname: str,domain: str, \
maxAttachments=5 maxAttachments=5
userPosts = getPosts(session,personUrl,30,maxMentions,maxEmoji, \ userPosts = getPosts(session,personUrl,30,maxMentions,maxEmoji, \
maxAttachments,federationList, \ maxAttachments,federationList, \
personCache,raw,simple) personCache,raw,simple,debug)
#print(str(userPosts)) #print(str(userPosts))
def sendCapabilitiesUpdate(session,baseDir: str,httpPrefix: str, \ def sendCapabilitiesUpdate(session,baseDir: str,httpPrefix: str, \