diff --git a/custom/templates/DefaultRevamp/email/notification.html b/custom/templates/DefaultRevamp/email/notification.html
new file mode 100644
index 0000000000..d79dcbc02e
--- /dev/null
+++ b/custom/templates/DefaultRevamp/email/notification.html
@@ -0,0 +1,17 @@
+
+
+
+
+ [Sitename] • [Title]
+
+
+
+
+
[Greeting]
+
[Content]
+
[Link]
+
+ [Thanks]
[Sitename]
+
+
+
\ No newline at end of file
diff --git a/modules/Core/classes/Core/Notification.php b/modules/Core/classes/Core/Notification.php
index 293f706bbe..6e31fdb5eb 100644
--- a/modules/Core/classes/Core/Notification.php
+++ b/modules/Core/classes/Core/Notification.php
@@ -23,30 +23,32 @@ class Notification {
/**
* Instantiate a new notification
*
- * @param string $type Type of notification
- * @param AlertTemplate $alertTemplate Alert template
- * @param EmailTemplate $emailTemplate Email template
- * @param int|int[] $recipients Notification recipient or recipients - array of user IDs
- * @param int $authorId User ID that sent the notification
- * @param bool $bypassNotificationSettings Whether to bypass the user's notification settings
+ * @param string $type Type of notification
+ * @param string|LanguageKey $title Title of notification
+ * @param string|LanguageKey $content Notification content. For alerts, if $alertUrl is set, this will ignored. If $alertUrl is not set, this will be the content of the alert. This will always be the content of the email.
+ * @param int|int[] $recipients Notification recipient or recipients - array of user IDs
+ * @param int $authorId User ID that sent the notification
+ * @param bool $bypassNotificationSettings Whether to bypass the user's notification settings
+ * @param ?string $link Optional URL to link to when clicking the alert
*
* @throws NotificationTypeNotFoundException
*/
public function __construct(
string $type,
- AlertTemplate $alertTemplate,
- EmailTemplate $emailTemplate,
+ string|LanguageKey $title,
+ string|LanguageKey $content,
int|array $recipients,
int $authorId,
bool $bypassNotificationSettings = false,
+ ?string $link = null,
) {
if (!in_array($type, array_column(self::getTypes(), 'key'))) {
throw new NotificationTypeNotFoundException("Type $type not registered");
}
$this->_type = $type;
- $this->_alertTemplate = $alertTemplate;
- $this->_emailTemplate = $emailTemplate;
+ $this->_alertTemplate = new AlertTemplate($title, $link ? null : $content, $link);
+ $this->_emailTemplate = new NotificationEmailTemplate($title, $content, $link);
$this->_authorId = $authorId;
$this->_bypassNotificationSettings = $bypassNotificationSettings;
@@ -72,6 +74,14 @@ public function __construct(
}, $recipients);
}
+ public function setAlertTemplate(AlertTemplate $template): void {
+ $this->_alertTemplate = $template;
+ }
+
+ public function setEmailTemplate(EmailTemplate $template): void {
+ $this->_emailTemplate = $template;
+ }
+
public function send(): void {
/** @var array $recipient */
foreach ($this->_recipients as $recipient) {
diff --git a/modules/Core/classes/Email_Templates/NotificationEmailTemplate.php b/modules/Core/classes/Email_Templates/NotificationEmailTemplate.php
new file mode 100644
index 0000000000..828b82e719
--- /dev/null
+++ b/modules/Core/classes/Email_Templates/NotificationEmailTemplate.php
@@ -0,0 +1,24 @@
+subject = $subject;
+
+ $this->addPlaceholder('[Title]', $subject);
+ $this->addPlaceholder('[Content]', $content);
+
+ // Register all notifications to nl2_alerts even if alert preference is off? Then all links can be sent to /user/alerts/?id={ID} then it will direct user + mark as read
+ $this->addPlaceholder('[Link]', $link ?? URL::getSelfURL());
+
+ parent::__construct();
+ }
+
+ public function subject(): string
+ {
+ return $this->subject;
+ }
+}
\ No newline at end of file
diff --git a/modules/Core/classes/Tasks/MassMessage.php b/modules/Core/classes/Tasks/MassMessage.php
index 94b54d00fb..22c9fb4230 100644
--- a/modules/Core/classes/Tasks/MassMessage.php
+++ b/modules/Core/classes/Tasks/MassMessage.php
@@ -42,18 +42,16 @@ public function run(): string {
$notification = new Notification(
'mass_message',
- new AlertTemplate(
- $title,
- $content,
- ),
- new MassMessageEmailTemplate(
- $title,
- $content,
- ),
+ $title,
+ $content,
array_map(static fn ($r) => $r->id, $recipients->results()),
$this->getUserId(),
(bool) $this->getData()['bypass_notification_settings'],
);
+ $notification->setEmailTemplate(new MassMessageEmailTemplate(
+ $title,
+ $content,
+ ));
$notification->send();
$this->setOutput(['userIds' => $whereVars, 'start' => $start, 'end' => $end, 'next_status' => $nextStatus]);
diff --git a/modules/Forum/pages/forum/view_topic.php b/modules/Forum/pages/forum/view_topic.php
index 0bfe740fcd..7f6d5a80cb 100644
--- a/modules/Forum/pages/forum/view_topic.php
+++ b/modules/Forum/pages/forum/view_topic.php
@@ -358,23 +358,25 @@
$notification = new Notification(
'forum_topic_reply',
- new AlertTemplate(
- new LanguageKey('forum', 'new_reply_in_topic', [
- 'author' => $user->data()->username, 'topic' => $topic->topic_title
- ], ROOT_PATH . '/modules/Forum/language'),
- null,
- $post_link,
- ),
- new ForumTopicReplyEmailTemplate(
- $user,
- $topic->topic_title,
- $original_content,
- $post_link,
- ),
+ $topic->topic_title,
+ $original_content,
$users_following,
$user->data()->id,
);
+ $notification->setAlertTemplate(new AlertTemplate(
+ new LanguageKey('forum', 'new_reply_in_topic', [
+ 'author' => $user->data()->username, 'topic' => $topic->topic_title
+ ], ROOT_PATH . '/modules/Forum/language'),
+ null,
+ $post_link,
+ ));
+ $notification->setEmailTemplate(new ForumTopicReplyEmailTemplate(
+ $user,
+ $topic->topic_title,
+ $original_content,
+ $post_link,
+ ));
$notification->send();
if (count($users_following)) {