From d39daa556b7d0fc7bdf62d4253c2906737a87e8c Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Mon, 29 Jan 2024 12:03:26 +0100 Subject: [PATCH] New features: Unread & Pinned (#377) * New features: Unread & Pinned * New feature: Pinned * Fix tests * Update pin icon * Fix select of next read message for redirect after mark as unread --- controllers/MailController.php | 81 ++++++++++++++++--- docs/CHANGELOG.md | 1 + helpers/Url.php | 19 ++++- migrations/m240125_080730_pinned.php | 26 ++++++ models/Message.php | 74 ++++++++++++++--- models/UserMessage.php | 16 ++-- resources/css/humhub.mail.css | 2 +- resources/css/humhub.mail.min.css | 2 +- resources/js/humhub.mail.conversation.js | 12 +-- resources/js/humhub.mail.messenger.bundle.js | 18 ++--- .../js/humhub.mail.messenger.bundle.min.js | 2 +- widgets/PinLink.php | 35 ++++++++ widgets/views/conversationHeader.php | 4 +- widgets/views/conversationSettingsMenu.php | 13 ++- widgets/views/inboxMessagePreview.php | 2 +- 15 files changed, 255 insertions(+), 52 deletions(-) create mode 100644 migrations/m240125_080730_pinned.php create mode 100644 widgets/PinLink.php diff --git a/controllers/MailController.php b/controllers/MailController.php index 2a94f404..9962b6ba 100644 --- a/controllers/MailController.php +++ b/controllers/MailController.php @@ -205,7 +205,7 @@ public function actionAddUser($id) */ public function actionNotificationList() { - $query = UserMessage::findByUser(null, 'message.updated_at DESC')->limit(5); + $query = UserMessage::findByUser()->limit(5); return $this->renderAjax('notificationList', ['userMessages' => $query->all()]); } @@ -341,6 +341,58 @@ public function actionCreate($userGuid = null, ?string $title = null, ?string $m ]); } + /** + * Mark a Conversation as unread + * + * @param int $id + */ + public function actionMarkUnread($id) + { + $this->forcePostRequest(); + $this->getMessage($id, true)->markUnread(); + + $nextReadMessage = $this->getNextReadMessage($id); + + return $this->asJson([ + 'success' => true, + 'redirect' => $nextReadMessage ? Url::toMessenger($nextReadMessage) : Url::to(['/dashboard']) + ]); + } + + /** + * Pin a Conversation + * + * @param int $id + */ + public function actionPin($id) + { + $this->forcePostRequest(); + $message = $this->getMessage($id, true); + $message->pin(); + + return $this->asJson([ + 'success' => true, + 'redirect' => Url::toMessenger($message) + ]); + } + + /** + * Unpin a Conversation + * + * @param int $id + */ + public function actionUnpin($id) + { + $this->forcePostRequest(); + $message = $this->getMessage($id, true); + $message->unpin(); + + return $this->asJson([ + 'success' => true, + 'redirect' => Url::toMessenger($message) + ]); + } + /** * Leave Message / Conversation * @@ -355,7 +407,7 @@ public function actionCreate($userGuid = null, ?string $title = null, ?string $m public function actionLeave($id) { $this->forcePostRequest(); - $this->getMessage($id, true)->leave(Yii::$app->user->id); + $this->getMessage($id, true)->leave(); return $this->asJson([ 'success' => true, @@ -441,18 +493,15 @@ public function actionGetNewMessageCountJson() * * @param int $id * @param bool $throw - * @return Message + * @return Message|null * @throws HttpException */ - private function getMessage($id, $throw = false) + private function getMessage($id, $throw = false): ?Message { $message = Message::findOne(['id' => $id]); - if ($message) { - $userMessage = $message->getUserMessage(); - if ($userMessage != null) { - return $message; - } + if ($message && $message->getUserMessage() !== null) { + return $message; } if ($throw) { @@ -461,4 +510,18 @@ private function getMessage($id, $throw = false) return null; } + + private function getNextReadMessage($id): ?Message + { + return Message::find() + ->leftJoin('user_message', 'user_message.message_id = message.id') + ->where(['user_id' => Yii::$app->user->id]) + ->andWhere(['!=', 'message_id', $id]) + ->andWhere('user_message.last_viewed >= message.updated_at') + ->orderBy([ + 'user_message.pinned' => SORT_DESC, + 'message.updated_at' => SORT_DESC + ]) + ->one(); + } } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 309b7624..2223731b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog Unreleased ------------------------ - Fix #369: Misplaced Online dot +- Enh #377: New features: Unread & Pinned 3.1.2 (January 22, 2024) ------------------------ diff --git a/helpers/Url.php b/helpers/Url.php index f5eac257..c7e2fdd9 100644 --- a/helpers/Url.php +++ b/helpers/Url.php @@ -70,9 +70,24 @@ public static function toConversationUserList(Message $message) return static::to(['/mail/mail/user-list', 'id' => $message->id]); } + public static function toMarkUnreadConversation(Message $message) + { + return static::to(['/mail/mail/mark-unread', 'id' => $message->id]); + } + + public static function toPinConversation(Message $message) + { + return static::to(['/mail/mail/pin', 'id' => $message->id]); + } + + public static function toUnpinConversation(Message $message) + { + return static::to(['/mail/mail/unpin', 'id' => $message->id]); + } + public static function toLeaveConversation(Message $message) { - return static::to(["/mail/mail/leave", 'id' => $message->id]); + return static::to(['/mail/mail/leave', 'id' => $message->id]); } public static function toMessenger(Message $message = null, $scheme = false) @@ -131,4 +146,4 @@ public static function toLoadMoreMessages() { return static::to(['/mail/mail/load-more']); } -} \ No newline at end of file +} diff --git a/migrations/m240125_080730_pinned.php b/migrations/m240125_080730_pinned.php new file mode 100644 index 00000000..f4c65cc4 --- /dev/null +++ b/migrations/m240125_080730_pinned.php @@ -0,0 +1,26 @@ +safeAddColumn(UserMessage::tableName(), 'pinned', $this->boolean()->defaultValue(false)->notNull()); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->safeDropColumn(UserMessage::tableName(), 'pinned'); + } +} diff --git a/models/Message.php b/models/Message.php index 317b69ef..b9664b51 100644 --- a/models/Message.php +++ b/models/Message.php @@ -5,6 +5,7 @@ use humhub\components\ActiveRecord; use humhub\modules\mail\Module; +use humhub\modules\ui\icon\widgets\Icon; use humhub\modules\user\models\User; use Yii; use yii\helpers\Html; @@ -105,12 +106,15 @@ public function getAuthor() } /** - * @param null $userId + * @param int|null $userId * @return UserMessage|null */ public function getUserMessage($userId = null) { if (!$userId) { + if (Yii::$app->user->isGuest) { + return null; + } $userId = Yii::$app->user->id; } @@ -233,23 +237,58 @@ public function deleteEntry($entry) } } + /** + * Mark this message as unread + * + * @param int|null $userId + */ + public function markUnread($userId = null) + { + $userMessage = $this->getUserMessage($userId); + if ($userMessage) { + $userMessage->last_viewed = null; + $userMessage->save(); + } + } + + /** + * Pin this message + * + * @param int|null $userId + * @param bool $pin + */ + public function pin($userId = null, bool $pin = true) + { + $userMessage = $this->getUserMessage($userId); + if ($userMessage) { + $userMessage->pinned = $pin; + $userMessage->save(); + } + } + + /** + * Unpin this message + * + * @param int|null $userId + */ + public function unpin($userId = null) + { + $this->pin($userId, false); + } + /** * User leaves a message * * If it's the last user, the whole message will be deleted. * - * @param int $userId + * @param int|null $userId * @throws \Throwable * @throws \yii\db\StaleObjectException */ - public function leave($userId) + public function leave($userId = null) { - $userMessage = UserMessage::findOne([ - 'message_id' => $this->id, - 'user_id' => $userId - ]); - - if(!$userMessage) { + $userMessage = $this->getUserMessage($userId); + if (!$userMessage) { return; } @@ -371,4 +410,21 @@ public function isBlocked(): bool return false; } + + public function isPinned($userId = null): bool + { + $userMessage = $this->getUserMessage($userId); + return $userMessage && $userMessage->pinned; + } + + public function getPinIcon($userId = null): ?Icon + { + if ($this->isPinned($userId)) { + return Icon::get('map-pin') + ->tooltip(Yii::t('MailModule.base', 'Pinned')) + ->color(Yii::$app->view->theme->variable('danger', 'red')); + } + + return null; + } } diff --git a/models/UserMessage.php b/models/UserMessage.php index 528617c3..9336f67c 100644 --- a/models/UserMessage.php +++ b/models/UserMessage.php @@ -22,6 +22,7 @@ * @property integer $created_by * @property string $updated_at * @property integer $updated_by + * @property integer $pinned * * @property-read Message $message * @property-read User $user @@ -113,19 +114,14 @@ public static function findByUser($userId = null) return static::find()->joinWith('message') ->where(['user_message.user_id' => $userId]) - ->orderBy('message.updated_at DESC'); + ->orderBy([ + 'user_message.pinned' => SORT_DESC, + 'message.updated_at' => SORT_DESC + ]); } - public function isUnread($userId = null) + public function isUnread(): bool { - if ($userId === null) { - $userId = Yii::$app->user->id; - } - - if($this->message->lastEntry && ($this->message->lastEntry->user_id === $userId)) { - return false; - } - return $this->message->updated_at > $this->last_viewed; } diff --git a/resources/css/humhub.mail.css b/resources/css/humhub.mail.css index 270bb8d0..e8168c02 100644 --- a/resources/css/humhub.mail.css +++ b/resources/css/humhub.mail.css @@ -228,7 +228,7 @@ .mail-conversation-entry.hideUserInfo .author-label { display: none; } -.mail-conversation-entry.hideUserInfo .author-image img { +.mail-conversation-entry.hideUserInfo .author-image a { visibility: hidden; margin-top: 0; } diff --git a/resources/css/humhub.mail.min.css b/resources/css/humhub.mail.min.css index 8b4c68d0..f250ce3c 100644 --- a/resources/css/humhub.mail.min.css +++ b/resources/css/humhub.mail.min.css @@ -1 +1 @@ -.placeholder{color:#77777a}#dropdown-messages .dropdown-header{color:#000;margin-bottom:12px;font-weight:600}#dropdown-messages .dropdown-footer .btn.btn-default{border:1px solid var(--default);box-shadow:none}#dropdown-messages .dropdown-footer .btn.btn-default:hover{border-color:var(--background3);background:var(--background3)}#dropdown-messages .dropdown-footer .btn.btn-default:active{border-color:var(--text-color-secondary);background:#fff}#dropdown-messages.dropdown-menu li a{font-size:inherit!important}#dropdown-messages .media-body{font-weight:200}.modal-body #createmessage-message .ProseMirror{min-height:100px!important}.media-list li.new{background-color:#e9f9ff}#create-message-button .fa,#mail-conversation-create-button .fa{margin:0}#conversation-filter-link{padding-left:0;display:block;padding-bottom:0}#conversation-tags-root{border-bottom:1px solid #eee}#conversation-tags-root .my-tags-label{padding-right:10px}.conversation-menu{display:none}.conversation-menu .time{color:inherit;text-transform:none}.conversation-menu .badge{background-color:var(--background-color-secondary);border-radius:10px;color:inherit}.conversation-menu .conversation-edit-button{background-color:var(--background-color-secondary);border-radius:50%;color:inherit}.conversation-menu .conversation-edit-button:hover{background-color:var(--background-color-secondary);color:inherit}.visible-xs .conversation-menu{padding-left:35px}.visible-xs .conversation-menu .conversation-menu-item{margin-bottom:10px}.conversation-menu-item{margin-left:5px}.conversation-menu-item a{cursor:pointer}.conversation-edit-button{border-bottom-right-radius:0;border-top-right-radius:0}.conversation-scroll-down-button{position:absolute;bottom:58px;right:25px;width:38px;height:38px;background:#fff;border-radius:50%;box-shadow:1px 1px 2px #999}.conversation-scroll-down-button .fa{font-size:26px;margin:7px 0 0 11px}.conversation-entry-list{max-height:600px;min-height:150px;overflow:auto}.conversation-entry-list .media{padding-right:5px}.conversation-entry-content{display:table;float:left;background-color:var(--background-color-secondary);border-radius:10px;padding:10px;max-width:70%}.conversation-entry-content pre{max-width:485px}.conversation-entry-content.own{float:right;background:var(--background-color-highlight)}.conversation-entry-content .markdown-render{float:left;width:100%;min-width:230px}.conversation-blocked-recipient{-webkit-filter:grayscale(100%);filter:grayscale(100%)}#mail-conversation-root hr{border-top:1px solid #eee}#mail-conversation-root .ProsemirrorEditor.focusMenu .ProseMirror-menubar{margin-top:0}#mail-conversation-root .panel-body{margin-bottom:0}#mail-conversation-header{padding:18px;border-bottom:1px solid var(--background3);border-bottom-left-radius:0;border-bottom-right-radius:0}#mail-conversation-header h1{font-weight:600;font-size:22px;display:inline-block}#mail-conversation-header small{display:block;font-size:11px;font-weight:400}#mail-conversation-header small a{color:var(--text-color-main)}#conversation-settings-button{padding:6px;font-size:12px}#mail-filter-root{margin-top:5px}.mail-inbox-messages .panel-heading>a{font-weight:600}.mail-inbox-messages .panel-heading #mail-filter-root>a{font-weight:400}.mail-inbox-messages .media{margin-top:0;display:flex}.mail-inbox-messages .media h4.media-heading{font-weight:600}.mail-inbox-messages .media h4.media-heading time{font-weight:400;float:right}.mail-inbox-messages .media h5{font-size:11px;font-weight:500;color:#000;display:flex;justify-content:space-between}.mail-inbox-messages .media h5 span:first-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mail-inbox-messages .media .mail-last-entry{font-size:11px;font-weight:400;color:var(--text-color-soft2)}.mail-inbox-messages .media-list>li:hover .mail-last-entry,.mail-inbox-messages .selected .mail-last-entry{color:var(--text-color-main)}.mail-message-form{position:absolute;bottom:0;width:100%;padding:10px}.mail-message-form .humhub-ui-richtext{padding-right:105px;border-radius:10px}.mail-message-form .upload-buttons{position:absolute;right:15px;bottom:15px;z-index:500}.mail-message-form .reply-button{margin-left:0!important}.mail-message-form .help-block{margin:0}.mail-message-form .alert{margin-bottom:0}.mail-conversation-entry{margin-top:3px;position:relative}.mail-conversation-entry .author-image .img-user{max-width:100%}.mail-conversation-entry .author-label{font-size:10px;font-weight:600}.mail-conversation-entry.hideUserInfo .author-label{display:none}.mail-conversation-entry.hideUserInfo .author-image img{visibility:hidden;margin-top:0}.mail-conversation-entry.own .conversation-menu-item{float:right;margin-left:0;margin-right:5px}.mail-conversation-entry .conversation-entry-time{float:right;font-size:10px;color:var(--text-color-main)}.mail-conversation-entry .conversation-entry-time>span{font-style:italic}.conversation-entry-badge{padding:10px 0 8px;text-align:center}.conversation-entry-badge span{display:inline-block;box-shadow:1px 1px 3px rgba(0,0,0,.3);border-radius:7px;padding:5px 20px}.conversation-entry-badge.conversation-date-badge span{text-transform:uppercase}#inbox{max-height:500px;overflow:auto;border-radius:4px}.messagePreviewEntry{cursor:pointer}.messagePreviewEntry time{font-size:10px;color:var(--text-color-secondary)}.messagePreviewEntry .new-message-badge{display:none}.messagePreviewEntry.unread .new-message-badge{display:block}.messagePreviewEntry.unread time{color:var(--info)}.messagePreviewEntry.unread .mail-last-entry{color:var(--text-color-main)}.message-tag-filter-group .select2-selection{border-bottom-right-radius:0}.message-tag-filter-group .manage-tags-link{font-weight:600;font-size:.8em;border:1px solid #ededed;border-top:0;border-bottom-left-radius:4px;border-bottom-right-radius:4px;padding:2px 5px}.new-message-badge{float:right;min-width:16px;height:16px;border-radius:50%;background:var(--info);margin-left:2px}.inbox-entry-title{font-weight:600}.field-replyform-message{margin:0}@media (max-width:991px){#inbox{max-height:500px!important}}@media (max-width:767px){#dropdown-messages{width:300px!important}.arrow{margin-left:-101px!important}#inbox{max-height:none!important}.mail-conversation-single-message #inbox{max-height:none!important}.mail-conversation-single-message .inbox-wrapper{display:none}.conversation-entry-content pre{max-width:245px;padding:0}} \ No newline at end of file +.placeholder{color:#77777a}#dropdown-messages .dropdown-header{color:#000;margin-bottom:12px;font-weight:600}#dropdown-messages.dropdown-menu li a{font-size:inherit!important}#dropdown-messages .media-body{font-weight:200}.modal-body #createmessage-message .ProseMirror{min-height:100px!important}.media-list li.new{background-color:#e9f9ff}#create-message-button .fa,#mail-conversation-create-button .fa{margin:0}#conversation-filter-link{padding-left:0;display:block;padding-bottom:0}#conversation-tags-root{border-bottom:1px solid #eee}#conversation-tags-root .my-tags-label{padding-right:10px}.conversation-menu{display:none}.conversation-menu .time{color:inherit;text-transform:none}.conversation-menu .badge{background-color:var(--background-color-secondary);border-radius:10px;color:inherit}.conversation-menu .conversation-edit-button{background-color:var(--background-color-secondary);border-radius:50%;color:inherit}.conversation-menu .conversation-edit-button:hover{background-color:var(--background-color-secondary);color:inherit}.visible-xs .conversation-menu{padding-left:35px}.visible-xs .conversation-menu .conversation-menu-item{margin-bottom:10px}.conversation-menu-item{margin-left:5px}.conversation-menu-item a{cursor:pointer}.conversation-edit-button{border-bottom-right-radius:0;border-top-right-radius:0}.conversation-scroll-down-button{position:absolute;bottom:58px;right:25px;width:38px;height:38px;background:#fff;border-radius:50%;box-shadow:1px 1px 2px #999}.conversation-scroll-down-button .fa{font-size:26px;margin:7px 0 0 11px}.conversation-entry-list{max-height:600px;min-height:150px;overflow:auto}.conversation-entry-list .media{padding-right:5px}.conversation-entry-content{display:table;float:left;background-color:var(--background-color-secondary);border-radius:10px;padding:10px;max-width:70%}.conversation-entry-content pre{max-width:485px}.conversation-entry-content.own{float:right;background:var(--background-color-highlight)}.conversation-entry-content .markdown-render{float:left;width:100%;min-width:230px}.conversation-blocked-recipient{-webkit-filter:grayscale(100%);filter:grayscale(100%)}#mail-conversation-root hr{border-top:1px solid #eee}#mail-conversation-root .ProsemirrorEditor.focusMenu .ProseMirror-menubar{margin-top:0}#mail-conversation-root .panel-body{margin-bottom:0}#mail-conversation-header{padding:18px;border-bottom:1px solid var(--background3);border-bottom-left-radius:0;border-bottom-right-radius:0}#mail-conversation-header h1{font-weight:600;font-size:22px;display:inline-block}#mail-conversation-header small{display:block;font-size:11px;font-weight:400}#mail-conversation-header small a{color:var(--text-color-main)}#conversation-settings-button{padding:6px;font-size:12px}#mail-filter-root{margin-top:5px}.mail-inbox-messages .panel-heading>a{font-weight:600}.mail-inbox-messages .panel-heading #mail-filter-root>a{font-weight:400}.mail-inbox-messages .media{margin-top:0;display:flex}.mail-inbox-messages .media h4.media-heading{font-weight:600}.mail-inbox-messages .media h4.media-heading time{font-weight:400;float:right}.mail-inbox-messages .media h5{font-size:11px;font-weight:500;color:#000;display:flex;justify-content:space-between}.mail-inbox-messages .media h5 span:first-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mail-inbox-messages .media .mail-last-entry{font-size:11px;font-weight:400;color:var(--text-color-soft2)}.mail-inbox-messages .media-list>li:hover .mail-last-entry,.mail-inbox-messages .selected .mail-last-entry{color:var(--text-color-main)}.mail-message-form{position:absolute;bottom:0;width:100%;padding:10px}.mail-message-form .humhub-ui-richtext{padding-right:105px;border-radius:10px}.mail-message-form .upload-buttons{position:absolute;right:15px;bottom:15px;z-index:500}.mail-message-form .reply-button{margin-left:0!important}.mail-message-form .help-block{margin:0}.mail-message-form .alert{margin-bottom:0}.mail-conversation-entry{margin-top:3px;position:relative}.mail-conversation-entry .author-image .img-user{max-width:100%}.mail-conversation-entry .author-label{font-size:10px;font-weight:600}.mail-conversation-entry.hideUserInfo .author-label{display:none}.mail-conversation-entry.hideUserInfo .author-image a{visibility:hidden;margin-top:0}.mail-conversation-entry.own .conversation-menu-item{float:right;margin-left:0;margin-right:5px}.mail-conversation-entry .conversation-entry-time{float:right;font-size:10px;color:var(--text-color-main)}.mail-conversation-entry .conversation-entry-time>span{font-style:italic}.conversation-entry-badge{padding:10px 0 8px;text-align:center}.conversation-entry-badge span{display:inline-block;box-shadow:1px 1px 3px rgba(0,0,0,.3);border-radius:7px;padding:5px 20px}.conversation-entry-badge.conversation-date-badge span{text-transform:uppercase}#inbox{max-height:500px;overflow:auto;border-radius:4px}.messagePreviewEntry{cursor:pointer}.messagePreviewEntry time{font-size:10px;color:var(--text-color-secondary)}.messagePreviewEntry .new-message-badge{display:none}.messagePreviewEntry.unread .new-message-badge{display:block}.messagePreviewEntry.unread time{color:var(--info)}.messagePreviewEntry.unread .mail-last-entry{color:var(--text-color-main)}.message-tag-filter-group .select2-selection{border-bottom-right-radius:0}.message-tag-filter-group .manage-tags-link{font-weight:600;font-size:.8em;border:1px solid #ededed;border-top:0;border-bottom-left-radius:4px;border-bottom-right-radius:4px;padding:2px 5px}.new-message-badge{float:right;min-width:16px;height:16px;border-radius:50%;background:var(--info);margin-left:2px}.inbox-entry-title{font-weight:600}.field-replyform-message{margin:0}@media (max-width:991px){#inbox{max-height:500px!important}}@media (max-width:767px){#dropdown-messages{width:300px!important}.arrow{margin-left:-101px!important}#inbox{max-height:none!important}.mail-conversation-single-message #inbox{max-height:none!important}.mail-conversation-single-message .inbox-wrapper{display:none}.conversation-entry-content pre{max-width:245px;padding:0}} \ No newline at end of file diff --git a/resources/js/humhub.mail.conversation.js b/resources/js/humhub.mail.conversation.js index cee1b703..f422dde4 100644 --- a/resources/js/humhub.mail.conversation.js +++ b/resources/js/humhub.mail.conversation.js @@ -87,7 +87,7 @@ humhub.module('mail.conversation', function (module, require, $) { }); }; - var leave = function (evt) { + var linkAction = function (evt) { client.post(evt).then(function (response) { if (response.redirect) { client.pjax.redirect(response.redirect); @@ -98,9 +98,9 @@ humhub.module('mail.conversation', function (module, require, $) { }; module.export({ - init: init, - leave: leave, - submitEditEntry: submitEditEntry, - deleteEntry: deleteEntry, + init, + linkAction, + submitEditEntry, + deleteEntry, }); -}); \ No newline at end of file +}); diff --git a/resources/js/humhub.mail.messenger.bundle.js b/resources/js/humhub.mail.messenger.bundle.js index e75dad18..7a50954e 100644 --- a/resources/js/humhub.mail.messenger.bundle.js +++ b/resources/js/humhub.mail.messenger.bundle.js @@ -415,7 +415,7 @@ humhub.module('mail.ConversationView', function (module, require, $) { module.export = ConversationView; }); - + humhub.module('mail.ConversationEntry', function (module, require, $) { var Widget = require('ui.widget').Widget; @@ -439,7 +439,7 @@ humhub.module('mail.ConversationEntry', function (module, require, $) { }; module.export = ConversationEntry; -}); +}); humhub.module('mail.inbox', function (module, require, $) { var Widget = require('ui.widget').Widget; @@ -696,7 +696,7 @@ humhub.module('mail.inbox', function (module, require, $) { setTagFilter: setTagFilter, toggleInbox: toggleInbox }); -}); +}); humhub.module('mail.conversation', function (module, require, $) { var Widget = require('ui.widget').Widget; var modal = require('ui.modal'); @@ -786,7 +786,7 @@ humhub.module('mail.conversation', function (module, require, $) { }); }; - var leave = function (evt) { + var linkAction = function (evt) { client.post(evt).then(function (response) { if (response.redirect) { client.pjax.redirect(response.redirect); @@ -797,9 +797,9 @@ humhub.module('mail.conversation', function (module, require, $) { }; module.export({ - init: init, - leave: leave, - submitEditEntry: submitEditEntry, - deleteEntry: deleteEntry, + init, + linkAction, + submitEditEntry, + deleteEntry, }); -}); \ No newline at end of file +}); diff --git a/resources/js/humhub.mail.messenger.bundle.min.js b/resources/js/humhub.mail.messenger.bundle.min.js index da384ca8..7c9b26ec 100644 --- a/resources/js/humhub.mail.messenger.bundle.min.js +++ b/resources/js/humhub.mail.messenger.bundle.min.js @@ -1 +1 @@ -humhub.module("mail.ConversationView",function(r,t,n){var s=t("ui.widget").Widget,a=t("ui.loader"),c=t("client"),o=t("ui.additions"),e=t("util.object"),i=t("mail.notification"),l=t("ui.view"),u=s.extend();u.prototype.init=function(){o.observe(this.$);var e=this;window.onresize=function(t){e.updateSize(!0)},this.getActiveMessageId()||this.setActiveMessageId(s.instance("#inbox").getFirstMessageId()),this.reload(),this.$.on("mouseenter",".mail-conversation-entry",function(){n(this).find(".conversation-menu").show()}).on("mouseleave",".mail-conversation-entry",function(){n(this).find(".conversation-menu").hide()})},u.prototype.loader=function(t){!1!==t?a.set(this.$):a.reset(this.$)},u.prototype.markSeen=function(t){c.post(this.options.markSeenUrl,{data:{id:t}}).then(function(t){e.isDefined(t.messageCount)&&i.setMailMessageCount(t.messageCount)}).catch(function(t){r.log.error(t)})},u.prototype.loadUpdate=function(){var t=this.$.find(".mail-conversation-entry:not(.own):last").data("entry-id"),t={id:this.getActiveMessageId(),from:t},e=this;c.get(this.options.loadUpdateUrl,{data:t}).then(function(t){t.html&&n(t.html).each(function(){e.appendEntry(n(this))})})},u.prototype.reply=function(e){var o=this;c.submit(e).then(function(t){t.success?o.appendEntry(t.content).then(function(){o.$.find(".time").timeago();var t=o.getReplyRichtext(),t=(t&&t.$.trigger("clear"),o.getReplyFilePreview());t.length&&(t.hide(),t.children("ul.files").html("")),o.scrollToBottom(),l.isSmall()||o.focus(),s.instance("#inbox").updateEntries([o.getActiveMessageId()]),o.setLivePollInterval()}):r.log.error(t,!0)}).catch(function(t){r.log.error(t,!0)}).finally(function(t){a.reset(n(".reply-button")),e.finish()})},u.prototype.setLivePollInterval=function(){t("live").setDelay(5)},u.prototype.getReplyRichtext=function(){return s.instance(this.$.find(".ProsemirrorEditor"))},u.prototype.getReplyFilePreview=function(){return this.$.find(".post-file-list")},u.prototype.focus=function(t){var e=this.getReplyRichtext();e&&e.focus()},u.prototype.canLoadMore=function(){return!this.options.isLast},u.prototype.reload=function(){this.getActiveMessageId()&&this.loadMessage(this.getActiveMessageId())},u.prototype.addUser=function(t){var e=this;c.submit(t).then(function(t){t.result?e.$.find("#mail-conversation-header").html(t.result):t.error&&r.log.error(t,!0)}).catch(function(t){r.log.error(t,!0)})},u.prototype.appendEntry=function(t){var o,i=this,t=n(t);return i.$.find('[data-entry-id="'+t.data("entryId")+'"]').length?Promise.resolve():((o=t.not("script, link").filter(function(){return 1===this.nodeType})).css("opacity",0),this.getListNode().append(t),new Promise(function(t,e){o.css("opacity",1).fadeIn("fast",function(){i.onUpdate(),setTimeout(function(){i.scrollToBottom()},100),t()})}))},u.prototype.loadMessage=function(o){var i=e.isNumber(o)?o:o.$trigger.data("message-id"),n=this;this.loader(),c.get(this.options.loadMessageUrl,{data:{id:i}}).then(function(t){n.setActiveMessageId(i),n.options.isLast=!1;var e=s.instance("#inbox");return e.updateActiveItem(),e.hide(),o.$trigger&&history&&history.replaceState&&(e=o.$trigger.data("action-url"))&&history.replaceState(null,null,e),n.$.css("visibility","hidden"),n.updateContent(t.html)}).then(function(){return n.initScroll()}).catch(function(t){r.log.error(t,!0)}).finally(function(){n.loader(!1),n.$.css("visibility","visible"),n.initReplyRichText()})},u.prototype.initReplyRichText=function(){var t,e,o=this;window.ResizeObserver&&(t=new ResizeObserver(function(t){o.updateSize(o.isScrolledToBottom(100))}),e=o.getReplyRichtext())&&t.observe(e.$[0]),o.getReplyFilePreview().on("DOMSubtreeModified",function(t){o.updateSize(!0)}),o.focus()},u.prototype.isScrolledToBottom=function(t){if(!this.getListNode().length)return!1;t=t||0;var e=this.getListNode()[0];return e.scrollHeight-e.offsetHeight-e.scrollTop<=t},u.prototype.initScroll=function(){var e,t,o,i;if(window.IntersectionObserver)return e=this.getListNode(),t=n('
'),e.prepend(t),o=this,i=new IntersectionObserver(function(t){o.preventScrollLoading()||t.length&&t[0].isIntersecting&&(a.prepend(e),o.loadMore().finally(function(){a.reset(e)}))},{root:e[0],rootMargin:"50px"}),this.assureScroll().then(function(){i.observe(t[0]),l.isLarge()&&(o.getListNode().niceScroll({cursorwidth:"7",cursorborder:"",cursorcolor:"#555",cursoropacitymax:"0.2",nativeparentscrolling:!1,railpadding:{top:0,right:0,left:0,bottom:0}}),o.scrollDownButton=void 0,o.getListNode().on("scroll",()=>o.getScrollDownButton().toggle(!o.isScrolledToBottom())))})},u.prototype.getScrollDownButton=function(){return"object"!=typeof this.scrollDownButton&&(this.scrollDownButton=n("
").addClass("conversation-scroll-down-button").html('').on("click",()=>this.scrollToBottom()),this.getListNode().append(this.scrollDownButton)),this.scrollDownButton},u.prototype.loadMore=function(){var o=this,t={id:this.getActiveMessageId(),from:this.$.find(".mail-conversation-entry:first").data("entryId")};return c.get(this.options.loadMoreUrl,{data:t}).then(function(t){var e;t.result&&(e=n(t.result).hide(),o.getListNode().find(".conversation-stream-end").after(e),e.fadeIn()),o.options.isLast=!t.result||t.isLast}).catch(function(t){r.log.error(t,!0)})},u.prototype.preventScrollLoading=function(){return this.scrollLock||!this.canLoadMore()},u.prototype.canLoadMore=function(){return!this.options.isLast},u.prototype.assureScroll=function(){var t=this,e=this.getListNode();return e[0].offsetHeight>=e[0].scrollHeight&&this.canLoadMore()?this.loadMore().then(function(){return t.assureScroll()}).catch(function(){return Promise.resolve()}):t.scrollToBottom()},u.prototype.updateContent=function(e){var o=this;return new Promise(function(t){o.$.html(e),t()})},u.prototype.getActiveMessageId=function(){return this.options.messageId},u.prototype.setActiveMessageId=function(t){this.options.messageId=t},u.prototype.scrollToBottom=function(){var o=this;return new Promise(function(e){setTimeout(function(){o.$.imagesLoaded(function(){var t=o.getListNode();t.length&&o.updateSize(!1).then(function(){t[0].scrollTop=t[0].scrollHeight,e()})})})})},u.prototype.updateSize=function(n){var r=this;return new Promise(function(i){setTimeout(function(){var t,e,o=r.getListNode();o.length&&(t=(t=r.getReplyRichtext())?t.$.closest(".mail-message-form").innerHeight():0,o.css("margin-bottom",t+5+"px"),e=r.getListNode().offset().top,e=window.innerHeight-e-t-(l.isSmall()?20:30)+"px",o.css("height",e),o.css("max-height",e),!1!==n&&r.scrollToBottom(),i())},100)})},u.prototype.getListNode=function(){return this.$.find(".conversation-entry-list")},u.prototype.onUpdate=function(){l.isLarge()&&this.getListNode().getNiceScroll().resize()},r.export=u}),humhub.module("mail.ConversationEntry",function(t,e,i){e=e("ui.widget").Widget.extend();e.prototype.replace=function(t){var e=this,o=i(t).hide();this.$.fadeOut(function(){i(this).replaceWith(o),e.$=o,e.$.fadeIn("slow")})},e.prototype.remove=function(){this.$.fadeToggle("slow",function(){i(this).remove()})},t.export=e}),humhub.module("mail.inbox",function(n,t,r){var e=t("ui.widget").Widget,o=t("ui.filter").Filter,i=t("ui.view"),s=t("ui.loader"),a=t("client"),t=o.extend(),o=(t.prototype.triggerChange=function(){this.super("triggerChange"),this.updateFilterCount()},t.prototype.updateFilterCount=function(){var t=this.getActiveFilterCount(),e=this.$.find("#conversation-filter-link"),o=e.find(".filterCount");t?(o=o.length?o:r('').insertBefore(e.find(".caret"))).html(" ("+t+") "):o.length&&o.remove()},e.extend());o.prototype.init=function(){this.filter=e.instance("#mail-filter-root"),this.initScroll(),this.initHeight();var t=this;this.filter.off("afterChange.inbox").on("afterChange.inbox",function(){t.reload().then(function(){t.updateActiveItem()})}),i.isLarge()&&this.$.niceScroll({cursorwidth:"7",cursorborder:"",cursorcolor:"#555",cursoropacitymax:"0.2",nativeparentscrolling:!1,railpadding:{top:0,right:3,left:0,bottom:0}}),this.$.on("click",".entry",function(){t.$.find(".entry").removeClass("selected"),r(this).addClass("selected")})},o.prototype.initHeight=function(){var t=this.$.offset().top;this.$.css("max-height",window.innerHeight-t-15+"px")},o.prototype.updateEntries=function(t){var o=this;t.length&&a.get(this.options.updateEntriesUrl,{data:{ids:t}}).then(function(t){t.result&&(r.each(t.result,function(t,e){t=o.getEntry(t);t.length?t.replaceWith(e):r(e).prependTo(o.$)}),o.updateActiveItem())}).catch(function(t){n.log.error(t)})},o.prototype.getEntry=function(t){return this.$.find('[data-message-id="'+t+'"]')},o.prototype.initScroll=function(){var t,e,o;window.IntersectionObserver&&(t=r('
'),this.$.append(t),e=this,o=new IntersectionObserver(function(t){e.preventScrollLoading()||t.length&&t[0].isIntersecting&&(s.append(e.$),e.loadMore().finally(function(){s.reset(e.$)}))},{root:this.$[0],rootMargin:"50px"}),this.assureScroll().then(function(){o.observe(t[0])}))},o.prototype.assureScroll=function(){var t=this;return this.$[0].offsetHeight>=this.$[0].scrollHeight&&this.canLoadMore()?this.loadMore().then(function(){return t.assureScroll()}).catch(function(){return Promise.resolve()}):Promise.resolve()},o.prototype.loadMore=function(){var i=this;return new Promise(function(e,o){var t=i.filter.getFilterMap();t.from=i.getLastMessageId(),a.get(i.options.loadMoreUrl,{data:t}).then(function(t){t.result&&(r(t.result).insertBefore(".inbox-stream-end"),i.$.find(".inbox-stream-end").append()),i.options.isLast=!t.result||t.isLast,i.updateActiveItem(),e()}).catch(function(t){n.log.error(t,!0),o()}).finally(function(){i.scrollLock=!1})})},o.prototype.preventScrollLoading=function(){return this.scrollLock||!this.canLoadMore()},o.prototype.canLoadMore=function(){return!this.options.isLast},o.prototype.getReloadOptions=function(){return{data:this.filter.getFilterMap()}},o.prototype.updateActiveItem=function(){var t=e.instance("#mail-conversation-root").getActiveMessageId(),t=(this.$.find(".entry").removeClass("selected"),this.$.find(".entry").removeClass("selected"),this.$.find('[data-message-id="'+t+'"]'));t.length&&t.removeClass("unread").addClass("selected")},o.prototype.getFirstMessageId=function(){return this.$.find(".entry:first").data("message-id")},o.prototype.getLastMessageId=function(){return this.$.find(".entry:last").data("message-id")},o.prototype.hide=function(){return new Promise(function(t){i.isSmall()&&r(".mail-conversation-single-message").length&&r(".inbox-wrapper").slideUp(function(){r("#mail-conversation-root").length&&e.instance("#mail-conversation-root").updateSize(),t()}),t()})},o.prototype.show=function(){return new Promise(function(t){i.isSmall()&&r(".inbox-wrapper").slideDown(function(){r("#mail-conversation-root").length&&e.instance("#mail-conversation-root").updateSize(),t()}),t()})};n.export({ConversationList:o,Filter:t,setTagFilter:function(t){e.instance("#inbox").show().then(function(){r("#mail-filter-menu").collapse("show"),e.instance("#inbox-tag-picker").setSelection([{id:t.$trigger.data("tagId"),text:t.$trigger.data("tagName"),image:t.$trigger.data("tagImage")}])})},toggleInbox:function(){i.isSmall()&&r(".inbox-wrapper").slideToggle(function(){e.instance("#mail-conversation-root").updateSize()})}})}),humhub.module("mail.conversation",function(i,t,r){function n(t){return s.instance('.mail-conversation-entry[data-entry-id="'+t+'"]')}var s=t("ui.widget").Widget,a=t("ui.modal"),o=t("client"),e=t("event"),c=t("mail.notification");i.export({init:function(){e.on("humhub:modules:mail:live:NewUserMessage",function(t,e){var o,i,n;r("#inbox").length&&(o=s.instance("#mail-conversation-root"),i=!1,n=[],e.forEach(function(t){n.push(t.data.message_id),!i&&o&&o.options.messageId==t.data.message_id&&(o.loadUpdate(),i=!0,o.markSeen(t.data.message_id))}),s.instance("#inbox").updateEntries(n))}).on("humhub:modules:mail:live:UserMessageDeleted",function(t,e,o){r("#inbox").length&&e.forEach(function(t){var e=n(t.data.entry_id);e&&e.remove(),c.setMailMessageCount(t.data.count)})})},leave:function(t){o.post(t).then(function(t){t.redirect&&o.pjax.redirect(t.redirect)}).catch(function(t){i.log.error(t,!0)})},submitEditEntry:function(o){a.submit(o).then(function(t){var e;t.success?(e=n(o.$trigger.data("entry-id")))&&setTimeout(function(){e.replace(t.content)},300):i.log.error(null,!0)}).catch(function(t){i.log.error(t,!0)})},deleteEntry:function(t){var e=n(t.$trigger.data("entry-id"));e?o.post(e.options.deleteUrl).then(function(t){a.global.close(),t.success&&setTimeout(function(){e.remove()},1e3)}).catch(function(t){i.log.error(t,!0)}):i.log.error(null,!0)}})}); \ No newline at end of file +humhub.module("mail.ConversationView",function(r,t,n){var s=t("ui.widget").Widget,a=t("ui.loader"),c=t("client"),o=t("ui.additions"),e=t("util.object"),i=t("mail.notification"),l=t("ui.view"),u=s.extend();u.prototype.init=function(){o.observe(this.$);var e=this;window.onresize=function(t){e.updateSize(!0)},this.getActiveMessageId()||this.setActiveMessageId(s.instance("#inbox").getFirstMessageId()),this.reload(),this.$.on("mouseenter",".mail-conversation-entry",function(){n(this).find(".conversation-menu").show()}).on("mouseleave",".mail-conversation-entry",function(){n(this).find(".conversation-menu").hide()})},u.prototype.loader=function(t){!1!==t?a.set(this.$):a.reset(this.$)},u.prototype.markSeen=function(t){c.post(this.options.markSeenUrl,{data:{id:t}}).then(function(t){e.isDefined(t.messageCount)&&i.setMailMessageCount(t.messageCount)}).catch(function(t){r.log.error(t)})},u.prototype.loadUpdate=function(){var t=this.$.find(".mail-conversation-entry:not(.own):last").data("entry-id"),t={id:this.getActiveMessageId(),from:t},e=this;c.get(this.options.loadUpdateUrl,{data:t}).then(function(t){t.html&&n(t.html).each(function(){e.appendEntry(n(this))})})},u.prototype.reply=function(e){var o=this;c.submit(e).then(function(t){t.success?o.appendEntry(t.content).then(function(){o.$.find(".time").timeago();var t=o.getReplyRichtext(),t=(t&&t.$.trigger("clear"),o.getReplyFilePreview());t.length&&(t.hide(),t.children("ul.files").html("")),o.scrollToBottom(),l.isSmall()||o.focus(),s.instance("#inbox").updateEntries([o.getActiveMessageId()]),o.setLivePollInterval()}):r.log.error(t,!0)}).catch(function(t){r.log.error(t,!0)}).finally(function(t){a.reset(n(".reply-button")),e.finish()})},u.prototype.setLivePollInterval=function(){t("live").setDelay(5)},u.prototype.getReplyRichtext=function(){return s.instance(this.$.find(".ProsemirrorEditor"))},u.prototype.getReplyFilePreview=function(){return this.$.find(".post-file-list")},u.prototype.focus=function(t){var e=this.getReplyRichtext();e&&e.focus()},u.prototype.canLoadMore=function(){return!this.options.isLast},u.prototype.reload=function(){this.getActiveMessageId()&&this.loadMessage(this.getActiveMessageId())},u.prototype.addUser=function(t){var e=this;c.submit(t).then(function(t){t.result?e.$.find("#mail-conversation-header").html(t.result):t.error&&r.log.error(t,!0)}).catch(function(t){r.log.error(t,!0)})},u.prototype.appendEntry=function(t){var o,i=this,t=n(t);return i.$.find('[data-entry-id="'+t.data("entryId")+'"]').length?Promise.resolve():((o=t.not("script, link").filter(function(){return 1===this.nodeType})).css("opacity",0),this.getListNode().append(t),new Promise(function(t,e){o.css("opacity",1).fadeIn("fast",function(){i.onUpdate(),setTimeout(function(){i.scrollToBottom()},100),t()})}))},u.prototype.loadMessage=function(o){var i=e.isNumber(o)?o:o.$trigger.data("message-id"),n=this;this.loader(),c.get(this.options.loadMessageUrl,{data:{id:i}}).then(function(t){n.setActiveMessageId(i),n.options.isLast=!1;var e=s.instance("#inbox");return e.updateActiveItem(),e.hide(),o.$trigger&&history&&history.replaceState&&(e=o.$trigger.data("action-url"))&&history.replaceState(null,null,e),n.$.css("visibility","hidden"),n.updateContent(t.html)}).then(function(){return n.initScroll()}).catch(function(t){r.log.error(t,!0)}).finally(function(){n.loader(!1),n.$.css("visibility","visible"),n.initReplyRichText()})},u.prototype.initReplyRichText=function(){var t,e,o=this;window.ResizeObserver&&(t=new ResizeObserver(function(t){o.updateSize(o.isScrolledToBottom(100))}),e=o.getReplyRichtext())&&t.observe(e.$[0]),o.getReplyFilePreview().on("DOMSubtreeModified",function(t){o.updateSize(!0)}),o.focus()},u.prototype.isScrolledToBottom=function(t){if(!this.getListNode().length)return!1;t=t||0;var e=this.getListNode()[0];return e.scrollHeight-e.offsetHeight-e.scrollTop<=t},u.prototype.initScroll=function(){var e,t,o,i;if(window.IntersectionObserver)return e=this.getListNode(),t=n('
'),e.prepend(t),o=this,i=new IntersectionObserver(function(t){o.preventScrollLoading()||t.length&&t[0].isIntersecting&&(a.prepend(e),o.loadMore().finally(function(){a.reset(e)}))},{root:e[0],rootMargin:"50px"}),this.assureScroll().then(function(){i.observe(t[0]),l.isLarge()&&(o.getListNode().niceScroll({cursorwidth:"7",cursorborder:"",cursorcolor:"#555",cursoropacitymax:"0.2",nativeparentscrolling:!1,railpadding:{top:0,right:0,left:0,bottom:0}}),o.scrollDownButton=void 0,o.getListNode().on("scroll",()=>o.getScrollDownButton().toggle(!o.isScrolledToBottom())))})},u.prototype.getScrollDownButton=function(){return"object"!=typeof this.scrollDownButton&&(this.scrollDownButton=n("
").addClass("conversation-scroll-down-button").html('').on("click",()=>this.scrollToBottom()),this.getListNode().append(this.scrollDownButton)),this.scrollDownButton},u.prototype.loadMore=function(){var o=this,t={id:this.getActiveMessageId(),from:this.$.find(".mail-conversation-entry:first").data("entryId")};return c.get(this.options.loadMoreUrl,{data:t}).then(function(t){var e;t.result&&(e=n(t.result).hide(),o.getListNode().find(".conversation-stream-end").after(e),e.fadeIn()),o.options.isLast=!t.result||t.isLast}).catch(function(t){r.log.error(t,!0)})},u.prototype.preventScrollLoading=function(){return this.scrollLock||!this.canLoadMore()},u.prototype.canLoadMore=function(){return!this.options.isLast},u.prototype.assureScroll=function(){var t=this,e=this.getListNode();return e[0].offsetHeight>=e[0].scrollHeight&&this.canLoadMore()?this.loadMore().then(function(){return t.assureScroll()}).catch(function(){return Promise.resolve()}):t.scrollToBottom()},u.prototype.updateContent=function(e){var o=this;return new Promise(function(t){o.$.html(e),t()})},u.prototype.getActiveMessageId=function(){return this.options.messageId},u.prototype.setActiveMessageId=function(t){this.options.messageId=t},u.prototype.scrollToBottom=function(){var o=this;return new Promise(function(e){setTimeout(function(){o.$.imagesLoaded(function(){var t=o.getListNode();t.length&&o.updateSize(!1).then(function(){t[0].scrollTop=t[0].scrollHeight,e()})})})})},u.prototype.updateSize=function(n){var r=this;return new Promise(function(i){setTimeout(function(){var t,e,o=r.getListNode();o.length&&(t=(t=r.getReplyRichtext())?t.$.closest(".mail-message-form").innerHeight():0,o.css("margin-bottom",t+5+"px"),e=r.getListNode().offset().top,e=window.innerHeight-e-t-(l.isSmall()?20:30)+"px",o.css("height",e),o.css("max-height",e),!1!==n&&r.scrollToBottom(),i())},100)})},u.prototype.getListNode=function(){return this.$.find(".conversation-entry-list")},u.prototype.onUpdate=function(){l.isLarge()&&this.getListNode().getNiceScroll().resize()},r.export=u}),humhub.module("mail.ConversationEntry",function(t,e,i){e=e("ui.widget").Widget.extend();e.prototype.replace=function(t){var e=this,o=i(t).hide();this.$.fadeOut(function(){i(this).replaceWith(o),e.$=o,e.$.fadeIn("slow")})},e.prototype.remove=function(){this.$.fadeToggle("slow",function(){i(this).remove()})},t.export=e}),humhub.module("mail.inbox",function(n,t,r){var e=t("ui.widget").Widget,o=t("ui.filter").Filter,i=t("ui.view"),s=t("ui.loader"),a=t("client"),t=o.extend(),o=(t.prototype.triggerChange=function(){this.super("triggerChange"),this.updateFilterCount()},t.prototype.updateFilterCount=function(){var t=this.getActiveFilterCount(),e=this.$.find("#conversation-filter-link"),o=e.find(".filterCount");t?(o=o.length?o:r('').insertBefore(e.find(".caret"))).html(" ("+t+") "):o.length&&o.remove()},e.extend());o.prototype.init=function(){this.filter=e.instance("#mail-filter-root"),this.initScroll(),this.initHeight();var t=this;this.filter.off("afterChange.inbox").on("afterChange.inbox",function(){t.reload().then(function(){t.updateActiveItem()})}),i.isLarge()&&this.$.niceScroll({cursorwidth:"7",cursorborder:"",cursorcolor:"#555",cursoropacitymax:"0.2",nativeparentscrolling:!1,railpadding:{top:0,right:3,left:0,bottom:0}}),this.$.on("click",".entry",function(){t.$.find(".entry").removeClass("selected"),r(this).addClass("selected")})},o.prototype.initHeight=function(){var t=this.$.offset().top;this.$.css("max-height",window.innerHeight-t-15+"px")},o.prototype.updateEntries=function(t){var o=this;t.length&&a.get(this.options.updateEntriesUrl,{data:{ids:t}}).then(function(t){t.result&&(r.each(t.result,function(t,e){t=o.getEntry(t);t.length?t.replaceWith(e):r(e).prependTo(o.$)}),o.updateActiveItem())}).catch(function(t){n.log.error(t)})},o.prototype.getEntry=function(t){return this.$.find('[data-message-id="'+t+'"]')},o.prototype.initScroll=function(){var t,e,o;window.IntersectionObserver&&(t=r('
'),this.$.append(t),e=this,o=new IntersectionObserver(function(t){e.preventScrollLoading()||t.length&&t[0].isIntersecting&&(s.append(e.$),e.loadMore().finally(function(){s.reset(e.$)}))},{root:this.$[0],rootMargin:"50px"}),this.assureScroll().then(function(){o.observe(t[0])}))},o.prototype.assureScroll=function(){var t=this;return this.$[0].offsetHeight>=this.$[0].scrollHeight&&this.canLoadMore()?this.loadMore().then(function(){return t.assureScroll()}).catch(function(){return Promise.resolve()}):Promise.resolve()},o.prototype.loadMore=function(){var i=this;return new Promise(function(e,o){var t=i.filter.getFilterMap();t.from=i.getLastMessageId(),a.get(i.options.loadMoreUrl,{data:t}).then(function(t){t.result&&(r(t.result).insertBefore(".inbox-stream-end"),i.$.find(".inbox-stream-end").append()),i.options.isLast=!t.result||t.isLast,i.updateActiveItem(),e()}).catch(function(t){n.log.error(t,!0),o()}).finally(function(){i.scrollLock=!1})})},o.prototype.preventScrollLoading=function(){return this.scrollLock||!this.canLoadMore()},o.prototype.canLoadMore=function(){return!this.options.isLast},o.prototype.getReloadOptions=function(){return{data:this.filter.getFilterMap()}},o.prototype.updateActiveItem=function(){var t=e.instance("#mail-conversation-root").getActiveMessageId(),t=(this.$.find(".entry").removeClass("selected"),this.$.find(".entry").removeClass("selected"),this.$.find('[data-message-id="'+t+'"]'));t.length&&t.removeClass("unread").addClass("selected")},o.prototype.getFirstMessageId=function(){return this.$.find(".entry:first").data("message-id")},o.prototype.getLastMessageId=function(){return this.$.find(".entry:last").data("message-id")},o.prototype.hide=function(){return new Promise(function(t){i.isSmall()&&r(".mail-conversation-single-message").length&&r(".inbox-wrapper").slideUp(function(){r("#mail-conversation-root").length&&e.instance("#mail-conversation-root").updateSize(),t()}),t()})},o.prototype.show=function(){return new Promise(function(t){i.isSmall()&&r(".inbox-wrapper").slideDown(function(){r("#mail-conversation-root").length&&e.instance("#mail-conversation-root").updateSize(),t()}),t()})};n.export({ConversationList:o,Filter:t,setTagFilter:function(t){e.instance("#inbox").show().then(function(){r("#mail-filter-menu").collapse("show"),e.instance("#inbox-tag-picker").setSelection([{id:t.$trigger.data("tagId"),text:t.$trigger.data("tagName"),image:t.$trigger.data("tagImage")}])})},toggleInbox:function(){i.isSmall()&&r(".inbox-wrapper").slideToggle(function(){e.instance("#mail-conversation-root").updateSize()})}})}),humhub.module("mail.conversation",function(i,t,r){function n(t){return s.instance('.mail-conversation-entry[data-entry-id="'+t+'"]')}var s=t("ui.widget").Widget,a=t("ui.modal"),o=t("client"),e=t("event"),c=t("mail.notification");i.export({init:function(){e.on("humhub:modules:mail:live:NewUserMessage",function(t,e){var o,i,n;r("#inbox").length&&(o=s.instance("#mail-conversation-root"),i=!1,n=[],e.forEach(function(t){n.push(t.data.message_id),!i&&o&&o.options.messageId==t.data.message_id&&(o.loadUpdate(),i=!0,o.markSeen(t.data.message_id))}),s.instance("#inbox").updateEntries(n))}).on("humhub:modules:mail:live:UserMessageDeleted",function(t,e,o){r("#inbox").length&&e.forEach(function(t){var e=n(t.data.entry_id);e&&e.remove(),c.setMailMessageCount(t.data.count)})})},linkAction:function(t){o.post(t).then(function(t){t.redirect&&o.pjax.redirect(t.redirect)}).catch(function(t){i.log.error(t,!0)})},submitEditEntry:function(o){a.submit(o).then(function(t){var e;t.success?(e=n(o.$trigger.data("entry-id")))&&setTimeout(function(){e.replace(t.content)},300):i.log.error(null,!0)}).catch(function(t){i.log.error(t,!0)})},deleteEntry:function(t){var e=n(t.$trigger.data("entry-id"));e?o.post(e.options.deleteUrl).then(function(t){a.global.close(),t.success&&setTimeout(function(){e.remove()},1e3)}).catch(function(t){i.log.error(t,!0)}):i.log.error(null,!0)}})}); \ No newline at end of file diff --git a/widgets/PinLink.php b/widgets/PinLink.php new file mode 100644 index 00000000..eeae056f --- /dev/null +++ b/widgets/PinLink.php @@ -0,0 +1,35 @@ +message->isPinned()) { + return Link::none(Yii::t('MailModule.base', 'Unpin')) + ->action('mail.conversation.linkAction', Url::toUnpinConversation($this->message)) + ->icon('map-pin'); + } + + return Link::none(Yii::t('MailModule.base', 'Pin')) + ->action('mail.conversation.linkAction', Url::toPinConversation($this->message)) + ->icon('map-pin'); + } +} diff --git a/widgets/views/conversationHeader.php b/widgets/views/conversationHeader.php index 7e6695e9..d80188ce 100644 --- a/widgets/views/conversationHeader.php +++ b/widgets/views/conversationHeader.php @@ -7,10 +7,10 @@ /* @var $message Message */ ?> -

title) ?>

+

title) . ' ' . $message->getPinIcon() ?>

$message]) ?>
- $message]) ?> \ No newline at end of file + $message]) ?> diff --git a/widgets/views/conversationSettingsMenu.php b/widgets/views/conversationSettingsMenu.php index 63b07add..1519e3c6 100644 --- a/widgets/views/conversationSettingsMenu.php +++ b/widgets/views/conversationSettingsMenu.php @@ -2,6 +2,7 @@ use humhub\modules\mail\helpers\Url; use humhub\modules\mail\models\Message; +use humhub\modules\mail\widgets\PinLink; use humhub\modules\ui\icon\widgets\Icon; use humhub\widgets\Link; use humhub\widgets\ModalButton; @@ -44,9 +45,19 @@ +
  • + action('mail.conversation.linkAction', Url::toMarkUnreadConversation($message)) + ->icon('eye-slash') ?> +
  • + +
  • + $message]) ?> +
  • +
  • action('mail.conversation.leave', Url::toLeaveConversation($message)) + ->action('mail.conversation.linkAction', Url::toLeaveConversation($message)) ->confirm($leaveConfirmTitle, $leaveConfirmText, $leaveConfirmButtonText) ->icon('sign-out') ->loader(false) ?> diff --git a/widgets/views/inboxMessagePreview.php b/widgets/views/inboxMessagePreview.php index d59ee44a..dcd974c8 100644 --- a/widgets/views/inboxMessagePreview.php +++ b/widgets/views/inboxMessagePreview.php @@ -31,7 +31,7 @@
  • - + getPinIcon() ?>