From 639524b9a473961595460aee6d927735b9d8d601 Mon Sep 17 00:00:00 2001 From: Luca Date: Mon, 8 May 2023 21:07:43 +0200 Subject: [PATCH] Mark incoming messages as read when sending outgoing message, replace $token --- shiftregister/team/views.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shiftregister/team/views.py b/shiftregister/team/views.py index 8ba4717..5407426 100644 --- a/shiftregister/team/views.py +++ b/shiftregister/team/views.py @@ -164,7 +164,14 @@ class HelperDetail(FormMixin, LoginRequiredMixin, DetailView): form = self.get_form() if form.is_valid(): - Message(text=form.cleaned_data["message"], to=self.object).save() + IncomingMessage.objects.filter(sender=self.object.phone).update(read=True) + Message( + text=form.cleaned_data["message"].replace( + "$token", + f"https://helfen.kntkt.de{self.object.logintoken_set.first().get_absolute_url()}", + ), + to=self.object, + ).save() return self.render_to_response(self.get_context_data(form=form))