<p></p>
<p><b>@grekko</b> commented on this pull request.</p>
<hr>
<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4284#discussion_r1373619275">app/controllers/messages_controller.rb</a>:</p>
<pre style='color:#555'>> @@ -47,7 +47,7 @@ def create
render :action => "new"
elsif @message.save
flash[:notice] = t ".message_sent"
- UserMailer.message_notification(@message).deliver_later
+ @message.notify_recipient_via_mail
</pre>
<blockquote>
<p dir="auto">I think it should be the controller that decides what is the list of things that should be done.</p>
</blockquote>
<p dir="auto">I think that is still the case. The controller still makes the call, but now there is this extra logic which is imo a detail that the controller does not need to bother about.</p>
<p dir="auto">I understand though that currently all direct calls to the <code class="notranslate">UserMailer</code> are made either from within the context of a Controller or Job and my change deviates from that pattern.</p>
<p dir="auto">To me it is important that the logic wether a E-Mail Notification should be sent is kept in a single place and is not spread across the application code.</p>
<p dir="auto">What do you think about this version?</p>
<div class="highlight highlight-source-diff" dir="auto"><pre class="notranslate"><span class="pl-c1">diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb</span>
index 21d08e7af..2ca86fc02 100644
<span class="pl-md">--- a/app/controllers/messages_controller.rb</span>
<span class="pl-mi1">+++ b/app/controllers/messages_controller.rb</span>
<span class="pl-mdr">@@ -47,7 +47,7 @@</span> class MessagesController < ApplicationController
render :action => "new"
elsif @message.save
flash[:notice] = t ".message_sent"
<span class="pl-md"><span class="pl-md">-</span> @message.notify_recipient_via_mail</span>
<span class="pl-mi1"><span class="pl-mi1">+</span> UserMailer.message_notification(@message).deliver_later if @message.notify_recipient?</span>
redirect_to :action => :inbox
else
@title = t "messages.new.title"
<span class="pl-c1">diff --git a/app/models/message.rb b/app/models/message.rb</span>
index 1be482cfb..fdeb89c4b 100644
<span class="pl-md">--- a/app/models/message.rb</span>
<span class="pl-mi1">+++ b/app/models/message.rb</span>
<span class="pl-mdr">@@ -74,10 +74,8 @@</span> class Message < ApplicationRecord
md5.hexdigest
end
<span class="pl-md"><span class="pl-md">-</span> def notify_recipient_via_mail</span>
<span class="pl-md"><span class="pl-md">-</span> return false if muted?</span>
<span class="pl-md"><span class="pl-md">-</span></span>
<span class="pl-md"><span class="pl-md">-</span> UserMailer.message_notification(self).deliver_later</span>
<span class="pl-mi1"><span class="pl-mi1">+</span> def notify_recipient?</span>
<span class="pl-mi1"><span class="pl-mi1">+</span> !muted?</span>
end
def unmute
<span class="pl-c1">diff --git a/script/deliver-message b/script/deliver-message</span>
index a382bffa1..496773597 100755
<span class="pl-md">--- a/script/deliver-message</span>
<span class="pl-mi1">+++ b/script/deliver-message</span>
<span class="pl-mdr">@@ -33,6 +33,6 @@</span> mail = Mail.new($stdin.read
message = Message.from_mail(mail, from, to)
message.save!
<span class="pl-md"><span class="pl-md">-</span>message.notify_recipient_via_mail</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>UserMailer.message_notification(message).deliver_later if message.notify_recipient?</span>
exit 0</pre></div>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4284#discussion_r1373619275">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLMVXU5D5HAMB63GNGDYBKUQ7AVCNFSM6AAAAAA53SDOR2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTOMBQGMZTSNZVGA">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLIBMU5QEMRW4VAZUDLYBKUQ7A5CNFSM6AAAAAA53SDOR2WGG33NNVSW45C7OR4XAZNRKB2WY3CSMVYXKZLTORJGK5TJMV32UY3PNVWWK3TUL5UWJTTFLEQCM.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/4284/review/1700339750</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/4284#discussion_r1373619275",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/4284#discussion_r1373619275",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>