Merge pull request #310 from mouse-reeve/unboost

Unboost
This commit is contained in:
Mouse Reeve 2020-11-07 19:00:10 -08:00 committed by GitHub
commit aa170d0d6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 154 additions and 144 deletions

View file

@ -299,7 +299,7 @@ def handle_unboost(activity):
remote_id=activity['object']['id'] remote_id=activity['object']['id']
).first() ).first()
if boost: if boost:
status_builder.delete_status(boost) boost.delete()
@app.task @app.task

View file

@ -320,6 +320,17 @@ def handle_boost(user, status):
broadcast(user, boost_activity) broadcast(user, boost_activity)
def handle_unboost(user, status):
''' a user regrets boosting a status '''
boost = models.Boost.objects.filter(
boosted_status=status, user=user
).first()
activity = boost.to_undo_activity(user)
boost.delete()
broadcast(user, activity)
def handle_update_book(user, book): def handle_update_book(user, book):
''' broadcast the news about our book ''' ''' broadcast the news about our book '''
broadcast(user, book.to_update_activity(user)) broadcast(user, book.to_update_activity(user))

View file

@ -1,6 +1,6 @@
{% load fr_display %} {% load fr_display %}
{% with activity.id|uuid as uuid %} {% with status.id|uuid as uuid %}
<form name="boost" action="/boost/{{ activity.id }}" method="post" onsubmit="return interact(event)" class="boost-{{ status.id }}-{{ uuid }} {% if request.user|boosted:status %}hidden{% endif %}" data-id="boost-{{ status.id }}-{{ uuid }}"> <form name="boost" action="/boost/{{ status.id }}" method="post" onsubmit="return interact(event)" class="boost-{{ status.id }}-{{ uuid }} {% if request.user|boosted:status %}hidden{% endif %}" data-id="boost-{{ status.id }}-{{ uuid }}">
{% csrf_token %} {% csrf_token %}
<button class="button is-small" type="submit"> <button class="button is-small" type="submit">
<span class="icon icon-boost"> <span class="icon icon-boost">
@ -8,7 +8,7 @@
</span> </span>
</button> </button>
</form> </form>
<form name="unboost" action="/unboost/{{ activity.id }}" method="post" onsubmit="return interact(event)" class="boost-{{ status.id }}-{{ uuid }} active {% if not request.user|boosted:status %}hidden{% endif %}" data-id="boost-{{ status.id }}-{{ uuid }}"> <form name="unboost" action="/unboost/{{ status.id }}" method="post" onsubmit="return interact(event)" class="boost-{{ status.id }}-{{ uuid }} active {% if not request.user|boosted:status %}hidden{% endif %}" data-id="boost-{{ status.id }}-{{ uuid }}">
{% csrf_token %} {% csrf_token %}
<button class="button is-small is-success" type="submit"> <button class="button is-small is-success" type="submit">
<span class="icon icon-boost"> <span class="icon icon-boost">

View file

@ -1,6 +1,6 @@
{% load fr_display %} {% load fr_display %}
{% with activity.id|uuid as uuid %} {% with status.id|uuid as uuid %}
<form name="favorite" action="/favorite/{{ activity.id }}" method="POST" onsubmit="return interact(event)" class="fav-{{ status.id }}-{{ uuid }} {% if request.user|liked:status %}hidden{% endif %}" data-id="fav-{{ status.id }}-{{ uuid }}"> <form name="favorite" action="/favorite/{{ status.id }}" method="POST" onsubmit="return interact(event)" class="fav-{{ status.id }}-{{ uuid }} {% if request.user|liked:status %}hidden{% endif %}" data-id="fav-{{ status.id }}-{{ uuid }}">
{% csrf_token %} {% csrf_token %}
<button class="button is-small" type="submit"> <button class="button is-small" type="submit">
<span class="icon icon-heart"> <span class="icon icon-heart">
@ -8,7 +8,7 @@
</span> </span>
</button> </button>
</form> </form>
<form name="unfavorite" action="/unfavorite/{{ activity.id }}" method="POST" onsubmit="return interact(event)" class="fav-{{ status.id }}-{{ uuid }} active {% if not request.user|liked:status %}hidden{% endif %}" data-id="fav-{{ status.id }}-{{ uuid }}"> <form name="unfavorite" action="/unfavorite/{{ status.id }}" method="POST" onsubmit="return interact(event)" class="fav-{{ status.id }}-{{ uuid }} active {% if not request.user|liked:status %}hidden{% endif %}" data-id="fav-{{ status.id }}-{{ uuid }}">
{% csrf_token %} {% csrf_token %}
<button class="button is-success is-small" type="submit"> <button class="button is-success is-small" type="submit">
<span class="icon icon-heart"> <span class="icon icon-heart">

View file

@ -1,142 +1,11 @@
{% load humanize %}
{% load fr_display %} {% load fr_display %}
{% if not status.deleted %} {% if not status.deleted %}
<div class="card"> {% if status.status_type == 'Boost' %}
<header class="card-header">
<div class="card-header-title">
<div class="columns">
<div class="column is-narrow">
{% if status.status_type == 'Boost' %}
{% include 'snippets/avatar.html' with user=status.user %}
{% include 'snippets/username.html' with user=status.user %}
boosted
</div>
<div class="column">
{% include 'snippets/status_header.html' with status=status|boosted_status %}
{% else %}
{% include 'snippets/status_header.html' with status=status %}
{% endif %}
</div>
</div>
</div>
</header>
<div class="card-content">
{% if status.status_type == 'Boost' %}
{% include 'snippets/status_content.html' with status=status|boosted_status %}
{% else %}
{% include 'snippets/status_content.html' with status=status %}
{% endif %}
</div>
<footer>
{% if request.user.is_authenticated %}
<input class="toggle-control" type="checkbox" name="show-comment-{{ status.id }}" id="show-comment-{{ status.id }}">
<div class="toggle-content hidden">
<div class="card-footer">
<div class="card-footer-item">
{% if status.status_type == 'Boost' %}
{% include 'snippets/reply_form.html' with status=status|boosted_status %}
{% else %}
{% include 'snippets/reply_form.html' with status=status %}
{% endif %}
</div>
</div>
</div>
{% endif %}
<div class="card-footer">
<div class="card-footer-item">
{% if request.user.is_authenticated %}
<label class="button is-small" for="show-comment-{{ status.id }}">
<span class="icon icon-comment"><span class="is-sr-only">Comment</span></span>
</label>
{% if status.status_type == 'Boost' %}
{% include 'snippets/boost_button.html' with status=status|boosted_status %}
{% include 'snippets/fav_button.html' with status=status|boosted_status %}
{% else %}
{% include 'snippets/boost_button.html' with status=status %}
{% include 'snippets/fav_button.html' with status=status %}
{% endif %}
{% else %}
<a href="/login">
<span class="icon icon-comment">
<span class="is-sr-only">Comment</span>
</span>
<span class="icon icon-boost">
<span class="is-sr-only">Boost status</span>
</span>
<span class="icon icon-heart">
<span class="is-sr-only">Like status</span>
</span>
</a>
{% endif %}
</div>
<div class="card-footer-item">
{% if status.privacy == 'public' %}
<span class="icon icon-globe">
<span class="is-sr-only">Public post</span>
</span>
{% elif status.privacy == 'unlisted' %}
<span class="icon icon-unlock">
<span class="is-sr-only">Unlisted post</span>
</span>
{% elif status.privacy == 'followers' %}
<span class="icon icon-lock">
<span class="is-sr-only">Followers-only post</span>
</span>
{% else %}
<span class="icon icon-envelope">
<span class="is-sr-only">Private post</span>
</span>
{% endif %}
</div>
<div class="card-footer-item">
<a href="{{ status.remote_id }}">{{ status.published_date | post_date }}</a>
</div>
{% if status.user == request.user %}
<div class="card-footer-item">
<label class="button" for="more-info-{{ status.id }}">
<div class="icon icon-dots-three">
<span class="is-sr-only">More options</span>
</div>
</label>
</div>
{% endif %}
</div>
<div>
<input class="toggle-control" type="checkbox" name="more-info-{{ status.id }}" id="more-info-{{ status.id }}">
<div class="toggle-content hidden card-footer">
{% if status.user == request.user %}
<div class="card-footer-item">
<form name="delete-{{status.id}}" action="/delete-status" method="post">
{% csrf_token %}
<input type="hidden" name="status" value="{{ status.id }}">
<button class="button is-danger" type="submit">
Delete post
</button>
</form>
</div>
{% endif %}
</div>
</div>
</footer>
</div>
{% else %}
<div class="card">
<header class="card-header">
<p>
{% include 'snippets/avatar.html' with user=status.user %} {% include 'snippets/avatar.html' with user=status.user %}
{% include 'snippets/username.html' with user=status.user %} {% include 'snippets/username.html' with user=status.user %}
deleted this status boosted
</p> {% include 'snippets/status_body.html' with status=status|boosted_status %}
</header> {% else %}
</div> {% include 'snippets/status_body.html' with status=status %}
{% endif %}
{% endif %} {% endif %}

View file

@ -0,0 +1,120 @@
{% load fr_display %}
{% load humanize %}
{% if not status.deleted %}
<div class="card">
<header class="card-header">
<div class="card-header-title">
<div class="columns">
<div class="column is-narrow">
{% include 'snippets/status_header.html' with status=status %}
</div>
</div>
</div>
</header>
<div class="card-content">
{% include 'snippets/status_content.html' with status=status %}
</div>
<footer>
{% if request.user.is_authenticated %}
<input class="toggle-control" type="checkbox" name="show-comment-{{ status.id }}" id="show-comment-{{ status.id }}">
<div class="toggle-content hidden">
<div class="card-footer">
<div class="card-footer-item">
{% include 'snippets/reply_form.html' with status=status %}
</div>
</div>
</div>
{% endif %}
<div class="card-footer">
<div class="card-footer-item">
{% if request.user.is_authenticated %}
<label class="button is-small" for="show-comment-{{ status.id }}">
<span class="icon icon-comment"><span class="is-sr-only">Comment</span></span>
</label>
{% include 'snippets/boost_button.html' with status=status %}
{% include 'snippets/fav_button.html' with status=status %}
{% else %}
<a href="/login">
<span class="icon icon-comment">
<span class="is-sr-only">Comment</span>
</span>
<span class="icon icon-boost">
<span class="is-sr-only">Boost status</span>
</span>
<span class="icon icon-heart">
<span class="is-sr-only">Like status</span>
</span>
</a>
{% endif %}
</div>
<div class="card-footer-item">
{% if status.privacy == 'public' %}
<span class="icon icon-globe">
<span class="is-sr-only">Public post</span>
</span>
{% elif status.privacy == 'unlisted' %}
<span class="icon icon-unlock">
<span class="is-sr-only">Unlisted post</span>
</span>
{% elif status.privacy == 'followers' %}
<span class="icon icon-lock">
<span class="is-sr-only">Followers-only post</span>
</span>
{% else %}
<span class="icon icon-envelope">
<span class="is-sr-only">Private post</span>
</span>
{% endif %}
</div>
<div class="card-footer-item">
<a href="{{ status.remote_id }}">{{ status.published_date | post_date }}</a>
</div>
{% if status.user == request.user %}
<div class="card-footer-item">
<label class="button" for="more-info-{{ status.id }}">
<div class="icon icon-dots-three">
<span class="is-sr-only">More options</span>
</div>
</label>
</div>
{% endif %}
</div>
<div>
<input class="toggle-control" type="checkbox" name="more-info-{{ status.id }}" id="more-info-{{ status.id }}">
<div class="toggle-content hidden card-footer">
{% if status.user == request.user %}
<div class="card-footer-item">
<form name="delete-{{status.id}}" action="/delete-status" method="post">
{% csrf_token %}
<input type="hidden" name="status" value="{{ status.id }}">
<button class="button is-danger" type="submit">
Delete post
</button>
</form>
</div>
{% endif %}
</div>
</div>
</footer>
</div>
{% else %}
<div class="card">
<header class="card-header">
<p>
{% include 'snippets/avatar.html' with user=status.user %}
{% include 'snippets/username.html' with user=status.user %}
deleted this status
</p>
</header>
</div>
{% endif %}

View file

@ -116,6 +116,7 @@ urlpatterns = [
re_path(r'^favorite/(?P<status_id>\d+)/?$', actions.favorite), re_path(r'^favorite/(?P<status_id>\d+)/?$', actions.favorite),
re_path(r'^unfavorite/(?P<status_id>\d+)/?$', actions.unfavorite), re_path(r'^unfavorite/(?P<status_id>\d+)/?$', actions.unfavorite),
re_path(r'^boost/(?P<status_id>\d+)/?$', actions.boost), re_path(r'^boost/(?P<status_id>\d+)/?$', actions.boost),
re_path(r'^unboost/(?P<status_id>\d+)/?$', actions.unboost),
re_path(r'^delete-status/?$', actions.delete_status), re_path(r'^delete-status/?$', actions.delete_status),

View file

@ -508,6 +508,7 @@ def unfavorite(request, status_id):
outgoing.handle_unfavorite(request.user, status) outgoing.handle_unfavorite(request.user, status)
return redirect(request.headers.get('Referer', '/')) return redirect(request.headers.get('Referer', '/'))
@login_required @login_required
def boost(request, status_id): def boost(request, status_id):
''' boost a status ''' ''' boost a status '''
@ -516,6 +517,14 @@ def boost(request, status_id):
return redirect(request.headers.get('Referer', '/')) return redirect(request.headers.get('Referer', '/'))
@login_required
def unboost(request, status_id):
''' boost a status '''
status = models.Status.objects.get(id=status_id)
outgoing.handle_unboost(request.user, status)
return redirect(request.headers.get('Referer', '/'))
@login_required @login_required
def delete_status(request): def delete_status(request):
''' delete and tombstone a status ''' ''' delete and tombstone a status '''