diff --git a/Events.php b/Events.php index b1b4eb68..d65190d4 100644 --- a/Events.php +++ b/Events.php @@ -8,18 +8,21 @@ namespace humhub\modules\mail; -use humhub\modules\mail\models\Message; -use humhub\modules\mail\models\UserMessageTag; -use humhub\modules\mail\permissions\StartConversation; -use humhub\modules\user\models\User; -use Yii; use humhub\modules\mail\helpers\Url; +use humhub\modules\mail\models\Config; +use humhub\modules\mail\models\Message; use humhub\modules\mail\models\MessageEntry; use humhub\modules\mail\models\UserMessage; +use humhub\modules\mail\models\UserMessageTag; +use humhub\modules\mail\permissions\SendMail; +use humhub\modules\mail\permissions\StartConversation; use humhub\modules\mail\widgets\NewMessageButton; use humhub\modules\mail\widgets\NotificationInbox; -use humhub\modules\mail\permissions\SendMail; -use humhub\modules\mail\models\Config; +use humhub\modules\mail\widgets\PeopleActionButtonsMail; +use humhub\modules\user\models\User; +use humhub\modules\user\widgets\PeopleActionButtons; +use Throwable; +use Yii; /** * Description of Events @@ -41,7 +44,7 @@ public static function onIntegrityCheck($event) try { foreach (Message::find()->each() as $message) { /* @var $message Message */ - if(!$message->getAuthor()->count()) { + if (!$message->getAuthor()->count()) { if ($integrityController->showFix("Deleting conversation id " . $message->id . " without existing author!")) { $message->delete(); } @@ -52,7 +55,7 @@ public static function onIntegrityCheck($event) foreach (MessageEntry::find()->each() as $messageEntry) { /* @var $messageEntry MessageEntry */ - if(!$messageEntry->getUser()->count()) { + if (!$messageEntry->getUser()->count()) { if ($integrityController->showFix("Deleting message entry id " . $messageEntry->id . " without existing user!")) { $messageEntry->delete(); } @@ -63,7 +66,7 @@ public static function onIntegrityCheck($event) foreach (UserMessage::find()->each() as $userMessage) { /* @var $userMessage UserMessage */ - if(!$userMessage->getUser()->count()) { + if (!$userMessage->getUser()->count()) { if ($integrityController->showFix("Deleting user message id " . $userMessage->message_id . " without existing user!")) { $userMessage->delete(); } @@ -74,13 +77,13 @@ public static function onIntegrityCheck($event) foreach (UserMessageTag::find()->each() as $messageTag) { /* @var $messageTag UserMessageTag */ - if(!$messageTag->getUser()->count()) { + if (!$messageTag->getUser()->count()) { if ($integrityController->showFix("Deleting user tag id " . $messageTag->id . " without existing user!")) { $messageTag->delete(); } } } - } catch(\Throwable $e) { + } catch (Throwable $e) { Yii::error($e); } } @@ -103,7 +106,7 @@ public static function onUserDelete($event) } foreach (UserMessage::findAll(['user_id' => $event->sender->id]) as $userMessage) { - if($userMessage->message) { + if ($userMessage->message) { $userMessage->message->leave($event->sender->id); } @@ -113,7 +116,7 @@ public static function onUserDelete($event) foreach (UserMessageTag::findAll(['user_id' => $event->sender->id]) as $userMessageTag) { $userMessageTag->delete(); } - } catch(\Throwable $e) { + } catch (Throwable $e) { Yii::error($e); } @@ -144,7 +147,7 @@ public static function onTopMenuInit($event) 'sortOrder' => 300, ]); } - } catch(\Throwable $e) { + } catch (Throwable $e) { Yii::error($e); } } @@ -157,7 +160,7 @@ public static function onNotificationAddonInit($event) } $event->sender->addWidget(NotificationInbox::className(), [], ['sortOrder' => 90]); - } catch (\Throwable $e) { + } catch (Throwable $e) { Yii::error($e); } } @@ -178,11 +181,19 @@ public static function onProfileHeaderControlsInit($event) } $event->sender->addWidget(NewMessageButton::class, ['guid' => $event->sender->user->guid, 'size' => null, 'icon' => null], ['sortOrder' => 90]); - } catch (\Throwable $e) { + } catch (Throwable $e) { Yii::error($e); } } + public static function onPeopleActionButtonsCreate($event) + { + /** @var PeopleActionButtons $buttons */ + $buttons = $event->sender; + + $event->config['class'] = PeopleActionButtonsMail::class; + } + public static function onRestApiAddRules() { /* @var \humhub\modules\rest\Module $restModule */ diff --git a/Module.php b/Module.php index 203cf006..8dfae131 100644 --- a/Module.php +++ b/Module.php @@ -3,12 +3,12 @@ namespace humhub\modules\mail; use humhub\components\console\Application as ConsoleApplication; -use humhub\modules\mail\notifications\MailNotification; +use humhub\modules\mail\helpers\Url; use humhub\modules\mail\notifications\ConversationNotification; -use humhub\modules\mail\permissions\StartConversation; +use humhub\modules\mail\notifications\MailNotification; use humhub\modules\mail\permissions\SendMail; +use humhub\modules\mail\permissions\StartConversation; use humhub\modules\user\models\User; -use humhub\modules\mail\helpers\Url; use Yii; /** @@ -45,6 +45,19 @@ class Module extends \humhub\components\Module */ public $conversationUpdatePageSize = 50; + /** + * @var bool Show the "Send message" button in the users' cards of the people directory + */ + public $showSendMessageButtonInPeopleCards = true; + + /** + * @return static + */ + public static function getModuleInstance() + { + return Yii::$app->getModule('mail'); + } + /** * @inheritdoc */ @@ -58,14 +71,6 @@ public function init() } } - /** - * @return static - */ - public static function getModuleInstance() - { - return Yii::$app->getModule('mail'); - } - /** * @inheritdoc */ diff --git a/config.php b/config.php index fd6798f8..2f9df7c4 100644 --- a/config.php +++ b/config.php @@ -2,9 +2,10 @@ use humhub\commands\IntegrityController; use humhub\modules\user\models\User; -use humhub\widgets\TopMenu; -use humhub\widgets\NotificationArea; +use humhub\modules\user\widgets\PeopleActionButtons; use humhub\modules\user\widgets\ProfileHeaderControls; +use humhub\widgets\NotificationArea; +use humhub\widgets\TopMenu; return [ 'id' => 'mail', @@ -15,6 +16,7 @@ ['class' => TopMenu::class, 'event' => TopMenu::EVENT_INIT, 'callback' => ['humhub\modules\mail\Events', 'onTopMenuInit']], ['class' => NotificationArea::class, 'event' => NotificationArea::EVENT_INIT, 'callback' => ['humhub\modules\mail\Events', 'onNotificationAddonInit']], ['class' => ProfileHeaderControls::class, 'event' => ProfileHeaderControls::EVENT_INIT, 'callback' => ['humhub\modules\mail\Events', 'onProfileHeaderControlsInit']], + ['class' => PeopleActionButtons::class, 'event' => PeopleActionButtons::EVENT_CREATE, 'callback' => ['humhub\modules\mail\Events', 'onPeopleActionButtonsCreate']], ['class' => IntegrityController::class, 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => ['humhub\modules\mail\Events', 'onIntegrityCheck']], ['class' => 'humhub\modules\rest\Module', 'event' => 'restApiAddRules', 'callback' => ['humhub\modules\mail\Events', 'onRestApiAddRules']], ], diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index cf070b64..3da8d9ed 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,8 @@ Changelog ------------------------- - Fix #252: Fix wrong user guid in Live Notification - Fix #251: Fix edit message +- Enh #257: Add "Send message" to People cards +- Chg: Update min HumHub version to v1.11 2.1.0 (December 7, 2021) ------------------------- diff --git a/module.json b/module.json index 155e26ab..e34ad142 100644 --- a/module.json +++ b/module.json @@ -5,7 +5,7 @@ "keywords": ["mail", "messaging", "communication"], "version": "2.1.1", "humhub": { - "minVersion": "1.10" + "minVersion": "1.11" }, "homepage": "https://github.com/humhub/humhub-modules-mail", "authors": [ diff --git a/widgets/NewMessageButton.php b/widgets/NewMessageButton.php index 8fa3b337..2bb8418e 100644 --- a/widgets/NewMessageButton.php +++ b/widgets/NewMessageButton.php @@ -2,10 +2,11 @@ namespace humhub\modules\mail\widgets; +use humhub\components\Widget; use humhub\modules\mail\helpers\Url; +use humhub\widgets\BootstrapComponent; use humhub\widgets\ModalButton; use Yii; -use humhub\components\Widget; class NewMessageButton extends Widget { @@ -45,22 +46,29 @@ class NewMessageButton extends Widget */ public $cssClass; + /** + * @var string button type for the color + */ + public $type = BootstrapComponent::TYPE_INFO; + + /** * Creates the Wall Widget */ public function run() { - $button = ModalButton::info($this->getLabel())->load(Url::toCreateConversation($this->guid))->id($this->id); + $button = new ModalButton(['type' => $this->type, 'text' => $this->getLabel()]); + $button->load(Url::toCreateConversation($this->guid))->id($this->id); - if($this->icon) { + if ($this->icon) { $button->icon($this->icon); } - if($this->right) { + if ($this->right) { $button->right(); } - if($this->cssClass) { + if ($this->cssClass) { $button->cssClass($this->cssClass); } @@ -84,7 +92,7 @@ public function run() public function getLabel() { - if($this->label !== null) { + if ($this->label !== null) { return $this->label; } diff --git a/widgets/PeopleActionButtonsMail.php b/widgets/PeopleActionButtonsMail.php new file mode 100644 index 00000000..a328e5a5 --- /dev/null +++ b/widgets/PeopleActionButtonsMail.php @@ -0,0 +1,36 @@ +addFollowButton(); + $html .= $this->addFriendshipButton(); + + /** @var Module $module */ + $module = Yii::$app->getModule('mail'); + + if ($module->showSendMessageButtonInPeopleCards) { + $html .= NewMessageButton::widget([ + 'label' => Icon::get('send') . ' ' . Yii::t('MailModule.base', 'Message'), + 'guid' => $this->user->guid, + 'type' => BootstrapComponent::TYPE_DEFAULT, + ]); + } + + if (trim($html) === '') { + return ''; + } + + return str_replace('{buttons}', $html, $this->template); + } + +}