Skip to content

Commit

Permalink
improve classic repost
Browse files Browse the repository at this point in the history
  • Loading branch information
Her Email authored and alphatownsman committed Dec 16, 2023
1 parent 04d5b77 commit 2229639
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion journal/models/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,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

0 comments on commit 2229639

Please sign in to comment.