forked from forks/microblog.pub
Finish support for pinned/featured note
This commit is contained in:
parent
f23dbcaf05
commit
a5e0983ca8
4 changed files with 91 additions and 6 deletions
51
app.py
51
app.py
|
@ -803,14 +803,25 @@ def index():
|
|||
"activity.object.inReplyTo": None,
|
||||
"meta.deleted": False,
|
||||
"meta.undo": False,
|
||||
"$or": [{"meta.pinned": False}, {"meta.pinned": {"$exists": False}}],
|
||||
}
|
||||
outbox_data, older_than, newer_than = paginated_query(DB.activities, q)
|
||||
|
||||
q_pinned = {
|
||||
"box": Box.OUTBOX.value,
|
||||
"type": ActivityType.CREATE.value,
|
||||
"meta.deleted": False,
|
||||
"meta.undo": False,
|
||||
"meta.pinned": True,
|
||||
}
|
||||
pinned = list(DB.activities.find(q_pinned))
|
||||
outbox_data, older_than, newer_than = paginated_query(
|
||||
DB.activities, q, limit=25 - len(pinned)
|
||||
)
|
||||
return render_template(
|
||||
"index.html",
|
||||
outbox_data=outbox_data,
|
||||
older_than=older_than,
|
||||
newer_than=newer_than,
|
||||
pinned=pinned,
|
||||
)
|
||||
|
||||
|
||||
|
@ -1453,6 +1464,32 @@ def api_like():
|
|||
return _user_api_response(activity=like.id)
|
||||
|
||||
|
||||
@app.route("/api/note/pin", methods=["POST"])
|
||||
@api_required
|
||||
def api_pin():
|
||||
note = _user_api_get_note(from_outbox=True)
|
||||
|
||||
DB.activities.update_one(
|
||||
{"activity.object.id": note.id, "box": Box.OUTBOX.value},
|
||||
{"$set": {"meta.pinned": True}},
|
||||
)
|
||||
|
||||
return _user_api_response(pinned=True)
|
||||
|
||||
|
||||
@app.route("/api/note/unpin", methods=["POST"])
|
||||
@api_required
|
||||
def api_unpin():
|
||||
note = _user_api_get_note(from_outbox=True)
|
||||
|
||||
DB.activities.update_one(
|
||||
{"activity.object.id": note.id, "box": Box.OUTBOX.value},
|
||||
{"$set": {"meta.pinned": False}},
|
||||
)
|
||||
|
||||
return _user_api_response(pinned=False)
|
||||
|
||||
|
||||
@app.route("/api/undo", methods=["POST"])
|
||||
@api_required
|
||||
def api_undo():
|
||||
|
@ -1783,7 +1820,15 @@ def tags(tag):
|
|||
def featured():
|
||||
if not is_api_request():
|
||||
abort(404)
|
||||
return jsonify(**activitypub.simple_build_ordered_collection("featured", []))
|
||||
q = {
|
||||
"box": Box.OUTBOX.value,
|
||||
"type": ActivityType.CREATE.value,
|
||||
"meta.deleted": False,
|
||||
"meta.undo": False,
|
||||
"meta.pinned": True,
|
||||
}
|
||||
data = [clean_activity(doc["activity"]["object"]) for doc in DB.activities.find(q)]
|
||||
return jsonify(**activitypub.simple_build_ordered_collection("featured", data))
|
||||
|
||||
|
||||
@app.route("/liked")
|
||||
|
|
|
@ -237,13 +237,27 @@ a:hover {
|
|||
.og-link { text-decoration: none; }
|
||||
.og-link:hover { text-decoration: none; }
|
||||
.bar-item-no-hover {
|
||||
cursor: default;
|
||||
background: $color-menu-background;
|
||||
padding: 5px;
|
||||
color: $color-light;
|
||||
margin-right:5px;
|
||||
border-radius:2px;
|
||||
}
|
||||
|
||||
.bar-item-no-hover:hover {
|
||||
cursor: default;
|
||||
}
|
||||
.bar-item-pinned {
|
||||
cursor: default;
|
||||
background: $color-menu-background;
|
||||
color: $color-light;
|
||||
padding: 5px;
|
||||
margin-right:5px;
|
||||
border-radius:2px;
|
||||
}
|
||||
.bar-item-pinned:hover {
|
||||
cursor: default;
|
||||
}
|
||||
.bar-item {
|
||||
background: $color-menu-background;
|
||||
padding: 5px;
|
||||
|
|
|
@ -21,6 +21,16 @@
|
|||
{% include "header.html" %}
|
||||
|
||||
<div id="notes">
|
||||
{% for item in pinned %}
|
||||
{% if item.meta.pinned %}
|
||||
<p style="margin-left:65px;padding-bottom:5px;">
|
||||
<span class="bar-item-pinned">pinned</span>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{{ utils.display_note(item.activity.object, meta=item.meta, no_color=True) }}
|
||||
{% endfor %}
|
||||
|
||||
{% for item in outbox_data %}
|
||||
|
||||
{% if item | has_type('Announce') %}
|
||||
|
|
|
@ -105,8 +105,8 @@
|
|||
{% elif meta.count_reply and session.logged_in %}
|
||||
<a class ="bar-item" href="/admin/thread?oid={{aid}}"><strong>{{ meta.count_reply }}</strong> replies</a>{% endif %}
|
||||
|
||||
{% if meta.count_boost and obj.id | is_from_outbox %}<a class ="bar-item" href="{{ obj.url | get_url }}"><strong>{{ meta.count_boost }}</strong> boosts</a>{% endif %}
|
||||
{% if meta.count_like and obj.id | is_from_outbox %}<a class ="bar-item" href="{{ obj.url | get_url }}"><strong>{{ meta.count_like }}</strong> likes</a>{% endif %}
|
||||
{% if not perma and meta.count_boost and obj.id | is_from_outbox %}<a class ="bar-item" href="{{ obj.url | get_url }}"><strong>{{ meta.count_boost }}</strong> boosts</a>{% endif %}
|
||||
{% if not perma and meta.count_like and obj.id | is_from_outbox %}<a class ="bar-item" href="{{ obj.url | get_url }}"><strong>{{ meta.count_like }}</strong> likes</a>{% endif %}
|
||||
|
||||
{% if session.logged_in %}
|
||||
{% if ui%}
|
||||
|
@ -153,6 +153,22 @@
|
|||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button type="submit" class="bar-item">delete</button>
|
||||
</form>
|
||||
{% if meta.pinned %}
|
||||
<form action="/api/note/unpin" class="action-form" method="POST">
|
||||
<input type="hidden" name="redirect" value="{{ redir }}">
|
||||
<input type="hidden" name="id" value="{{ obj.id }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button type="submit" class="bar-item">unpin</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form action="/api/note/pin" class="action-form" method="POST">
|
||||
<input type="hidden" name="redirect" value="{{ redir }}">
|
||||
<input type="hidden" name="id" value="{{ obj.id }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button type="submit" class="bar-item">pin</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<form action="/api/block" class="action-form" method="POST">
|
||||
<input type="hidden" name="redirect" value="{{ redir }}">
|
||||
|
|
Loading…
Reference in a new issue