Skip to content

Commit

Permalink
fix(mentions): cannot use mentionables extender
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Jun 30, 2023
1 parent 5437bf5 commit 96d567b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
3 changes: 0 additions & 3 deletions extensions/mentions/js/src/forum/addComposerAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<div class="ComposerBody-mentionsDropdownContainer"></div>');
const dropdown = new AutocompleteDropdown();

Expand Down
5 changes: 5 additions & 0 deletions extensions/mentions/js/src/forum/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Extend from 'flarum/common/extenders';
import Post from 'flarum/common/models/Post';
import User from 'flarum/common/models/User';
import MentionsUserPage from './components/MentionsUserPage';
import Mentionables from "./extenders/Mentionables";
import TagMention from "./mentionables/TagMention";

export default [
new Extend.Routes() //
Expand All @@ -13,4 +15,7 @@ export default [

new Extend.Model(User) //
.attribute<boolean>('canMentionGroups'),

new Mentionables()
.mentionable('#', TagMention),
];
4 changes: 2 additions & 2 deletions extensions/mentions/js/src/forum/extenders/Mentionables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type MentionFormat from '../mentionables/formats/MentionFormat';

export default class Mentionables implements IExtender<ForumApplication> {
protected formats: (new () => MentionFormat)[] = [];
protected mentionables: Record<string, (new () => MentionableModel)[]> = {};
protected mentionables: Record<string, (new (...args: any[]) => MentionableModel)[]> = {};

/**
* Register a new mention format.
Expand All @@ -26,7 +26,7 @@ export default class Mentionables implements IExtender<ForumApplication> {
* @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] = [];
}
Expand Down
3 changes: 3 additions & 0 deletions extensions/mentions/js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '#';
Expand Down

0 comments on commit 96d567b

Please sign in to comment.