diff --git a/aurweb/routers/packages.py b/aurweb/routers/packages.py
index 92fc9361..681cde4f 100644
--- a/aurweb/routers/packages.py
+++ b/aurweb/routers/packages.py
@@ -131,6 +131,10 @@ async def make_single_context(request: Request,
context["comments"] = pkgbase.comments.order_by(
PackageComment.CommentTS.desc()
)
+ context["pinned_comments"] = pkgbase.comments.filter(
+ PackageComment.PinnedTS != 0
+ ).order_by(PackageComment.CommentTS.desc())
+
context["is_maintainer"] = (request.user.is_authenticated()
and request.user.ID == pkgbase.MaintainerUID)
context["notified"] = request.user.notified(pkgbase)
@@ -343,3 +347,25 @@ async def pkgbase_comment_undelete(request: Request, name: str, id: int):
return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER))
+
+
+@router.post("/pkgbase/{name}/comments/{id}/pin")
+@auth_required(True)
+async def pkgbase_comment_pin(request: Request, name: str, id: int):
+ pkgbase = get_pkg_or_base(name, PackageBase)
+ comment = get_pkgbase_comment(pkgbase, id)
+
+ has_cred = request.user.has_credential("CRED_COMMENT_PIN",
+ approved=[pkgbase.Maintainer])
+ if not has_cred:
+ _ = l10n.get_translator_for_request(request)
+ raise HTTPException(
+ status_code=int(HTTPStatus.UNAUTHORIZED),
+ detail=_("You are not allowed to pin this comment."))
+
+ now = int(datetime.utcnow().timestamp())
+ with db.begin():
+ comment.PinnedTS = now
+
+ return RedirectResponse(f"/pkgbase/{name}",
+ status_code=int(HTTPStatus.SEE_OTHER))
diff --git a/templates/packages/show.html b/templates/packages/show.html
index 0bf8d9fd..ba531fc8 100644
--- a/templates/packages/show.html
+++ b/templates/packages/show.html
@@ -18,7 +18,5 @@
{% set pkgname = result.Name %}
{% set pkgbase_id = result.ID %}
- {% if comments.count() %}
- {% include "partials/packages/comments.html" %}
- {% endif %}
+ {% include "partials/packages/comments.html" %}
{% endblock %}
diff --git a/templates/partials/packages/comment.html b/templates/partials/packages/comment.html
index 6af5cd9e..97f11723 100644
--- a/templates/partials/packages/comment.html
+++ b/templates/partials/packages/comment.html
@@ -49,16 +49,38 @@
{% endif %}
- {% if request.user.has_credential("CRED_COMMENT_PIN", approved=[pkgbase.Maintainer]) %}
-
+ {{ "Pinned Comments" | tr }} + +
+