From 7b64395747c838d50356c2e03662443bd3266495 Mon Sep 17 00:00:00 2001 From: ArchBlood <35392110+ArchBlood@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:27:30 -0500 Subject: [PATCH 01/10] Update ConversationStateBadge.php --- widgets/ConversationStateBadge.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/widgets/ConversationStateBadge.php b/widgets/ConversationStateBadge.php index 802995ee..db51ab8d 100644 --- a/widgets/ConversationStateBadge.php +++ b/widgets/ConversationStateBadge.php @@ -44,16 +44,23 @@ protected function getOptions(): array protected function renderInfoText(): ?string { + $config = new \humhub\modules\mail\models\Config(); + switch ($this->entry->type) { case AbstractMessageEntry::TYPE_USER_JOINED: - return $this->isOwn() - ? Yii::t('MailModule.base', 'You joined the conversation.') - : Yii::t('MailModule.base', '{username} joined the conversation.', ['username' => $this->username]); - + if ($config->enableMessageUserJoined) { + return $this->isOwn() + ? Yii::t('MailModule.base', 'You joined the conversation.') + : Yii::t('MailModule.base', '{username} joined the conversation.', ['username' => $this->username]); + } + break; case AbstractMessageEntry::TYPE_USER_LEFT: - return $this->isOwn() - ? Yii::t('MailModule.base', 'You left the conversation.') - : Yii::t('MailModule.base', '{username} left the conversation.', ['username' => $this->username]); + if ($config->enableMessageUserLeft) { + return $this->isOwn() + ? Yii::t('MailModule.base', 'You left the conversation.') + : Yii::t('MailModule.base', '{username} left the conversation.', ['username' => $this->username]); + } + break; } return null; From 0e2312790583095bab9fca17d537a34c695b2d07 Mon Sep 17 00:00:00 2001 From: ArchBlood <35392110+ArchBlood@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:28:57 -0500 Subject: [PATCH 02/10] Update InboxMessagePreview.php --- widgets/InboxMessagePreview.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/widgets/InboxMessagePreview.php b/widgets/InboxMessagePreview.php index c0cd6ff2..c85ec1d2 100644 --- a/widgets/InboxMessagePreview.php +++ b/widgets/InboxMessagePreview.php @@ -97,16 +97,27 @@ private function getMessageTitle(): string public function getMessagePreview(): string { + // Retrieve the configuration module + $config = new \humhub\modules\mail\models\Config(); + switch ($this->getLastEntry()->type) { case AbstractMessageEntry::TYPE_USER_JOINED: - return $this->isOwnLastEntry() - ? Yii::t('MailModule.base', 'You joined the conversation.') - : Yii::t('MailModule.base', '{username} joined the conversation.', ['username' => $this->getUsername()]); + // Check if showing user joined message is enabled + if ($config->enableMessageUserJoined) { + return $this->isOwnLastEntry() + ? Yii::t('MailModule.base', 'You joined the conversation.') + : Yii::t('MailModule.base', '{username} joined the conversation.', ['username' => $this->getUsername()]); + } + break; case AbstractMessageEntry::TYPE_USER_LEFT: - return $this->isOwnLastEntry() - ? Yii::t('MailModule.base', 'You left the conversation.') - : Yii::t('MailModule.base', '{username} left the conversation.', ['username' => $this->getUsername()]); + // Check if showing user left message is enabled + if ($config->enableMessageUserLeft) { + return $this->isOwnLastEntry() + ? Yii::t('MailModule.base', 'You left the conversation.') + : Yii::t('MailModule.base', '{username} left the conversation.', ['username' => $this->getUsername()]); + } + break; } if ($this->isGroupChat()) { From b9a91722198e47584ba66d107cb5cd460b4de0e6 Mon Sep 17 00:00:00 2001 From: ArchBlood <35392110+ArchBlood@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:30:45 -0500 Subject: [PATCH 03/10] Update UserMessage.php --- models/UserMessage.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/models/UserMessage.php b/models/UserMessage.php index 002e80a9..533da247 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); + } } } From 132eaadd2d0f49701d5f4a9c04b076e2d5eb97b2 Mon Sep 17 00:00:00 2001 From: ArchBlood <35392110+ArchBlood@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:32:36 -0500 Subject: [PATCH 04/10] Update Config.php --- models/Config.php | 59 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/models/Config.php b/models/Config.php index e3009f15..7fc9385b 100644 --- a/models/Config.php +++ b/models/Config.php @@ -2,11 +2,13 @@ namespace humhub\modules\mail\models; -use DateInterval; -use DateTime; -use humhub\modules\user\models\User; use Yii; +use DateTime; +use DateInterval; use humhub\modules\mail\Module; +use humhub\modules\user\models\User; +use humhub\modules\mail\models\states\MessageUserLeft; +use humhub\modules\mail\models\states\MessageUserJoined; /** * ConfigureForm defines the configurable fields. @@ -30,6 +32,20 @@ class Config extends \yii\base\Model public $userMessageRestriction = null; + public $enableMessageUserJoined = true; + + public $enableMessageUserLeft = true; + + /** + * 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 function init() { parent::init(); @@ -41,6 +57,8 @@ public function init() $this->newUserMessageRestriction = (int) $module->settings->get('newUserMessageRestriction', $this->newUserMessageRestriction); $this->userConversationRestriction = (int) $module->settings->get('userConversationRestriction', $this->userConversationRestriction); $this->userMessageRestriction = (int) $module->settings->get('userMessageRestriction', $this->userMessageRestriction); + $this->enableMessageUserJoined = (bool) $module->settings->get('enableMessageUserJoined', $this->enableMessageUserJoined); + $this->enableMessageUserLeft = (bool) $module->settings->get('enableMessageUserLeft', $this->enableMessageUserLeft); } /** @@ -57,7 +75,7 @@ public static function getModule() public function rules() { return [ - [['showInTopNav', 'newUserRestrictionEnabled'], 'boolean'], + [['showInTopNav', 'newUserRestrictionEnabled', 'enableMessageUserJoined', 'enableMessageUserLeft'], 'boolean'], [['newUserConversationRestriction', 'newUserMessageRestriction', 'userConversationRestriction', @@ -81,12 +99,14 @@ public function attributeLabels() 'newUserMessageRestriction' => Yii::t('MailModule.base', 'Max number of messages allowed for a new user per day'), 'userConversationRestriction' => Yii::t('MailModule.base', 'Max number of new conversations allowed for a user per day'), 'userMessageRestriction' => Yii::t('MailModule.base', 'Max messages allowed per day'), + 'enableMessageUserJoined' => Yii::t('MailModule.base', 'Enable "User Joined" message'), + 'enableMessageUserLeft' => Yii::t('MailModule.base', 'Enable "User Left" message'), ]; } public function save() { - if (!$this->validate()) { + if(!$this->validate()) { return false; } @@ -98,12 +118,37 @@ public function save() $module->settings->set('newUserMessageRestriction', $this->newUserMessageRestriction); $module->settings->set('userConversationRestriction', $this->userConversationRestriction); $module->settings->set('userMessageRestriction', $this->userMessageRestriction); + $module->settings->set('enableMessageUserJoined', $this->enableMessageUserJoined); + $module->settings->set('enableMessageUserLeft', $this->enableMessageUserLeft); return true; } + public function afterSave($insert, $changedAttributes) + { + parent::afterSave($insert, $changedAttributes); + + // Update the settings for MessageUserJoined and MessageUserLeft states + $module = $this->getModule(); + $module->settings->set(MessageUserJoined::SETTING_ENABLE_MESSAGE_USER_JOINED, $this->enableMessageUserJoined); + $module->settings->set(MessageUserLeft::SETTING_ENABLE_MESSAGE_USER_LEFT, $this->enableMessageUserLeft); + } + + /** + * @inheritdoc + */ + public function afterDelete() + { + parent::afterDelete(); + + // Inform about user left if the corresponding setting is enabled + if ($this->settings[MessageUserLeft::SETTING_ENABLE_MESSAGE_USER_LEFT]) { + MessageUserLeft::inform($this->message, $this->user); + } + } + public function canCreateConversation(User $originator) { - if ($originator->isSystemAdmin()) { + if($originator->isSystemAdmin()) { return true; } @@ -116,7 +161,7 @@ public function canCreateConversation(User $originator) public function isNewUser(User $originator) { - if (empty($this->newUserRestrictionEnabled)) { + if(empty($this->newUserRestrictionEnabled)) { return false; } From 1612308226e5c246c50a673cb67f33c9369980c6 Mon Sep 17 00:00:00 2001 From: ArchBlood Date: Tue, 5 Nov 2024 19:32:56 +0000 Subject: [PATCH 05/10] Autocommit PHP CS Fixer --- models/Config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/Config.php b/models/Config.php index 7fc9385b..7ef02295 100644 --- a/models/Config.php +++ b/models/Config.php @@ -106,7 +106,7 @@ public function attributeLabels() public function save() { - if(!$this->validate()) { + if (!$this->validate()) { return false; } @@ -148,7 +148,7 @@ public function afterDelete() public function canCreateConversation(User $originator) { - if($originator->isSystemAdmin()) { + if ($originator->isSystemAdmin()) { return true; } @@ -161,7 +161,7 @@ public function canCreateConversation(User $originator) public function isNewUser(User $originator) { - if(empty($this->newUserRestrictionEnabled)) { + if (empty($this->newUserRestrictionEnabled)) { return false; } From 599fd9859cf92f3fef56343d43df72dabb543511 Mon Sep 17 00:00:00 2001 From: ArchBlood <35392110+ArchBlood@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:33:07 -0500 Subject: [PATCH 06/10] Update MessageUserJoined.php --- models/states/MessageUserJoined.php | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/models/states/MessageUserJoined.php b/models/states/MessageUserJoined.php index 3b5df22d..c76aceef 100644 --- a/models/states/MessageUserJoined.php +++ b/models/states/MessageUserJoined.php @@ -1,4 +1,5 @@ Date: Tue, 5 Nov 2024 14:33:41 -0500 Subject: [PATCH 07/10] Update MessageUserLeft.php --- models/states/MessageUserLeft.php | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/models/states/MessageUserLeft.php b/models/states/MessageUserLeft.php index b7710ea0..f58cfedf 100644 --- a/models/states/MessageUserLeft.php +++ b/models/states/MessageUserLeft.php @@ -1,4 +1,5 @@ Date: Tue, 5 Nov 2024 14:34:41 -0500 Subject: [PATCH 08/10] Update index.php --- views/config/index.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/views/config/index.php b/views/config/index.php index 378e99c6..034b22ff 100644 --- a/views/config/index.php +++ b/views/config/index.php @@ -1,25 +1,20 @@ +?>
-
Messenger module configuration'); ?>
-
'configure-form']); ?> - field($model, 'showInTopNav')->checkbox(); ?> -
field($model, 'userConversationRestriction')->textInput(['type' => 'number']); ?> field($model, 'userMessageRestriction')->textInput(['type' => 'number']); ?> -
field($model, 'newUserRestrictionEnabled')->checkbox(['id' => 'newUserCheckbox']); ?>
@@ -27,16 +22,16 @@ field($model, 'newUserConversationRestriction')->textInput(['type' => 'number']); ?> field($model, 'newUserMessageRestriction')->textInput(['type' => 'number']); ?>
- +
+ field($model, 'enableMessageUserJoined')->checkbox(); ?> + field($model, 'enableMessageUserLeft')->checkbox(); ?>
- submit() ?>
- Date: Tue, 5 Nov 2024 19:36:41 +0000 Subject: [PATCH 09/10] Autocommit PHP CS Fixer --- models/states/MessageUserJoined.php | 4 ++-- models/states/MessageUserLeft.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/states/MessageUserJoined.php b/models/states/MessageUserJoined.php index c76aceef..66adfee6 100644 --- a/models/states/MessageUserJoined.php +++ b/models/states/MessageUserJoined.php @@ -19,12 +19,12 @@ class MessageUserJoined extends AbstractMessageState /** * The default value for the 'enableMessageUserJoined' setting. */ - const DEFAULT_ENABLE_MESSAGE_USER_JOINED = true; + public const DEFAULT_ENABLE_MESSAGE_USER_JOINED = true; /** * The key for the 'enableMessageUserJoined' setting. */ - const SETTING_ENABLE_MESSAGE_USER_JOINED = 'enableMessageUserJoined'; + public const SETTING_ENABLE_MESSAGE_USER_JOINED = 'enableMessageUserJoined'; /** * @inheritdoc diff --git a/models/states/MessageUserLeft.php b/models/states/MessageUserLeft.php index f58cfedf..f4318138 100644 --- a/models/states/MessageUserLeft.php +++ b/models/states/MessageUserLeft.php @@ -19,12 +19,12 @@ class MessageUserLeft extends AbstractMessageState /** * The default value for the 'enableMessageUserLeft' setting. */ - const DEFAULT_ENABLE_MESSAGE_USER_LEFT = true; + public const DEFAULT_ENABLE_MESSAGE_USER_LEFT = true; /** * The key for the 'enableMessageUserLeft' setting. */ - const SETTING_ENABLE_MESSAGE_USER_LEFT = 'enableMessageUserLeft'; + public const SETTING_ENABLE_MESSAGE_USER_LEFT = 'enableMessageUserLeft'; /** * @inheritdoc From 285574a916b7020f1cffef133addd4db0a9cc071 Mon Sep 17 00:00:00 2001 From: ArchBlood Date: Sun, 1 Dec 2024 00:28:40 +0000 Subject: [PATCH 10/10] Autocommit PHP CS Fixer --- controllers/rest/EntryController.php | 1 + controllers/rest/MessageController.php | 1 + controllers/rest/TagController.php | 1 + controllers/rest/UserController.php | 1 + helpers/RestDefinitions.php | 1 + models/AbstractMessageEntry.php | 1 + models/states/AbstractMessageState.php | 1 + notifications/ConversationNotification.php | 1 + notifications/ConversationNotificationCategory.php | 1 + notifications/MailNotification.php | 1 + search/SearchProvider.php | 1 + search/SearchRecord.php | 1 + tests/codeception/_bootstrap.php | 1 + tests/codeception/acceptance/_bootstrap.php | 1 + tests/codeception/api/_bootstrap.php | 1 + tests/codeception/functional/_bootstrap.php | 1 + tests/codeception/unit/_bootstrap.php | 1 + tests/config/api.php | 1 + tests/config/common.php | 1 + tests/config/functional.php | 1 + tests/config/unit.php | 1 + widgets/ConversationDateBadge.php | 1 + widgets/ConversationEntry.php | 1 + widgets/ConversationEntryMenu.php | 1 + widgets/ConversationStateBadge.php | 1 + widgets/ConversationView.php | 1 + widgets/MailRichtextEditor.php | 1 + widgets/MessageEntryTime.php | 1 + widgets/PinLink.php | 1 + 29 files changed, 29 insertions(+) diff --git a/controllers/rest/EntryController.php b/controllers/rest/EntryController.php index fac9a3a8..2c59440f 100644 --- a/controllers/rest/EntryController.php +++ b/controllers/rest/EntryController.php @@ -1,4 +1,5 @@