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 9b3023d7..1ab5080d 100644 --- a/conf/config.defaults +++ b/conf/config.defaults @@ -30,6 +30,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 a6b2ae46..3674cc1f 100644 --- a/templates/requests.html +++ b/templates/requests.html @@ -86,6 +86,7 @@ {{ "Type" | tr }} {{ "Comments" | tr }} {{ "Filed by" | tr }} + {{ "Thread" | tr }} {{ "Date" | tr }} {{ "Status" | tr }} @@ -116,6 +117,7 @@ {# Comments #} {{ result.Comments }} + {# Filed by #} {# If the record has an associated User, display a link to that user. #} @@ -125,10 +127,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 %}