1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 07:27:39 +02:00

fix?: Allow mentions from non-post objects (#79)

This commit is contained in:
Ian Morland
2021-11-28 08:52:29 +00:00
committed by GitHub
parent e8cb1559cf
commit 7d3bc4a092
2 changed files with 10 additions and 8 deletions

View File

@@ -10,6 +10,7 @@
namespace Flarum\Mentions\Formatter; namespace Flarum\Mentions\Formatter;
use Flarum\Http\SlugManager; use Flarum\Http\SlugManager;
use Flarum\Post\Post;
use Flarum\User\User; use Flarum\User\User;
use s9e\TextFormatter\Renderer; use s9e\TextFormatter\Renderer;
use s9e\TextFormatter\Utils; use s9e\TextFormatter\Utils;
@@ -43,10 +44,10 @@ class FormatUserMentions
*/ */
public function __invoke(Renderer $renderer, $context, string $xml) public function __invoke(Renderer $renderer, $context, string $xml)
{ {
$post = $context; return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) {
$user = (isset($context->getRelations()['mentionsUsers']) || $context instanceof Post)
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($post) { ? $context->mentionsUsers->find($attributes['id'])
$user = $post->mentionsUsers->find($attributes['id']); : User::find($attributes['id']);
$attributes['deleted'] = false; $attributes['deleted'] = false;

View File

@@ -9,6 +9,7 @@
namespace Flarum\Mentions\Formatter; namespace Flarum\Mentions\Formatter;
use Flarum\Post\Post;
use Flarum\User\User; use Flarum\User\User;
use s9e\TextFormatter\Utils; use s9e\TextFormatter\Utils;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
@@ -49,10 +50,10 @@ class UnparseUserMentions
*/ */
protected function updateUserMentionTags($context, string $xml): string protected function updateUserMentionTags($context, string $xml): string
{ {
$post = $context; return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) {
$user = (isset($context->getRelations()['mentionsUsers']) || $context instanceof Post)
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($post) { ? $context->mentionsUsers->find($attributes['id'])
$user = $post->mentionsUsers->find($attributes['id']); : User::find($attributes['id']);
if ($user) { if ($user) {
$attributes['displayname'] = $user->display_name; $attributes['displayname'] = $user->display_name;