From ba06c450b8c49f0b12ab1e5887fef164a5db1974 Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Tue, 9 May 2023 11:13:18 +0200 Subject: [PATCH] add an indicator about the amount of replies in the aur-requests thread related to https://gitlab.archlinux.org/archlinux/aurweb/-/issues/356 Signed-off-by: Christian Heusel --- aurweb/models/package_request.py | 17 +++++++++++++++++ conf/config.defaults | 1 + templates/requests.html | 12 +++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/aurweb/models/package_request.py b/aurweb/models/package_request.py index 94ff064b..8796f0c7 100644 --- a/aurweb/models/package_request.py +++ b/aurweb/models/package_request.py @@ -1,6 +1,7 @@ import base64 import hashlib +import requests from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import backref, relationship @@ -119,3 +120,19 @@ class PackageRequest(Base): """Return the mailing list URL for the request.""" url = config.get("options", "ml_thread_url") % (self.ml_message_id_hash()) return url + + def ml_message_api_url(self) -> str: + """Return the mailing list API URL for the request.""" + url = config.get("options", "ml_thread_api_url") % (self.ml_message_id_hash()) + return url + + def ml_message_reply_count(self) -> int: + """Return the number of replies in thread""" + url = self.ml_message_api_url() + count = 0 + response = requests.get(url, params="?format=json") + if response.status_code == 200: + response = response.json() + for message in response: + count += len(message.get("children", [])) + return count diff --git a/conf/config.defaults b/conf/config.defaults index 0cd4b9d4..4c890407 100644 --- a/conf/config.defaults +++ b/conf/config.defaults @@ -26,6 +26,7 @@ max_search_results = 2500 max_depends = 1000 aur_request_ml = aur-requests@lists.archlinux.org ml_thread_url = https://lists.archlinux.org/archives/list/aur-requests@lists.archlinux.org/thread/%s +ml_thread_api_url = https://lists.archlinux.org/archives/api/list/aur-requests@lists.archlinux.org/thread/%s/emails/ request_idle_time = 1209600 request_archive_time = 15552000 auto_orphan_age = 15552000 diff --git a/templates/requests.html b/templates/requests.html index 697fbedb..78480de8 100644 --- a/templates/requests.html +++ b/templates/requests.html @@ -80,6 +80,7 @@ {{ "Type" | tr }} {{ "Comments" | tr }} {{ "Filed by" | tr }} + {{ "Thread" | tr }} {{ "Date" | tr }} {{ "Status" | tr }} @@ -108,6 +109,7 @@ {# Comments #} {{ result.Comments }} + {# Filed by #} {# If the record has an associated User, display a link to that user. #} @@ -117,10 +119,18 @@ {{ result.User.Username }}   {% endif %} + + + {% set reply_count = result.ml_message_reply_count() %} + - (PRQ#{{ result.ID }}) + [PRQ#{{ result.ID }}] + {% if reply_count > 0 %} + - {{ reply_count }} 📧 + {% endif %} + {% set idle_time = config_getint("options", "request_idle_time") %} {% set time_delta = (utcnow - result.RequestTS) | int %}