Resolve posts from Friendica

merge-requests/30/head
Bob Mottram 2021-10-27 13:46:38 +01:00
parent a70ca0f0d0
commit aaa201ba9a
1 changed files with 37 additions and 23 deletions

View File

@ -444,9 +444,11 @@ def _isPublicFeedPost(item: {}, personPosts: {}, debug: bool) -> bool:
if debug: if debug:
print('No type') print('No type')
return False return False
if item['type'] != 'Create' and item['type'] != 'Announce': if item['type'] != 'Create' and \
item['type'] != 'Announce' and \
item['type'] != 'Note':
if debug: if debug:
print('Not a Create type') print('Not a Create/Note/Announce type')
return False return False
if item.get('object'): if item.get('object'):
if isinstance(item['object'], dict): if isinstance(item['object'], dict):
@ -463,19 +465,27 @@ def _isPublicFeedPost(item: {}, personPosts: {}, debug: bool) -> bool:
if debug: if debug:
print('object is not a dict or string') print('object is not a dict or string')
return False return False
elif item['type'] == 'Note':
if not item.get('published'):
if debug:
print('No published attribute')
return False
if not personPosts.get(item['id']): if not personPosts.get(item['id']):
thisItem = item
if item.get('object'):
thisItem = item['object']
# check that this is a public post # check that this is a public post
# #Public should appear in the "to" list # #Public should appear in the "to" list
if isinstance(item['object'], dict): if isinstance(thisItem, dict):
if item['object'].get('to'): if thisItem.get('to'):
isPublic = False isPublic = False
for recipient in item['object']['to']: for recipient in thisItem['to']:
if recipient.endswith('#Public'): if recipient.endswith('#Public'):
isPublic = True isPublic = True
break break
if not isPublic: if not isPublic:
return False return False
elif isinstance(item['object'], str): elif isinstance(thisItem, str) or item['type'] == 'Note':
if item.get('to'): if item.get('to'):
isPublic = False isPublic = False
for recipient in item['to']: for recipient in item['to']:
@ -570,6 +580,10 @@ def _getPosts(session, outboxUrl: str, maxPosts: int,
if not _isPublicFeedPost(item, personPosts, debug): if not _isPublicFeedPost(item, personPosts, debug):
continue continue
thisItem = item
if item['type'] != 'Note':
thisItem = item['object']
content = getBaseContentFromPost(item, systemLanguage) content = getBaseContentFromPost(item, systemLanguage)
content = content.replace(''', "'") content = content.replace(''', "'")
@ -579,9 +593,9 @@ def _getPosts(session, outboxUrl: str, maxPosts: int,
inReplyTo = '' inReplyTo = ''
attachment = [] attachment = []
sensitive = False sensitive = False
if isinstance(item['object'], dict): if isinstance(thisItem, dict):
if item['object'].get('tag'): if thisItem.get('tag'):
for tagItem in item['object']['tag']: for tagItem in thisItem['tag']:
tagType = tagItem['type'].lower() tagType = tagItem['type'].lower()
if tagType == 'emoji': if tagType == 'emoji':
if tagItem.get('name') and tagItem.get('icon'): if tagItem.get('name') and tagItem.get('icon'):
@ -609,25 +623,25 @@ def _getPosts(session, outboxUrl: str, maxPosts: int,
print('max emojis reached') print('max emojis reached')
continue continue
if item['object'].get('summary'): if thisItem.get('summary'):
if item['object']['summary']: if thisItem['summary']:
summary = item['object']['summary'] summary = thisItem['summary']
if item['object'].get('inReplyTo'): if thisItem.get('inReplyTo'):
if item['object']['inReplyTo']: if thisItem['inReplyTo']:
if isinstance(item['object']['inReplyTo'], str): if isinstance(thisItem['inReplyTo'], str):
# No replies to non-permitted domains # No replies to non-permitted domains
if not urlPermitted(item['object']['inReplyTo'], if not urlPermitted(thisItem['inReplyTo'],
federationList): federationList):
if debug: if debug:
print('url not permitted ' + print('url not permitted ' +
item['object']['inReplyTo']) thisItem['inReplyTo'])
continue continue
inReplyTo = item['object']['inReplyTo'] inReplyTo = thisItem['inReplyTo']
if item['object'].get('attachment'): if thisItem.get('attachment'):
if item['object']['attachment']: if thisItem['attachment']:
for attach in item['object']['attachment']: for attach in thisItem['attachment']:
if attach.get('name') and attach.get('url'): if attach.get('name') and attach.get('url'):
# no attachments from non-permitted domains # no attachments from non-permitted domains
if urlPermitted(attach['url'], if urlPermitted(attach['url'],
@ -640,8 +654,8 @@ def _getPosts(session, outboxUrl: str, maxPosts: int,
attach['url']) attach['url'])
sensitive = False sensitive = False
if item['object'].get('sensitive'): if thisItem.get('sensitive'):
sensitive = item['object']['sensitive'] sensitive = thisItem['sensitive']
if content: if content:
if simple: if simple: