mirror of
https://github.com/flarum/framework.git
synced 2025-03-03 22:19:40 +08:00
fix?: Allow mentions from non-post objects (#79)
This commit is contained in:
parent
e8cb1559cf
commit
7d3bc4a092
@ -10,6 +10,7 @@
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Http\SlugManager;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use s9e\TextFormatter\Renderer;
|
||||
use s9e\TextFormatter\Utils;
|
||||
@ -43,10 +44,10 @@ class FormatUserMentions
|
||||
*/
|
||||
public function __invoke(Renderer $renderer, $context, string $xml)
|
||||
{
|
||||
$post = $context;
|
||||
|
||||
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($post) {
|
||||
$user = $post->mentionsUsers->find($attributes['id']);
|
||||
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) {
|
||||
$user = (isset($context->getRelations()['mentionsUsers']) || $context instanceof Post)
|
||||
? $context->mentionsUsers->find($attributes['id'])
|
||||
: User::find($attributes['id']);
|
||||
|
||||
$attributes['deleted'] = false;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
@ -49,10 +50,10 @@ class UnparseUserMentions
|
||||
*/
|
||||
protected function updateUserMentionTags($context, string $xml): string
|
||||
{
|
||||
$post = $context;
|
||||
|
||||
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($post) {
|
||||
$user = $post->mentionsUsers->find($attributes['id']);
|
||||
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) {
|
||||
$user = (isset($context->getRelations()['mentionsUsers']) || $context instanceof Post)
|
||||
? $context->mentionsUsers->find($attributes['id'])
|
||||
: User::find($attributes['id']);
|
||||
|
||||
if ($user) {
|
||||
$attributes['displayname'] = $user->display_name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user