diff --git a/models/UserMessage.php b/models/UserMessage.php index 002e80a..533da24 100644 --- a/models/UserMessage.php +++ b/models/UserMessage.php @@ -2,11 +2,11 @@ namespace humhub\modules\mail\models; +use Yii; use humhub\components\ActiveRecord; -use humhub\modules\mail\models\states\MessageUserJoined; -use humhub\modules\mail\models\states\MessageUserLeft; use humhub\modules\user\models\User; -use Yii; +use humhub\modules\mail\models\states\MessageUserLeft; +use humhub\modules\mail\models\states\MessageUserJoined; /** * This class represents the relation between users and conversations. @@ -32,6 +32,16 @@ */ class UserMessage extends ActiveRecord { + /** + * The settings array, containing the necessary settings for the MessageUserJoined and MessageUserLeft states. + * + * @var array + */ + private $settings = [ + MessageUserJoined::SETTING_ENABLE_MESSAGE_USER_JOINED => true, + MessageUserLeft::SETTING_ENABLE_MESSAGE_USER_LEFT => true, + ]; + public bool $informAfterAdd = true; /** @@ -129,7 +139,7 @@ public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); - if ($insert && $this->informAfterAdd) { + if ($insert && $this->informAfterAdd && MessageUserJoined::isEnabled($this->settings)) { MessageUserJoined::inform($this->message, $this->user); } } @@ -140,6 +150,9 @@ public function afterSave($insert, $changedAttributes) public function afterDelete() { parent::afterDelete(); - MessageUserLeft::inform($this->message, $this->user); + + if (MessageUserLeft::isEnabled($this->settings)) { + MessageUserLeft::inform($this->message, $this->user); + } } }