diff options
author | Magnus Hagander | 2018-02-21 17:31:54 +0000 |
---|---|---|
committer | Magnus Hagander | 2018-02-21 17:45:19 +0000 |
commit | b8274b5875a4742800307ed645f1137c10e2a09d (patch) | |
tree | fd91a0b4b27e7f822c8bedfcf976c5662b152621 /pgcommitfest/commitfest | |
parent | da4c56069c8f61dd7e8f499827618e527e1a4a1b (diff) |
Implement thread notification receiving
This allows the archivs server to ping the CF app to pick up updates to
mailthreads quicker.
Diffstat (limited to 'pgcommitfest/commitfest')
-rw-r--r-- | pgcommitfest/commitfest/ajax.py | 16 | ||||
-rw-r--r-- | pgcommitfest/commitfest/util.py | 1 | ||||
-rw-r--r-- | pgcommitfest/commitfest/views.py | 24 |
3 files changed, 40 insertions, 1 deletions
diff --git a/pgcommitfest/commitfest/ajax.py b/pgcommitfest/commitfest/ajax.py index cffc33d..b65de8d 100644 --- a/pgcommitfest/commitfest/ajax.py +++ b/pgcommitfest/commitfest/ajax.py @@ -79,6 +79,22 @@ def getMessages(request): r = _archivesAPI('/message-id.json/%s' % thread.messageid) return sorted(r, key=lambda x: x['date'], reverse=True) +def refresh_single_thread(thread): + r = sorted(_archivesAPI('/message-id.json/%s' % thread.messageid), key=lambda x: x['date']) + if thread.latestmsgid != r[-1]['msgid']: + # There is now a newer mail in the thread! + thread.latestmsgid = r[-1]['msgid'] + thread.latestmessage = r[-1]['date'] + thread.latestauthor = r[-1]['from'] + thread.latestsubject = r[-1]['subj'] + thread.save() + parse_and_add_attachments(r, thread) + # Potentially update the last mail date - if there wasn't already a mail on each patch + # from a *different* thread that had an earlier date. + for p in thread.patches.filter(lastmail__lt=thread.latestmessage): + p.lastmail = thread.latestmessage + p.save() + @transaction.atomic def annotateMessage(request): thread = get_object_or_404(MailThread, pk=int(request.POST['t'])) diff --git a/pgcommitfest/commitfest/util.py b/pgcommitfest/commitfest/util.py index 7a38c7b..84f543d 100644 --- a/pgcommitfest/commitfest/util.py +++ b/pgcommitfest/commitfest/util.py @@ -41,3 +41,4 @@ class DiffableModel(object): fields = [field.name for field in self._meta.fields] fields.extend([field.name for field in self._meta.many_to_many]) return model_to_dict(self, fields=fields) + diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py index 8eadafa..68bdbef 100644 --- a/pgcommitfest/commitfest/views.py +++ b/pgcommitfest/commitfest/views.py @@ -14,14 +14,16 @@ from django.conf import settings from datetime import datetime from email.mime.text import MIMEText from email.utils import formatdate, make_msgid +import json from pgcommitfest.mailqueue.util import send_mail, send_simple_mail from pgcommitfest.userprofile.util import UserWrapper from models import CommitFest, Patch, PatchOnCommitFest, PatchHistory, Committer +from models import MailThread from forms import PatchForm, NewPatchForm, CommentForm, CommitFestFilterForm from forms import BulkEmailForm -from ajax import doAttachThread +from ajax import doAttachThread, refresh_single_thread from feeds import ActivityFeed def home(request): @@ -662,3 +664,23 @@ def send_email(request, cfid): 'breadcrumbs': [{'title': cf.title, 'href': '/%s/' % cf.pk},], 'savebutton': 'Send email', }) + + +@csrf_exempt +def thread_notify(request): + if request.method != 'POST': + return HttpResponseForbidden("Invalid method") + + j = json.loads(request.body) + if j['apikey'] != settings.ARCHIVES_APIKEY: + return HttpResponseForbidden("Invalid API key") + + for m in j['messageids']: + try: + t = MailThread.objects.get(messageid=m) + refresh_single_thread(t) + except Exception, e: + # Just ignore it, we'll check again later + pass + + return HttpResponse(status=200) |