From 2bc2899a1dc6ead615a98887c7306c9e56d1ee4b Mon Sep 17 00:00:00 2001 From: Rafael Horvat Date: Sat, 1 Jul 2023 18:44:59 +0200 Subject: [PATCH 1/5] fix(mentions): missed post mentions UI changes (#3832) Co-authored-by: Ian Morland --- extensions/mentions/js/src/forum/addMentionedByList.js | 4 ++-- .../mentions/src/Api/LoadMentionedByRelationship.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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/src/Api/LoadMentionedByRelationship.php b/extensions/mentions/src/Api/LoadMentionedByRelationship.php index 209e3be6b..14fc82430 100644 --- a/extensions/mentions/src/Api/LoadMentionedByRelationship.php +++ b/extensions/mentions/src/Api/LoadMentionedByRelationship.php @@ -50,6 +50,16 @@ class LoadMentionedByRelationship $loadable = $data->newCollection($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) { From d2a63296890759e0684caceaeba67e943e4092c2 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Sat, 1 Jul 2023 17:47:33 +0100 Subject: [PATCH 2/5] fix(mentions): cannot use mentionables extender (#3849) --- extensions/mentions/js/src/forum/addComposerAutocomplete.js | 3 --- extensions/mentions/js/src/forum/extenders/Mentionables.ts | 4 ++-- extensions/mentions/js/src/forum/index.js | 3 +++ .../js/src/forum/mentionables/formats/HashMentionFormat.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) 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/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 7323a00d7..56424cedf 100644 --- a/extensions/mentions/js/src/forum/index.js +++ b/extensions/mentions/js/src/forum/index.js @@ -13,11 +13,14 @@ 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'; import User from 'flarum/common/models/User'; import Model from 'flarum/common/Model'; +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 '#'; From 5a4bb7ccf226f66dd44816cb69b3d7cfe4ad7f7c Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Tue, 4 Jul 2023 11:00:45 +0100 Subject: [PATCH 3/5] fix: missing slug from post mention links --- extensions/mentions/extend.php | 10 ++++++---- .../src/Api/LoadMentionedByRelationship.php | 2 +- extensions/mentions/src/FilterVisiblePosts.php | 0 .../src/Formatter/FormatPostMentions.php | 17 ++++++++++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) delete mode 100755 extensions/mentions/src/FilterVisiblePosts.php diff --git a/extensions/mentions/extend.php b/extensions/mentions/extend.php index 52ee37717..6f59fd0b2 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::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']), diff --git a/extensions/mentions/src/Api/LoadMentionedByRelationship.php b/extensions/mentions/src/Api/LoadMentionedByRelationship.php index 14fc82430..7af49a7fd 100644 --- a/extensions/mentions/src/Api/LoadMentionedByRelationship.php +++ b/extensions/mentions/src/Api/LoadMentionedByRelationship.php @@ -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 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 45a485e57..2f745bfcc 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 @@ 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; }); } From 8538f9c8f6a166c965a22a97abf3b8f51a0eae59 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Tue, 4 Jul 2023 11:12:55 +0100 Subject: [PATCH 4/5] chore: prepare v1.8.2 release --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3499a1d86..7e5a8d295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [v1.8.2](https://github.com/flarum/framework/compare/v1.8.1...v1.8.2) +### Fixed +* (mentions) missed post mentions UI changes with lazy loading +* (mentions) cannot use newly introduced mentionables extender +* (mentions) missing slug from post mention links + ## [v1.8.1](https://github.com/flarum/framework/compare/v1.8.0...v1.8.1) ### Fixed * recover temporary solution for html entities in browser title (e72541e35de4f71f9d870bbd9bb46ddf586bdf1d) From 102e31754a60bb991a63b149472b4a980b3237ad Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Tue, 4 Jul 2023 11:19:15 +0100 Subject: [PATCH 5/5] chore: not 1.8.2 --- CHANGELOG.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e5a8d295..bcddd5f9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,13 @@ # Changelog -## [v1.8.2](https://github.com/flarum/framework/compare/v1.8.1...v1.8.2) -### Fixed -* (mentions) missed post mentions UI changes with lazy loading -* (mentions) cannot use newly introduced mentionables extender -* (mentions) missing slug from post mention links - ## [v1.8.1](https://github.com/flarum/framework/compare/v1.8.0...v1.8.1) ### Fixed * 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