From bfd9df6e5098d34c6eae509ae1be791e61aaa56b Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Tue, 7 Dec 2021 18:17:02 +0300 Subject: [PATCH] Use permalink comment in notification (#5464) --- CHANGELOG.md | 1 + .../modules/comment/activities/NewComment.php | 3 +-- .../humhub/modules/comment/models/Comment.php | 26 ++++++++++++++++--- .../comment/notifications/NewComment.php | 11 +++++++- .../comment/widgets/CommentControls.php | 5 +--- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3dfd61c1a..7bbe9dd578 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ HumHub Changelog - Fix #5450: Fix confirmation before close a form with unsaved changes on modal window - Fix #5453: Fix migration of default group - Enh #5461: Added Event after a new file content (new version) is stored +- Enh #5457: Use permalink comment in notification 1.10.1 (November 26, 2021) diff --git a/protected/humhub/modules/comment/activities/NewComment.php b/protected/humhub/modules/comment/activities/NewComment.php index 0841400383..cf2d1ce59b 100644 --- a/protected/humhub/modules/comment/activities/NewComment.php +++ b/protected/humhub/modules/comment/activities/NewComment.php @@ -12,7 +12,6 @@ use humhub\modules\comment\models\Comment; use Yii; use humhub\modules\activity\components\BaseActivity; use humhub\modules\activity\interfaces\ConfigurableActivityInterface; -use yii\helpers\Url; /** * NewComment activity @@ -58,7 +57,7 @@ class NewComment extends BaseActivity implements ConfigurableActivityInterface */ public function getUrl() { - return Url::to(['/comment/perma', 'id' => $this->source->id], true); + return $this->source->url; } } diff --git a/protected/humhub/modules/comment/models/Comment.php b/protected/humhub/modules/comment/models/Comment.php index 313f305cad..ca0c0bcf9c 100644 --- a/protected/humhub/modules/comment/models/Comment.php +++ b/protected/humhub/modules/comment/models/Comment.php @@ -8,13 +8,10 @@ namespace humhub\modules\comment\models; -use humhub\modules\comment\Module; -use Yii; -use yii\base\Exception; -use yii\db\ActiveRecord; use humhub\components\behaviors\PolymorphicRelation; use humhub\modules\comment\activities\NewComment; use humhub\modules\comment\live\NewComment as NewCommentLive; +use humhub\modules\comment\Module; use humhub\modules\comment\notifications\NewComment as NewCommentNotification; use humhub\modules\content\components\ContentActiveRecord; use humhub\modules\content\components\ContentAddonActiveRecord; @@ -23,6 +20,10 @@ use humhub\modules\content\widgets\richtext\RichText; use humhub\modules\search\libs\SearchHelper; use humhub\modules\space\models\Space; use humhub\modules\user\models\User; +use Yii; +use yii\base\Exception; +use yii\db\ActiveRecord; +use yii\helpers\Url; /** @@ -36,6 +37,7 @@ use humhub\modules\user\models\User; * @property integer $created_by * @property string $updated_at * @property integer $updated_by + * @property-read string $url @since 1.10.2 * * @since 0.5 */ @@ -324,4 +326,20 @@ class Comment extends ContentAddonActiveRecord implements ContentOwner { return $object instanceof Comment && $object->object_model === Comment::class; } + + /** + * Get comment permalink URL + * + * @param bool|string $scheme the URI scheme to use in the generated URL + * @return string + * @since 1.10.2 + */ + public function getUrl($scheme = true): string + { + if ($this->isNewRecord) { + return $this->content->getUrl(); + } + + return Url::to(['/comment/perma', 'id' => $this->id], $scheme); + } } diff --git a/protected/humhub/modules/comment/notifications/NewComment.php b/protected/humhub/modules/comment/notifications/NewComment.php index 50c150942a..363c5fb25f 100644 --- a/protected/humhub/modules/comment/notifications/NewComment.php +++ b/protected/humhub/modules/comment/notifications/NewComment.php @@ -12,10 +12,10 @@ use humhub\modules\comment\models\Comment; use humhub\modules\content\components\ContentActiveRecord; use humhub\modules\notification\components\BaseNotification; use humhub\modules\notification\models\Notification; +use humhub\modules\user\models\User; use humhub\modules\user\notifications\Mentioned; use Yii; use yii\bootstrap\Html; -use humhub\modules\user\models\User; /** * Notification for new comments @@ -202,4 +202,13 @@ class NewComment extends BaseNotification return $source->getCommentedRecord(); } + + + /** + * @inheritdoc + */ + public function getUrl() + { + return $this->source->url; + } } diff --git a/protected/humhub/modules/comment/widgets/CommentControls.php b/protected/humhub/modules/comment/widgets/CommentControls.php index 10d5234c02..a8666dfedb 100644 --- a/protected/humhub/modules/comment/widgets/CommentControls.php +++ b/protected/humhub/modules/comment/widgets/CommentControls.php @@ -7,11 +7,8 @@ namespace humhub\modules\comment\widgets; -use humhub\libs\Html; use humhub\modules\comment\models\Comment; -use humhub\modules\ui\menu\MenuEntry; use humhub\modules\ui\menu\MenuLink; -use humhub\modules\ui\menu\WidgetMenuEntry; use humhub\modules\ui\menu\widgets\Menu; use Yii; use yii\helpers\Url; @@ -51,7 +48,7 @@ class CommentControls extends Menu 'url' => '#', 'htmlOptions' => [ 'data-action-click' => 'content.permalink', - 'data-content-permalink' => Url::to(['/comment/perma', 'id' => $this->comment->id], true), + 'data-content-permalink' => $this->comment->url, 'data-content-permalink-title' => Yii::t('CommentModule.base', 'Permalink to this comment'), ],