-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send notification mail for circle invitation #1349
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,93 @@ public function __construct( | |
} | ||
|
||
|
||
/** | ||
* @param string $author | ||
* @param Circle $circle | ||
* @param Member $member | ||
* @param array $mails | ||
*/ | ||
public function generateInvitationMail( | ||
string $author, | ||
Circle $circle, | ||
Member $member, | ||
array $mails, | ||
): void { | ||
|
||
|
||
if ($member->getUserType() === Member::TYPE_MAIL) { | ||
$mails = [$member->getUserId()]; | ||
} | ||
|
||
if (empty($mails)) { | ||
return; | ||
} | ||
|
||
$circleName = $circle->getDisplayName(); | ||
|
||
$template = $this->generateMailInvitation( | ||
$author, | ||
$circleName | ||
); | ||
|
||
foreach ($mails as $mail) { | ||
try { | ||
$this->sendMailInvitation($template, $author, $mail, $circleName); | ||
} catch (Exception $e) { | ||
} | ||
} | ||
Comment on lines
+123
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens during this exception? You probably want to write this on the logs? |
||
} | ||
|
||
/** | ||
* @param string $author | ||
* @param string $circleName | ||
* | ||
* @return IEMailTemplate | ||
*/ | ||
private function generateMailInvitation( | ||
string $author, | ||
string $circleName | ||
): IEMailTemplate { | ||
$emailTemplate = $this->mailer->createEMailTemplate('circles.ExistingShareNotification', []); | ||
$emailTemplate->addHeader(); | ||
|
||
$text = $this->l10n->t('%s invited you to the circle %s.', [$author, $circleName]); | ||
$emailTemplate->addBodyText(htmlspecialchars($text), $text); | ||
|
||
return $emailTemplate; | ||
} | ||
|
||
|
||
/** | ||
* @param IEMailTemplate $emailTemplate | ||
* @param string $author | ||
* @param string $recipient | ||
* @param string $circleName | ||
* | ||
* @throws Exception | ||
*/ | ||
private function sendMailInvitation( | ||
IEMailTemplate $emailTemplate, | ||
string $author, | ||
string $recipient, | ||
string $circleName | ||
) { | ||
$instanceName = $this->defaults->getName(); | ||
$senderName = $this->l10n->t('%s on %s', [$author, $instanceName]); | ||
$subject = $this->l10n->t('%s invited you to the circle %s.', [$author, $circleName]); | ||
|
||
$message = $this->mailer->createMessage(); | ||
|
||
$message->setFrom([Util::getDefaultEmailAddress($instanceName) => $senderName]); | ||
$message->setSubject($subject); | ||
$message->setPlainBody($emailTemplate->renderText()); | ||
$message->setHtmlBody($emailTemplate->renderHtml()); | ||
$message->setTo([$recipient]); | ||
|
||
$this->mailer->send($message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know but it could be possible to build all the mail templates and call the send function with an array of messages? (Related to the loop that calls |
||
} | ||
|
||
|
||
/** | ||
* @param string $author | ||
* @param Circle $circle | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see in the screen shot that
test
started with lower-case so, we want to start the statement and name in this case with caps.