1
0
mirror of https://github.com/flarum/core.git synced 2025-08-03 23:17:43 +02:00

fix: missing slug from post mention links

This commit is contained in:
Sami Mazouz
2023-07-04 11:00:45 +01:00
parent d2a6329689
commit 5a4bb7ccf2
4 changed files with 23 additions and 6 deletions

View File

@@ -78,15 +78,17 @@ return [
->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 @@ return [
(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']),

View File

@@ -29,7 +29,7 @@ class LoadMentionedByRelationship
$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

View File

@@ -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 @@ class FormatPostMentions
$attributes['displayname'] = $this->translator->trans('core.lib.username.deleted_text');
}
if ($post) {
$attributes['discussionid'] = $this->slugManager
->forResource(Discussion::class)
->toSlug($post->discussion);
}
return $attributes;
});
}