Use permalink comment in notification (#5464)

This commit is contained in:
Yuriy Bakhtin 2021-12-07 18:17:02 +03:00 committed by GitHub
parent 04e7ae543c
commit bfd9df6e50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 11 deletions

View File

@ -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)

View File

@ -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;
}
}

View File

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

View File

@ -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;
}
}

View File

@ -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', '<strong>Permalink</strong> to this comment'),
],