mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 13:14:28 +00:00
Add boomarks feature/admin section
This commit is contained in:
parent
96a9835593
commit
737949e197
3 changed files with 61 additions and 4 deletions
45
app.py
45
app.py
|
@ -171,15 +171,17 @@ def inject_config():
|
|||
"meta.undo": False,
|
||||
}
|
||||
|
||||
logged_in = session.get("logged_in", False)
|
||||
|
||||
return dict(
|
||||
microblogpub_version=VERSION,
|
||||
config=config,
|
||||
logged_in=session.get("logged_in", False),
|
||||
logged_in=logged_in,
|
||||
followers_count=DB.activities.count(followers_q),
|
||||
following_count=DB.activities.count(following_q),
|
||||
following_count=DB.activities.count(following_q) if logged_in else 0,
|
||||
notes_count=notes_count,
|
||||
liked_count=liked_count,
|
||||
with_replies_count=with_replies_count,
|
||||
with_replies_count=with_replies_count if logged_in else 0,
|
||||
me=ME,
|
||||
base_url=config.BASE_URL,
|
||||
)
|
||||
|
@ -1718,6 +1720,23 @@ def api_like():
|
|||
return _user_api_response(activity=like_id)
|
||||
|
||||
|
||||
@app.route("/api/bookmark", methods=["POST"])
|
||||
@api_required
|
||||
def api_bookmark():
|
||||
note = _user_api_get_note()
|
||||
|
||||
undo = _user_api_arg("undo", default=None) == "yes"
|
||||
|
||||
DB.activities.update_one(
|
||||
{"meta.object.id": note.id}, {"$set": {"meta.bookmarked": not undo}}
|
||||
)
|
||||
DB.activities.update_one(
|
||||
{"activity.object.id": note.id}, {"$set": {"meta.bookmarked": not undo}}
|
||||
)
|
||||
|
||||
return _user_api_response()
|
||||
|
||||
|
||||
@app.route("/api/note/pin", methods=["POST"])
|
||||
@api_required
|
||||
def api_pin():
|
||||
|
@ -1785,6 +1804,26 @@ def admin_stream():
|
|||
)
|
||||
|
||||
|
||||
@app.route("/admin/bookmarks")
|
||||
@login_required
|
||||
def admin_bookmarks():
|
||||
q = {"meta.bookmarked": True}
|
||||
|
||||
tpl = "stream.html"
|
||||
if request.args.get("debug"):
|
||||
tpl = "stream_debug.html"
|
||||
if request.args.get("debug_inbox"):
|
||||
q = {}
|
||||
|
||||
inbox_data, older_than, newer_than = paginated_query(
|
||||
DB.activities, q, limit=int(request.args.get("limit", 25))
|
||||
)
|
||||
|
||||
return render_template(
|
||||
tpl, inbox_data=inbox_data, older_than=older_than, newer_than=newer_than
|
||||
)
|
||||
|
||||
|
||||
@app.route("/inbox", methods=["GET", "POST"]) # noqa: C901
|
||||
def inbox():
|
||||
if request.method == "GET":
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
<li class="left"><a href="/" class="admin-title {% if not request.path.startswith("/admin") %} selected{% endif %}">Public</a></li>
|
||||
<li class="left"><a href="/admin/new"{% if request.path == "/admin/new" %} class="selected" {% endif %}>New</a></li>
|
||||
<li class="left"><a href="/admin/stream"{% if request.path == "/admin/stream" %} class="selected" {% endif %}>Stream</a></li>
|
||||
<li class="left"><a href="/admin/bookmarks"{% if request.path == "/admin/bookmarks" %} class="selected" {% endif %}>Bookmarks</a></li>
|
||||
<li class="left"><a href="/admin/notifications"{% if request.path == "/admin/notifications" %} class="selected" {% endif %}>Notifications</a></li>
|
||||
<li class="left"><a href="/following"{% if request.path == "/following" %} class="selected" {% endif %}>Following</a></li>
|
||||
<li class="left"><a href="/admin/lookup"{% if request.path == "/admin/lookup" %} class="selected" {% endif %}>Lookup</a></li>
|
||||
<li class="left"><a href="/admin/logout">Logout</a></li>
|
||||
</ul>
|
||||
|
|
|
@ -212,6 +212,24 @@
|
|||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if meta.bookmarked or request.path == url_for("admin_bookmarks") %}
|
||||
<form action="/api/bookmark" class="action-form" method="POST">
|
||||
<input type="hidden" name="redirect" value="{{ redir }}">
|
||||
<input type="hidden" name="id" value="{{ obj.id }}">
|
||||
<input type="hidden" name="undo" value="yes">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button type="submit" class="bar-item">unbookmark</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form action="/api/bookmark" 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">bookmark</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if obj.id | is_from_outbox %}
|
||||
|
|
Loading…
Reference in a new issue