Skip to content

Commit

Permalink
MBS-13719: Implement review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
JadedBlueEyes committed Oct 25, 2024
1 parent 4fde2a8 commit 39d62c6
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions lib/MusicBrainz/Server/Email.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use DBDefs;
use Try::Tiny;
use List::AllUtils qw( any sort_by );
use JSON::XS qw( encode_json );
use Data::Dumper;
use HTTP::Request::Common qw(DELETE POST GET HEAD PUT);

use MusicBrainz::Server::Constants qw(
Expand Down Expand Up @@ -388,7 +389,7 @@ sub send_message_to_editor
{
my ($self, %opts) = @_;

my $_url = $mail_service_base_url . "/send_single";
my $_url = "$mail_service_base_url/send_single";

my $from = $opts{from} or die q(Missing 'from' argument);
my $to = $opts{to} or die q(Missing 'to' argument);
Expand All @@ -402,13 +403,15 @@ sub send_message_to_editor
'template_id' => 'editor-message',
'to' => _user_address($to),
'from' => $EMAIL_NOREPLY_ADDRESS,
# TODO: send the user's language preference here. (This preference is not yet stored on the server)
# Which language should we use, as this email is not going to the user?
# 'lang'
'message_id' => _message_id('correspondence-%s-%s-%d', $correspondents[0]->id, $correspondents[1]->id, time()),
'references' => [_message_id('correspondence-%s-%s', $correspondents[0]->id, $correspondents[1]->id)],
'in_reply_to' => [_message_id('correspondence-%s-%s', $correspondents[0]->id, $correspondents[1]->id)],
'params' => {
'to_name' => $to -> name,
'from_name' => $from -> name,
'to_name' => $to->name,
'from_name' => $from->name,
'subject' => $subject,
'message' => $message,
'contact_url' => $contact_url,
Expand All @@ -428,39 +431,26 @@ sub send_message_to_editor
};

my $res = $self->c->lwp->request(POST $_url, %$header_params, Content => encode_json($body));
if (! $res->is_success) {
print "Failed to send!"
unless ($res->is_success) {
my $status = $res->status;
die "Failed to send mail ($status):\n" . Dumper($res->content);
}

if ($opts{send_to_self}) {
my $self_body = {
'template_id' => 'editor-message',
'to' => _user_address($from),
'from' => $EMAIL_NOREPLY_ADDRESS,
# 'lang'
'message_id' => _message_id('correspondence-%s-%s-%d', $correspondents[0]->id, $correspondents[1]->id, time()),
'references' => [_message_id('correspondence-%s-%s', $correspondents[0]->id, $correspondents[1]->id)],
'in_reply_to' => [_message_id('correspondence-%s-%s', $correspondents[0]->id, $correspondents[1]->id)],
'params' => {
'to_name' => $to -> name,
'from_name' => $from -> name,
'subject' => $subject,
'message' => $message,
'contact_url' => $contact_url,
'revealed_address' => \$opts{reveal_address},
'is_self_copy' => \1
}
};
$body->{to} = _user_address($from);
$body->{params}{is_self_copy} = \1;
# TODO: Should we set language here to the reporter's language?

if ($opts{reveal_address}) {
$self_body->{reply_to} = _user_address($from);
$body->{reply_to} = _user_address($from);
} else {
$self_body->{reply_to} = $EMAIL_NOREPLY_ADDRESS;
$body->{reply_to} = $EMAIL_NOREPLY_ADDRESS;
}

my $res = $self->c->lwp->request(POST $_url, %$header_params, Content => encode_json($self_body));
if (! $res->is_success) {
print "Failed to send!"
unless ($res->is_success) {
my $status = $res->status;
die "Failed to send mail ($status):\n" . Dumper($res->content);
}
}
}
Expand Down

0 comments on commit 39d62c6

Please sign in to comment.