Extra check for edition tag

merge-requests/30/head
Bob Mottram 2024-01-04 18:53:34 +00:00
parent f27cc4d66e
commit 4e59beab16
2 changed files with 36 additions and 7 deletions

View File

@ -63,6 +63,7 @@ from shares import outbox_undo_share_upload
from webapp_post import individual_post_as_html
from speaker import update_speaker
from reading import store_book_events
from reading import has_edition_tag
def _person_receive_update_outbox(base_dir: str, http_prefix: str,
@ -502,13 +503,14 @@ def post_message_to_outbox(session, translate: {},
theme, system_language,
outbox_name)
store_book_events(base_dir,
message_json,
system_language, [],
translate, debug,
max_recent_books,
books_cache,
max_cached_readers)
if has_edition_tag(message_json):
store_book_events(base_dir,
message_json,
system_language, [],
translate, debug,
max_recent_books,
books_cache,
max_cached_readers)
# save all instance blogs to the news actor
if post_to_nickname != 'news' and outbox_name == 'tlblogs':

View File

@ -89,6 +89,30 @@ def _get_book_image_from_post(post_json_object: {}) -> str:
return ''
def has_edition_tag(post_json_object: {}) -> bool:
"""Checks whether the given post has an Edition tag
indicating that it contains a book event
"""
post_obj = post_json_object
if has_object_dict(post_json_object):
post_obj = post_json_object['object']
if not post_obj.get('tag'):
return False
if not isinstance(post_obj['tag'], list):
return False
for tag in post_obj['tag']:
if not isinstance(tag, dict):
continue
if not tag.get('type'):
continue
if not isinstance(tag['type'], str):
continue
if tag['type'] == 'Edition':
return True
return False
def get_reading_status(post_json_object: {},
system_language: str,
languages_understood: [],
@ -169,6 +193,9 @@ def get_reading_status(post_json_object: {},
book_dict['image_url'] = book_image_url
return book_dict
if not has_edition_tag(post_json_object):
return {}
# get the book details from a post tag
book_dict = get_book_from_post(post_json_object, debug)
if not book_dict: