Browse Source

Add sending notifications for PM

Visman 3 years ago
parent
commit
b254c54694

+ 43 - 0
app/Models/Pages/PM/PMPost.php

@@ -18,6 +18,7 @@ use ForkBB\Models\Pages\PostValidatorTrait;
 use ForkBB\Models\PM\Cnst;
 use ForkBB\Models\PM\PPost;
 use ForkBB\Models\PM\PTopic;
+use ForkBB\Core\Exceptions\MailException;
 use InvalidArgumentException;
 use function \ForkBB\__;
 
@@ -259,6 +260,48 @@ class PMPost extends AbstractPM
 
         $this->c->users->update($this->user);
 
+        // отправка уведомления
+        $this->c->Online->calc($this);
+
+        if ( // ????
+            Cnst::PT_NORMAL === $topic->poster_status
+            && 1 === $this->targetUser->u_pm_notify
+            && 1 === $this->targetUser->email_confirmed
+            && 0 === $this->c->bans->banFromName($this->targetUser->username)
+            && ! $this->c->Online->isOnline($this->targetUser)
+        ) {
+            try {
+                $this->c->Lang->load('common', $this->targetUser->language);
+
+                $tplData = [
+                    'fTitle'     => $this->c->config->o_board_title,
+                    'fMailer'    => __(['Mailer', $this->c->config->o_board_title]),
+                    'pmSubject'  => $topic->subject,
+                    'username'   => $this->targetUser->username,
+                    'sender'     => $this->user->username,
+                    'messageUrl' => $this->newTopic ? $topic->link : $post->link,
+                ];
+
+                $this->c->Mail
+                    ->reset()
+                    ->setMaxRecipients(1)
+                    ->setFolder($this->c->DIR_LANG)
+                    ->setLanguage($this->targetUser->language)
+                    ->setTo($this->targetUser->email, $this->targetUser->username)
+                    ->setFrom($this->c->config->o_webmaster_email, $tplData['fMailer'])
+                    ->setTpl('new_pm.tpl', $tplData)
+                    ->send();
+
+                $this->c->Lang->load('common', $this->user->language); // ???? вынести?
+            } catch (MailException $e) {
+                $this->c->Log->error('PM: MailException', [
+                    'exception' => $e,
+                    'headers'   => false,
+                ]);
+            }
+        }
+        // отправка уведомления
+
         return $this->c->Redirect->url($post->link)->message($message);
     }
 }

+ 0 - 10
app/lang/en/mail/form_pmsn.tpl

@@ -1,10 +0,0 @@
-Subject: New personal message: {!mail_subject!}
-
-Hello, {!user!}!
-
-'{!sender!}' from '{!board_title!}' has sent you a personal message.
-The message is located at {!message_url!}
-
---
-{!board_mailer!} Mailer
-(Do not reply to this message)

+ 10 - 0
app/lang/en/mail/new_pm.tpl

@@ -0,0 +1,10 @@
+Subject: New personal message: {!pmSubject!}
+
+Hello, {!username!}!
+
+'{!sender!}' from '{!fTitle!}' has sent you a personal message.
+The message is located at {!messageUrl!}
+
+--
+{!fMailer!} Mailer
+(Do not reply to this message)

+ 0 - 10
app/lang/ru/mail/form_pmsn.tpl

@@ -1,10 +0,0 @@
-Subject: Новое личное сообщение: {!mail_subject!}
-
-Здравствуйте, {!user!}!
-
-Пользователь '{!sender!}' форума '{!board_title!}' отправил Вам личное сообщение.
-Сообщение можно прочитать по адресу: {!message_url!}
-
---
-Отправитель {!board_mailer!}
-(Не отвечайте на это сообщение)

+ 10 - 0
app/lang/ru/mail/new_pm.tpl

@@ -0,0 +1,10 @@
+Subject: Новое личное сообщение: {!pmSubject!}
+
+Здравствуйте, {!username!}!
+
+Пользователь '{!sender!}' форума '{!fTitle!}' отправил Вам личное сообщение.
+Сообщение можно прочитать по адресу: {!messageUrl!}
+
+--
+Отправитель {!fMailer!}
+(Не отвечайте на это сообщение)