Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classic repost fix #439

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion journal/models/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions mastodon/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down