diff --git a/journal/models/mark.py b/journal/models/mark.py index 0dc37f17..ed5fd861 100644 --- a/journal/models/mark.py +++ b/journal/models/mark.py @@ -182,6 +182,10 @@ def update( if last_shelf_type: Takahe.delete_posts(self.shelfmember.all_post_ids) self.shelfmember.log_and_delete() + if self.comment: + self.comment.delete() + if self.rating: + self.rating.delete() return # create/update shelf member and shelf log if necessary if last_shelf_type == shelf_type: @@ -243,7 +247,7 @@ def update( # async boost to mastodon if post and share_to_mastodon: if classic_repost: - share_mark(self) + share_mark(self, post_as_new) else: boost_toot_later(self.owner.user, post.url) return True diff --git a/mastodon/api.py b/mastodon/api.py index 5b5a1181..3f644bdc 100644 --- a/mastodon/api.py +++ b/mastodon/api.py @@ -485,7 +485,7 @@ def share_comment(comment): return False -def share_mark(mark): +def share_mark(mark, post_as_new=False): from catalog.common import ItemCategory user = mark.owner.user @@ -505,7 +505,11 @@ def share_mark(mark): ) spoiler_text, txt = get_spoiler_text(mark.comment_text or "", mark.item) content = f"{mark.action_label}《{mark.item.display_title}》{stars}\n{mark.item.absolute_url}\n{txt}{tags}" - update_id = None # get_status_id_by_url(mark.shared_link) + update_id = ( + None + if post_as_new + else get_status_id_by_url((mark.shelfmember.metadata or {}).get("shared_link")) + ) response = post_toot( user.mastodon_site, content, @@ -516,11 +520,10 @@ def share_mark(mark): spoiler_text, ) if response is not None and response.status_code in [200, 201]: - # j = response.json() - # if "url" in j: - # mark.shared_link = j["url"] - # if mark.shared_link: - # mark.save(update_fields=["shared_link"]) + j = response.json() + if "url" in j: + mark.shelfmember.metadata = {"shared_link": j["url"]} + mark.shelfmember.save(update_fields=["metadata"]) return True, 200 else: logger.warning(response)