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)
|
post = Takahe.get_post(post_id)
|
||||||
if not post:
|
if not post:
|
||||||
raise BadRequest(_("Invalid parameter"))
|
raise BadRequest(_("Invalid parameter"))
|
||||||
if request.user.mastodon and request.user.preference.mastodon_repost_mode == 1:
|
boost = Takahe.boost_post(post_id, request.user.identity.pk)
|
||||||
request.user.mastodon.boost_later(post.object_uri)
|
print(boost.state if boost else "x")
|
||||||
else:
|
if boost and boost.state == "new":
|
||||||
Takahe.boost_post(post_id, request.user.identity.pk)
|
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})
|
return render(request, "action_boost_post.html", {"post": post})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1764,6 +1764,8 @@ class PostInteraction(models.Model):
|
||||||
# state = StateField(PostInteractionStates)
|
# state = StateField(PostInteractionStates)
|
||||||
state = models.CharField(max_length=100, default="new")
|
state = models.CharField(max_length=100, default="new")
|
||||||
state_changed = models.DateTimeField(auto_now_add=True)
|
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
|
# The canonical object ID
|
||||||
object_uri = models.CharField(max_length=500, blank=True, null=True, unique=True)
|
object_uri = models.CharField(max_length=500, blank=True, null=True, unique=True)
|
||||||
|
|
|
@ -617,7 +617,7 @@ class Takahe:
|
||||||
return post
|
return post
|
||||||
|
|
||||||
@staticmethod
|
@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()
|
post = Post.objects.filter(pk=post_pk).first()
|
||||||
if not post:
|
if not post:
|
||||||
logger.warning(f"Cannot find post {post_pk}")
|
logger.warning(f"Cannot find post {post_pk}")
|
||||||
|
@ -626,14 +626,15 @@ class Takahe:
|
||||||
if not identity:
|
if not identity:
|
||||||
logger.warning(f"Cannot find identity {identity_pk}")
|
logger.warning(f"Cannot find identity {identity_pk}")
|
||||||
return
|
return
|
||||||
interaction = PostInteraction.objects.get_or_create(
|
interaction, created = PostInteraction.objects.get_or_create(
|
||||||
type=type,
|
type=type,
|
||||||
identity_id=identity_pk,
|
identity_id=identity_pk,
|
||||||
post=post,
|
post=post,
|
||||||
)[0]
|
)
|
||||||
if interaction.state not in ["new", "fanned_out"]:
|
if flip and not created:
|
||||||
interaction.state = "new"
|
Takahe.update_state(interaction, "undone")
|
||||||
interaction.save()
|
elif interaction.state not in ["new", "fanned_out"]:
|
||||||
|
Takahe.update_state(interaction, "new")
|
||||||
post.calculate_stats()
|
post.calculate_stats()
|
||||||
return interaction
|
return interaction
|
||||||
|
|
||||||
|
@ -660,7 +661,7 @@ class Takahe:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def boost_post(post_pk: int, identity_pk: int):
|
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
|
@staticmethod
|
||||||
def post_boosted_by(post_pk: int, identity_pk: int) -> bool:
|
def post_boosted_by(post_pk: int, identity_pk: int) -> bool:
|
||||||
|
@ -747,7 +748,7 @@ class Takahe:
|
||||||
return FediverseHtmlParser(linebreaks_filter(txt)).html
|
return FediverseHtmlParser(linebreaks_filter(txt)).html
|
||||||
|
|
||||||
@staticmethod
|
@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 = state
|
||||||
obj.state_changed = timezone.now()
|
obj.state_changed = timezone.now()
|
||||||
obj.state_next_attempt = None
|
obj.state_next_attempt = None
|
||||||
|
|
Loading…
Add table
Reference in a new issue