diff --git a/CHANGELOG.md b/CHANGELOG.md index 3499a1d86..bcddd5f9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ * recover temporary solution for html entities in browser title (e72541e35de4f71f9d870bbd9bb46ddf586bdf1d) * custom contrast color affected by parents (577890d89c593ae5b6cb96083fab69e2f1ae600c) * reply placeholder wrong positioning (253a3d281dbf5ce3fa712b629b80587cf67e7dbe) +* (mentions) missed post mentions UI changes with lazy loading [#3832] +* (mentions) cannot use newly introduced mentionables extender [#3849] +* (mentions) missing slug from post mention links ([5a4bb7c](5a4bb7ccf226f66dd44816cb69b3d7cfe4ad7f7c)) ## [v1.8.0](https://github.com/flarum/framework/compare/v1.7.1...v1.8.0) ### Fixed diff --git a/extensions/mentions/extend.php b/extensions/mentions/extend.php index b659d049d..5f9c568b8 100644 --- a/extensions/mentions/extend.php +++ b/extensions/mentions/extend.php @@ -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::mutateRelation(...)) ->prepareDataForSerialization(LoadMentionedByRelationship::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::mutateRelation(...)) ->prepareDataForSerialization(LoadMentionedByRelationship::countRelation(...)), diff --git a/extensions/mentions/js/src/forum/addComposerAutocomplete.js b/extensions/mentions/js/src/forum/addComposerAutocomplete.js index 09808a56a..a4f02e20e 100644 --- a/extensions/mentions/js/src/forum/addComposerAutocomplete.js +++ b/extensions/mentions/js/src/forum/addComposerAutocomplete.js @@ -5,12 +5,9 @@ import TextEditorButton from 'flarum/common/components/TextEditorButton'; import KeyboardNavigatable from 'flarum/common/utils/KeyboardNavigatable'; import AutocompleteDropdown from './fragments/AutocompleteDropdown'; -import MentionFormats from './mentionables/formats/MentionFormats'; import MentionableModels from './mentionables/MentionableModels'; export default function addComposerAutocomplete() { - app.mentionFormats = new MentionFormats(); - const $container = $('
'); const dropdown = new AutocompleteDropdown(); diff --git a/extensions/mentions/js/src/forum/addMentionedByList.js b/extensions/mentions/js/src/forum/addMentionedByList.js index 45b54023d..48fe082f6 100644 --- a/extensions/mentions/js/src/forum/addMentionedByList.js +++ b/extensions/mentions/js/src/forum/addMentionedByList.js @@ -118,7 +118,7 @@ export default function addMentionedByList() { }); const limit = 4; - const overLimit = repliers.length > limit; + const overLimit = post.mentionedByCount() > limit; // Create a list of unique users who have replied. So even if a user has // replied twice, they will only be in this array once. @@ -136,7 +136,7 @@ export default function addMentionedByList() { // others" name to the end of the list. Clicking on it will display a modal // with a full list of names. if (overLimit) { - const count = repliers.length - names.length; + const count = post.mentionedByCount() - names.length; names.push(app.translator.trans('flarum-mentions.forum.post.others_text', { count })); } diff --git a/extensions/mentions/js/src/forum/extenders/Mentionables.ts b/extensions/mentions/js/src/forum/extenders/Mentionables.ts index cf2db51f7..46423ae54 100644 --- a/extensions/mentions/js/src/forum/extenders/Mentionables.ts +++ b/extensions/mentions/js/src/forum/extenders/Mentionables.ts @@ -5,7 +5,7 @@ import type MentionFormat from '../mentionables/formats/MentionFormat'; export default class Mentionables implements IExtender { protected formats: (new () => MentionFormat)[] = []; - protected mentionables: Record MentionableModel)[]> = {}; + protected mentionables: Record MentionableModel)[]> = {}; /** * Register a new mention format. @@ -26,7 +26,7 @@ export default class Mentionables implements IExtender { * @param mentionable The mentionable instance to register. * Must extend MentionableModel. */ - mentionable(symbol: string, mentionable: new () => MentionableModel): this { + mentionable(symbol: string, mentionable: new (...args: any[]) => MentionableModel): this { if (!this.mentionables[symbol]) { this.mentionables[symbol] = []; } diff --git a/extensions/mentions/js/src/forum/index.js b/extensions/mentions/js/src/forum/index.js index 4d20ffc98..3022293c8 100644 --- a/extensions/mentions/js/src/forum/index.js +++ b/extensions/mentions/js/src/forum/index.js @@ -13,9 +13,12 @@ import addComposerAutocomplete from './addComposerAutocomplete'; import PostMentionedNotification from './components/PostMentionedNotification'; import UserMentionedNotification from './components/UserMentionedNotification'; import GroupMentionedNotification from './components/GroupMentionedNotification'; +import MentionFormats from './mentionables/formats/MentionFormats'; import UserPage from 'flarum/forum/components/UserPage'; import LinkButton from 'flarum/common/components/LinkButton'; +app.mentionFormats = new MentionFormats(); + export { default as extend } from './extend'; app.initializers.add('flarum-mentions', function () { diff --git a/extensions/mentions/js/src/forum/mentionables/formats/HashMentionFormat.ts b/extensions/mentions/js/src/forum/mentionables/formats/HashMentionFormat.ts index a01bf00e9..ef30d50c9 100644 --- a/extensions/mentions/js/src/forum/mentionables/formats/HashMentionFormat.ts +++ b/extensions/mentions/js/src/forum/mentionables/formats/HashMentionFormat.ts @@ -4,7 +4,7 @@ import TagMention from '../TagMention'; export default class HashMentionFormat extends MentionFormat { public mentionables: (new (...args: any[]) => MentionableModel)[] = [TagMention]; - protected extendable: boolean = false; + protected extendable: boolean = true; public trigger(): string { return '#'; diff --git a/extensions/mentions/src/Api/LoadMentionedByRelationship.php b/extensions/mentions/src/Api/LoadMentionedByRelationship.php index 82f916869..47bceafb7 100644 --- a/extensions/mentions/src/Api/LoadMentionedByRelationship.php +++ b/extensions/mentions/src/Api/LoadMentionedByRelationship.php @@ -30,7 +30,7 @@ class LoadMentionedByRelationship $actor = RequestUtil::getActor($request); $query - ->with(['mentionsPosts', 'mentionsPosts.user', 'mentionsUsers']) + ->with(['mentionsPosts', 'mentionsPosts.user', 'mentionsPosts.discussion', 'mentionsUsers']) ->whereVisibleTo($actor) ->oldest() // Limiting a relationship results is only possible because @@ -53,6 +53,16 @@ class LoadMentionedByRelationship $loadable = $data->posts->filter(function ($post) { return $post instanceof Post; }); + + // firstPost and lastPost might have been included in the API response, + // so we have to make sure counts are also loaded for them. + if ($data->firstPost) { + $loadable->push($data->firstPost); + } + + if ($data->lastPost) { + $loadable->push($data->lastPost); + } } elseif ($data instanceof Collection) { $loadable = $data; } elseif ($data instanceof Post) { diff --git a/extensions/mentions/src/FilterVisiblePosts.php b/extensions/mentions/src/FilterVisiblePosts.php deleted file mode 100755 index e69de29bb..000000000 diff --git a/extensions/mentions/src/Formatter/FormatPostMentions.php b/extensions/mentions/src/Formatter/FormatPostMentions.php index ed17bcb79..992dca150 100644 --- a/extensions/mentions/src/Formatter/FormatPostMentions.php +++ b/extensions/mentions/src/Formatter/FormatPostMentions.php @@ -9,6 +9,8 @@ namespace Flarum\Mentions\Formatter; +use Flarum\Discussion\Discussion; +use Flarum\Http\SlugManager; use Flarum\Locale\TranslatorInterface; use Psr\Http\Message\ServerRequestInterface as Request; use s9e\TextFormatter\Renderer; @@ -17,7 +19,8 @@ use s9e\TextFormatter\Utils; class FormatPostMentions { public function __construct( - private readonly TranslatorInterface $translator + private readonly TranslatorInterface $translator, + private readonly SlugManager $slugManager ) { } @@ -42,6 +45,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; }); }