Skip to content

Commit

Permalink
Update UserMessage.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchBlood authored Nov 5, 2024
1 parent 0e23127 commit b9a9172
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions models/UserMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
}

0 comments on commit b9a9172

Please sign in to comment.