fix undo boost
This commit is contained in:
parent
6568b2324f
commit
b9f2173f27
3 changed files with 16 additions and 12 deletions
|
@ -68,10 +68,11 @@ def post_boost(request: AuthedHttpRequest, post_id: int):
|
|||
post = Takahe.get_post(post_id)
|
||||
if not post:
|
||||
raise BadRequest(_("Invalid parameter"))
|
||||
if request.user.mastodon and request.user.preference.mastodon_repost_mode == 1:
|
||||
request.user.mastodon.boost_later(post.object_uri)
|
||||
else:
|
||||
Takahe.boost_post(post_id, request.user.identity.pk)
|
||||
boost = Takahe.boost_post(post_id, request.user.identity.pk)
|
||||
print(boost.state if boost else "x")
|
||||
if boost and boost.state == "new":
|
||||
if request.user.mastodon and request.user.preference.mastodon_repost_mode == 1:
|
||||
request.user.mastodon.boost_later(post.object_uri)
|
||||
return render(request, "action_boost_post.html", {"post": post})
|
||||
|
||||
|
||||
|
|
|
@ -1764,6 +1764,8 @@ class PostInteraction(models.Model):
|
|||
# state = StateField(PostInteractionStates)
|
||||
state = models.CharField(max_length=100, default="new")
|
||||
state_changed = models.DateTimeField(auto_now_add=True)
|
||||
state_next_attempt = models.DateTimeField(blank=True, null=True)
|
||||
state_locked_until = models.DateTimeField(null=True, blank=True, db_index=True)
|
||||
|
||||
# The canonical object ID
|
||||
object_uri = models.CharField(max_length=500, blank=True, null=True, unique=True)
|
||||
|
|
|
@ -617,7 +617,7 @@ class Takahe:
|
|||
return post
|
||||
|
||||
@staticmethod
|
||||
def interact_post(post_pk: int, identity_pk: int, type: str):
|
||||
def interact_post(post_pk: int, identity_pk: int, type: str, flip=False):
|
||||
post = Post.objects.filter(pk=post_pk).first()
|
||||
if not post:
|
||||
logger.warning(f"Cannot find post {post_pk}")
|
||||
|
@ -626,14 +626,15 @@ class Takahe:
|
|||
if not identity:
|
||||
logger.warning(f"Cannot find identity {identity_pk}")
|
||||
return
|
||||
interaction = PostInteraction.objects.get_or_create(
|
||||
interaction, created = PostInteraction.objects.get_or_create(
|
||||
type=type,
|
||||
identity_id=identity_pk,
|
||||
post=post,
|
||||
)[0]
|
||||
if interaction.state not in ["new", "fanned_out"]:
|
||||
interaction.state = "new"
|
||||
interaction.save()
|
||||
)
|
||||
if flip and not created:
|
||||
Takahe.update_state(interaction, "undone")
|
||||
elif interaction.state not in ["new", "fanned_out"]:
|
||||
Takahe.update_state(interaction, "new")
|
||||
post.calculate_stats()
|
||||
return interaction
|
||||
|
||||
|
@ -660,7 +661,7 @@ class Takahe:
|
|||
|
||||
@staticmethod
|
||||
def boost_post(post_pk: int, identity_pk: int):
|
||||
return Takahe.interact_post(post_pk, identity_pk, "boost")
|
||||
return Takahe.interact_post(post_pk, identity_pk, "boost", flip=True)
|
||||
|
||||
@staticmethod
|
||||
def post_boosted_by(post_pk: int, identity_pk: int) -> bool:
|
||||
|
@ -747,7 +748,7 @@ class Takahe:
|
|||
return FediverseHtmlParser(linebreaks_filter(txt)).html
|
||||
|
||||
@staticmethod
|
||||
def update_state(obj: Post | Relay | Identity, state: str):
|
||||
def update_state(obj: Post | PostInteraction | Relay | Identity, state: str):
|
||||
obj.state = state
|
||||
obj.state_changed = timezone.now()
|
||||
obj.state_next_attempt = None
|
||||
|
|
Loading…
Add table
Reference in a new issue