Bugfix for undo boosts/likes

This commit is contained in:
Thomas Sileo 2018-07-07 12:10:25 +02:00
parent b31994dae7
commit 3281e2165e
4 changed files with 35 additions and 2 deletions

View file

@ -180,6 +180,7 @@ class MicroblogPubBackend(Backend):
{"box": Box.OUTBOX.value, "activity.object.id": obj.id},
{"$inc": {"meta.count_like": -1}},
)
DB.activities.update_one({"remote_id": like.id}, {"$set": {"meta.undo": True}})
@ensure_it_is_me
def outbox_like(self, as_actor: ap.Person, like: ap.Like) -> None:
@ -199,6 +200,7 @@ class MicroblogPubBackend(Backend):
{"activity.object.id": obj.id},
{"$inc": {"meta.count_like": -1}, "$set": {"meta.liked": False}},
)
DB.activities.update_one({"remote_id": like.id}, {"$set": {"meta.undo": True}})
@ensure_it_is_me
def inbox_announce(self, as_actor: ap.Person, announce: ap.Announce) -> None:
@ -228,6 +230,9 @@ class MicroblogPubBackend(Backend):
DB.activities.update_one(
{"activity.object.id": obj.id}, {"$inc": {"meta.count_boost": -1}}
)
DB.activities.update_one(
{"remote_id": announce.id}, {"$set": {"meta.undo": True}}
)
@ensure_it_is_me
def outbox_announce(self, as_actor: ap.Person, announce: ap.Announce) -> None:
@ -246,6 +251,9 @@ class MicroblogPubBackend(Backend):
DB.activities.update_one(
{"activity.object.id": obj.id}, {"$set": {"meta.boosted": False}}
)
DB.activities.update_one(
{"remote_id": announce.id}, {"$set": {"meta.undo": True}}
)
@ensure_it_is_me
def inbox_delete(self, as_actor: ap.Person, delete: ap.Delete) -> None:

View file

@ -25,7 +25,21 @@
{% if item | has_type('Announce') %}
{% set boost_actor = item.activity.actor | get_actor %}
<p style="margin-left:65px;padding-bottom:5px;"><span class="bar-item-no-hover"><a style="color:#808080;" href="{{ boost_actor.url }}">{{ boost_actor.name }}</a> boosted</span></p>
{% if session.logged_in %}
<div style="margin-left:65px;padding-bottom:5px;margin-bottom:15px;">
<span class="bar-item-no-hover"><a style="color:#808080;" href="{{ boost_actor.url }}">{{ boost_actor.name }}</a> boosted</span>
<form action="/api/undo" class="action-form" method="POST">
<input type="hidden" name="redirect" value="/"/>
<input type="hidden" name="id" value="{{ item.remote_id }}"/>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<button type="submit" class="bar-item">unboost</button>
</form>
</div>
{% else %}
<p style="margin-left:65px;padding-bottom:5px;">
<span class="bar-item-no-hover"><a style="color:#808080;" href="{{ boost_actor.url }}">{{ boost_actor.name }}</a> boosted</span>
</p>
{% endif %}
{% if item.meta.object %}
{{ utils.display_note(item.meta.object, ui=False) }}
{% endif %}

View file

@ -8,6 +8,17 @@
<div id="notes">
{% for item in liked %}
{% if session.logged_in %}
<div style="margin-left:65px;padding-bottom:5px;margin-bottom:15px;">
<form action="/api/undo" class="action-form" method="POST">
<input type="hidden" name="redirect" value="/liked"/>
<input type="hidden" name="id" value="{{ item.remote_id }}"/>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<button type="submit" class="bar-item">unlike</button>
</form>
</div>
{% endif %}
{% if item.meta.object %}
{{ utils.display_note(item.meta.object) }}
{% endif %}

View file

@ -9,7 +9,7 @@
<div id="notes">
{% for item in inbox_data %}
{% if item | has_type('Create') %}
{{ utils.display_note(item.activity.object, ui=True) }}
{{ utils.display_note(item.activity.object, ui=True, meta=item.meta) }}
{% else %}
{% if item | has_type('Announce') %}