Browse Source

Fix automatic subscription

Made through the form of sending a message
Visman 4 years ago
parent
commit
38be73b0a7

+ 8 - 9
app/Models/Pages/Post.php

@@ -278,6 +278,14 @@ class Post extends Page
         $this->user->last_post = $now;
         $this->c->users->update($this->user);
 
+        if ('1' == $this->c->config->o_topic_subscriptions) { // ????
+            if ($v->subscribe && ! $topic->is_subscribed) {
+                $this->c->subscriptions->subscribe($this->user, $topic);
+            } elseif (! $v->subscribe && $topic->is_subscribed) {
+                $this->c->subscriptions->unsubscribe($this->user, $topic);
+            }
+        }
+
         if ($merge) {
             $this->c->search->index($lastPost, 'merge');
         } else {
@@ -285,15 +293,6 @@ class Post extends Page
 
             if ($createTopic) {
                 if ('1' == $this->c->config->o_forum_subscriptions) { // ????
-                    // автоподписка на свою тему
-                    if (
-                        '1' == $this->c->config->o_topic_subscriptions
-                        && $this->user->auto_notify
-                        && $this->user->email_confirmed
-                    ) {
-                        $this->c->subscriptions->subscribe($this->user, $topic);
-                    }
-
                     $this->c->subscriptions->send($post, $topic);
                 }
             } else {

+ 29 - 0
app/Models/Pages/PostFormTrait.php

@@ -134,6 +134,7 @@ trait PostFormTrait
                     'checked' => isset($vars['merge_post']) ? (bool) $vars['merge_post'] : true,
                 ];
             }
+
             if (
                 $editPost
                 && ! $model->user->isGuest
@@ -147,6 +148,33 @@ trait PostFormTrait
                 ];
             }
         }
+
+        if (
+            ! $editPost
+            && '1' == $this->c->config->o_topic_subscriptions
+            && $this->user->email_confirmed
+        ) {
+            $subscribed = ! $editSubject && $model->is_subscribed;
+
+            if ($quickReply) {
+                if (
+                    $subscribed
+                    || $this->user->auto_notify
+                ) {
+                    $form['hidden']['subscribe'] = '1';
+                }
+            } else {
+                $fieldset['subscribe'] = [
+                    'type'    => 'checkbox',
+                    'label'   => $subscribed ? __('Stay subscribed') : __('New subscribe'),
+                    'value'   => '1',
+                    'checked' => isset($vars['subscribe'])
+                        ? (bool) $vars['subscribe']
+                        : ($subscribed || $this->user->auto_notify),
+                ];
+            }
+        }
+
         if (
             ! $quickReply
             && '1' == $this->c->config->o_smilies
@@ -158,6 +186,7 @@ trait PostFormTrait
                 'checked' => isset($vars['hide_smilies']) ? (bool) $vars['hide_smilies'] : false,
             ];
         }
+
         if ($fieldset) {
             $form['sets']['sett'] = [
                 'legend' => __('Options'),

+ 11 - 0
app/Models/Pages/PostValidatorTrait.php

@@ -156,6 +156,16 @@ trait PostValidatorTrait
             $ruleSubject = 'absent';
         }
 
+        if (
+            ! $editPost
+            && '1' == $this->c->config->o_topic_subscriptions
+            && $this->user->email_confirmed
+        ) {
+            $ruleSubscribe = 'checkbox';
+        } else {
+            $ruleSubscribe = 'absent';
+        }
+
         if ('1' == $this->c->config->o_smilies) {
             $ruleHideSmilies = 'checkbox';
         } else {
@@ -177,6 +187,7 @@ trait PostValidatorTrait
                 'merge_post'   => $ruleMergePost,
                 'hide_smilies' => $ruleHideSmilies,
                 'edit_post'    => $ruleEditPost,
+                'subscribe'    => $ruleSubscribe,
                 'preview'      => 'string',
                 'submit'       => 'string|check_timeout',
                 'message'      => 'required|string:trim|max:' . $this->c->MAX_POST_SIZE . '|check_message',

+ 1 - 1
app/lang/en/post.po

@@ -66,7 +66,7 @@ msgstr "Post new topic"
 msgid "Hide smilies"
 msgstr "Never show smilies as icons for this post"
 
-msgid "Subscribe"
+msgid "New subscribe"
 msgstr "Subscribe to this topic"
 
 msgid "Stay subscribed"

+ 1 - 1
app/lang/ru/post.po

@@ -66,7 +66,7 @@ msgstr "Публикация новой темы"
 msgid "Hide smilies"
 msgstr "Никогда не показывать смайлы в виде картинок в этом сообщении"
 
-msgid "Subscribe"
+msgid "New subscribe"
 msgstr "Подписаться на эту тему"
 
 msgid "Stay subscribed"