Skip to content

Commit 93eeba0

Browse files
committed
Some gentle touches regarding solution comments email helper
1 parent 2f38750 commit 93eeba0

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

app/V1Module/presenters/CommentsPresenter.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ public function actionAddComment(string $id) {
123123
$this->comments->flush();
124124

125125
// send email to all participants in comment thread
126-
if ($solution = $this->assignmentSolutions->get($id)) {
127-
$this->solutionCommentsEmailsSender->assignmentSolutionComment($solution, $comment);
128-
} else if ($solution = $this->referenceExerciseSolutions->get($id)) {
129-
$this->solutionCommentsEmailsSender->referenceSolutionComment($solution, $comment);
126+
$assignmentSolution = $this->assignmentSolutions->get($id);
127+
$referenceSolution = $this->referenceExerciseSolutions->get($id);
128+
if ($assignmentSolution) {
129+
$this->solutionCommentsEmailsSender->assignmentSolutionComment($assignmentSolution, $comment);
130+
} else if ($referenceSolution) {
131+
$this->solutionCommentsEmailsSender->referenceSolutionComment($referenceSolution, $comment);
130132
} else {
131133
// Nothing to do here...
132134
}

app/helpers/Emails/NotificationsHelper/Comments/SolutionCommentsEmailsSender.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,19 @@ private function sendSolutionComment($solution, Comment $comment): bool {
4949

5050
$baseSolution = $solution->getSolution();
5151
$subject = $this->assignmentSolutionCommentPrefix . $baseSolution->getAuthor()->getName();
52-
$recipients = [$baseSolution->getAuthor()->getEmail()];
52+
53+
$recipients = [];
54+
$recipients[$baseSolution->getAuthor()->getEmail()] = $baseSolution->getAuthor();
5355
foreach ($comment->getThread()->findAllPublic() as $pComment) {
5456
$user = $pComment->getUser();
5557
if (!$user->getSettings()->getSolutionCommentsEmails()) {
5658
continue;
5759
}
58-
$recipients[] = $user->getEmail();
60+
$recipients[$user->getEmail()] = $user;
5961
}
6062

61-
// make user emails unique, so the emails won't be multiplied
62-
$recipients = array_unique($recipients);
63-
6463
// filter out the author of the comment, it is pointless to send email to that user
65-
$recipients = array_filter($recipients, function (string $email) use ($comment) {
66-
return $email !== $comment->getUser()->getEmail();
67-
});
64+
unset($recipients[$comment->getUser()->getEmail()]);
6865

6966
if (count($recipients) === 0) {
7067
return true;
@@ -82,7 +79,7 @@ private function sendSolutionComment($solution, Comment $comment): bool {
8279
[],
8380
$subject,
8481
$body,
85-
$recipients
82+
array_keys($recipients)
8683
);
8784
}
8885

0 commit comments

Comments
 (0)