diff --git a/extensions/mentions/extend.php b/extensions/mentions/extend.php index 52ee377176..6f59fd0b20 100644 --- a/extensions/mentions/extend.php +++ b/extensions/mentions/extend.php @@ -78,15 +78,17 @@ ->addInclude(['posts.mentionedBy', 'posts.mentionedBy.user', 'posts.mentionedBy.discussion']) ->load([ 'posts.mentionsUsers', 'posts.mentionsPosts', 'posts.mentionsPosts.user', - 'posts.mentionsGroups' + 'posts.mentionsPosts.discussion', 'posts.mentionsGroups' ]) ->loadWhere('posts.mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation']) ->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']), (new Extend\ApiController(Controller\ListDiscussionsController::class)) ->load([ - 'firstPost.mentionsUsers', 'firstPost.mentionsPosts', 'firstPost.mentionsPosts.user', 'firstPost.mentionsGroups', - 'lastPost.mentionsUsers', 'lastPost.mentionsPosts', 'lastPost.mentionsPosts.user', 'lastPost.mentionsGroups', + 'firstPost.mentionsUsers', 'firstPost.mentionsPosts', + 'firstPost.mentionsPosts.user', 'firstPost.mentionsPosts.discussion', 'firstPost.mentionsGroups', + 'lastPost.mentionsUsers', 'lastPost.mentionsPosts', + 'lastPost.mentionsPosts.user', 'lastPost.mentionsPosts.discussion', 'lastPost.mentionsGroups', ]), (new Extend\ApiController(Controller\ShowPostController::class)) @@ -98,7 +100,7 @@ (new Extend\ApiController(Controller\ListPostsController::class)) ->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion']) - ->load(['mentionsUsers', 'mentionsPosts', 'mentionsPosts.user', 'mentionsGroups']) + ->load(['mentionsUsers', 'mentionsPosts', 'mentionsPosts.user', 'mentionsPosts.discussion', 'mentionsGroups']) ->loadWhere('mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation']) ->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']), diff --git a/extensions/mentions/src/Api/LoadMentionedByRelationship.php b/extensions/mentions/src/Api/LoadMentionedByRelationship.php index 14fc824306..7af49a7fd5 100644 --- a/extensions/mentions/src/Api/LoadMentionedByRelationship.php +++ b/extensions/mentions/src/Api/LoadMentionedByRelationship.php @@ -29,7 +29,7 @@ public static function mutateRelation(BelongsToMany $query, ServerRequestInterfa $actor = RequestUtil::getActor($request); return $query - ->with(['mentionsPosts', 'mentionsPosts.user', 'mentionsUsers']) + ->with(['mentionsPosts', 'mentionsPosts.user', 'mentionsPosts.discussion', 'mentionsUsers']) ->whereVisibleTo($actor) ->oldest() // Limiting a relationship results is only possible because diff --git a/extensions/mentions/src/FilterVisiblePosts.php b/extensions/mentions/src/FilterVisiblePosts.php deleted file mode 100755 index e69de29bb2..0000000000 diff --git a/extensions/mentions/src/Formatter/FormatPostMentions.php b/extensions/mentions/src/Formatter/FormatPostMentions.php index 45a485e57a..2f745bfcce 100644 --- a/extensions/mentions/src/Formatter/FormatPostMentions.php +++ b/extensions/mentions/src/Formatter/FormatPostMentions.php @@ -9,6 +9,9 @@ namespace Flarum\Mentions\Formatter; +use Flarum\Discussion\Discussion; +use Flarum\Http\SlugManager; +use Flarum\Post\CommentPost; use Psr\Http\Message\ServerRequestInterface as Request; use s9e\TextFormatter\Renderer; use s9e\TextFormatter\Utils; @@ -21,9 +24,15 @@ class FormatPostMentions */ private $translator; - public function __construct(TranslatorInterface $translator) + /** + * @var SlugManager + */ + private $slugManager; + + public function __construct(TranslatorInterface $translator, SlugManager $slugManager) { $this->translator = $translator; + $this->slugManager = $slugManager; } /** @@ -56,6 +65,12 @@ public function __invoke(Renderer $renderer, $context, $xml, Request $request = $attributes['displayname'] = $this->translator->trans('core.lib.username.deleted_text'); } + if ($post) { + $attributes['discussionid'] = $this->slugManager + ->forResource(Discussion::class) + ->toSlug($post->discussion); + } + return $attributes; }); }