Browse Source

Update Models\PM\PTopic for block

Visman 3 năm trước cách đây
mục cha
commit
7d5d30e86e
1 tập tin đã thay đổi với 23 bổ sung4 xóa
  1. 23 4
      app/Models/PM/PTopic.php

+ 23 - 4
app/Models/PM/PTopic.php

@@ -30,13 +30,13 @@ class PTopic extends DataModel
             'last_post'     => ['firstNew'],
             'last_post_id'  => ['linkLast', 'firstNew'],
             'num_replies'   => ['numPages', 'pagination'],
-            'poster'        => ['last_poster', 'byOrFor', 'zpUser', 'ztUser'],
-            'poster_id'     => ['closed', 'firstNew', 'zp', 'zt', 'zpUser', 'ztUser', 'actionsAllowed', 'canReply', 'canSend'],
+            'poster'        => ['last_poster', 'byOrFor', 'zpUser', 'ztUser', 'canBlock'],
+            'poster_id'     => ['closed', 'firstNew', 'zp', 'zt', 'zpUser', 'ztUser', 'actionsAllowed', 'canReply', 'canSend', 'canBlock'],
             'poster_status' => ['closed', 'actionsAllowed', 'canReply', 'isFullDeleted', 'canSend'],
             'poster_visit'  => ['firstNew'],
             'subject'       => ['name'],
-            'target'        => ['last_poster', 'byOrFor', 'zpUser', 'ztUser'],
-            'target_id'     => ['closed', 'firstNew', 'zp', 'zt', 'zpUser', 'ztUser', 'actionsAllowed', 'canReply', 'canSend'],
+            'target'        => ['last_poster', 'byOrFor', 'zpUser', 'ztUser', 'canBlock'],
+            'target_id'     => ['closed', 'firstNew', 'zp', 'zt', 'zpUser', 'ztUser', 'actionsAllowed', 'canReply', 'canSend', 'canBlock'],
             'target_status' => ['closed', 'actionsAllowed', 'canReply', 'isFullDeleted', 'canSend'],
             'target_visit'  => ['firstNew'],
         ];
@@ -480,12 +480,30 @@ class PTopic extends DataModel
             && $this->ztUser->usePM;
     }
 
+    /**
+     * Статус блокировки между пользователями
+     * 2 - вы заблокирвоали собеседника
+     * 1 - собеседник заблокировал вас
+     * 0 - блокировки нет
+     */
+    protected function getcanBlock(): int
+    {
+        if ($this->c->pms->block->isBlock($this->ztUser) && ! $this->ztUser->isAdmin) {
+            return 2;
+        } elseif ($this->c->pms->block->inBlock($this->ztUser) && ! $this->zpUser->isAdmin) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
     /**
      * Статус возможности ответа в теме
      */
     protected function getcanReply(): bool
     {
         return $this->actionsAllowed
+            && 0 === $this->canBlock
             && (
                 (
                     1 === $this->zpUser->u_pm
@@ -507,6 +525,7 @@ class PTopic extends DataModel
     {
         return Cnst::PT_ARCHIVE === $this->poster_status
             && $this->actionsAllowed
+            && 0 === $this->canBlock
             && (
                 (
                     1 === $this->zpUser->u_pm