Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh #257: Add "Send message" to People cards #258

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -144,7 +147,7 @@ public static function onTopMenuInit($event)
'sortOrder' => 300,
]);
}
} catch(\Throwable $e) {
} catch (Throwable $e) {
Yii::error($e);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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 */
Expand Down
27 changes: 16 additions & 11 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
*/
Expand All @@ -58,14 +71,6 @@ public function init()
}
}

/**
* @return static
*/
public static function getModuleInstance()
{
return Yii::$app->getModule('mail');
}

/**
* @inheritdoc
*/
Expand Down
6 changes: 4 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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']],
],
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
-------------------------
- Fix #252: Fix wrong user guid in Live Notification
- Fix #251: Fix edit message
- Enh #257: Add "Send message" to People cards

2.1.0 (December 7, 2021)
-------------------------
Expand Down
20 changes: 14 additions & 6 deletions widgets/NewMessageButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -84,7 +92,7 @@ public function run()

public function getLabel()
{
if($this->label !== null) {
if ($this->label !== null) {
return $this->label;
}

Expand Down
49 changes: 49 additions & 0 deletions widgets/PeopleActionButtonsMail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace humhub\modules\mail\widgets;

use humhub\modules\friendship\widgets\FriendshipButton;
use humhub\modules\mail\Module;
use humhub\modules\user\widgets\PeopleActionButtons;
use humhub\modules\user\widgets\UserFollowButton;
use humhub\widgets\BootstrapComponent;
use Yii;

class PeopleActionButtonsMail extends PeopleActionButtons
{
public function run()
{
$html = UserFollowButton::widget([
'user' => $this->user,
'followOptions' => ['class' => 'btn btn-primary btn-sm'],
'unfollowOptions' => ['class' => 'btn btn-primary btn-sm active'],
]);

$html .= FriendshipButton::widget([

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have an if tag in cases where friendship is disabled.

'user' => $this->user,
'options' => [
'friends' => ['attrs' => ['class' => 'btn btn-info btn-sm active']],
'addFriend' => ['attrs' => ['class' => 'btn btn-info btn-sm']],
'acceptFriendRequest' => ['attrs' => ['class' => 'btn btn-info btn-sm active'], 'togglerClass' => 'btn btn-info btn-sm active'],
'cancelFriendRequest' => ['attrs' => ['class' => 'btn btn-info btn-sm active']],
],
]);

/** @var Module $module */
$module = Yii::$app->getModule('mail');

if ($module->showSendMessageButtonInPeopleCards) {
$html .= NewMessageButton::widget([
'guid' => $this->user->guid,
'type' => BootstrapComponent::TYPE_DEFAULT,
]);
}

if (trim($html) === '') {
return '';
}

return str_replace('{buttons}', $html, $this->template);
}

}