mirror of
https://github.com/flarum/framework.git
synced 2025-02-01 02:23:00 +08:00
chore: simplify checking of current composer
This commit is contained in:
parent
6e5180dcfe
commit
53ac644516
|
@ -21,10 +21,7 @@ export default class PostMention extends MentionableModel<Post, AtMentionFormat>
|
|||
* match any username characters that have been typed.
|
||||
*/
|
||||
initialResults(): Post[] {
|
||||
const EditPostComposer = flarum.reg.checkModule('core', 'forum/components/EditPostComposer');
|
||||
const ReplyComposer = flarum.reg.checkModule('core', 'forum/components/ReplyComposer');
|
||||
|
||||
if ((!ReplyComposer || !app.composer.bodyMatches(ReplyComposer)) && (!EditPostComposer || !app.composer.bodyMatches(EditPostComposer))) {
|
||||
if (!app.composer.bodyMatches('flarum/forum/components/ReplyComposer') && !app.composer.bodyMatches('flarum/forum/components/EditPostComposer')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,7 @@ export function insertMention(post, composer, quote) {
|
|||
}
|
||||
|
||||
export default function reply(post, quote) {
|
||||
const EditPostComposer = flarum.reg.checkModule('core', 'forum/components/EditPostComposer');
|
||||
|
||||
if (EditPostComposer && app.composer.bodyMatches(EditPostComposer) && app.composer.body.attrs.post.discussion() === post.discussion()) {
|
||||
if (app.composer.bodyMatches('flarum/forum/components/EditPostComposer') && app.composer.body.attrs.post.discussion() === post.discussion()) {
|
||||
// If we're already editing a post in the discussion of post we're quoting,
|
||||
// insert the mention directly.
|
||||
return insertMention(post, app.composer, quote);
|
||||
|
|
|
@ -24,11 +24,7 @@ app.initializers.add('flarum-messages', () => {
|
|||
);
|
||||
|
||||
app.composer.composingMessageTo = function (dialog: Dialog) {
|
||||
const MessageComposer = flarum.reg.checkModule('flarum-messages', 'forum/components/MessageComposer');
|
||||
|
||||
if (!MessageComposer) return false;
|
||||
|
||||
return this.isVisible() && this.bodyMatches(MessageComposer, { dialog });
|
||||
return this.isVisible() && this.bodyMatches('flarum/messages/forum/components/MessageComposer', { dialog });
|
||||
};
|
||||
|
||||
extend(IndexSidebar.prototype, 'navItems', function (items) {
|
||||
|
|
|
@ -107,11 +107,7 @@ export default class CommentPost extends Post {
|
|||
}
|
||||
|
||||
isEditing() {
|
||||
const EditPostComposer = flarum.reg.checkModule('core', 'forum/components/EditPostComposer');
|
||||
|
||||
if (!EditPostComposer) return false;
|
||||
|
||||
return app.composer.bodyMatches(EditPostComposer, { post: this.attrs.post });
|
||||
return app.composer.bodyMatches('flarum/forum/components/EditPostComposer', { post: this.attrs.post });
|
||||
}
|
||||
|
||||
elementAttrs() {
|
||||
|
|
|
@ -171,7 +171,15 @@ class ComposerState {
|
|||
* @param type The component class to check against. Subclasses are accepted as well.
|
||||
* @param data
|
||||
*/
|
||||
bodyMatches(type: object, data: any = {}): boolean {
|
||||
bodyMatches(type: object | string, data: any = {}): boolean {
|
||||
if (typeof type === 'string') {
|
||||
const [namespace, id] = flarum.reg.namespaceAndIdFromPath(type);
|
||||
|
||||
type = flarum.reg.checkModule(namespace, id);
|
||||
|
||||
if (!type) return false;
|
||||
}
|
||||
|
||||
// Fail early when the body is of a different type
|
||||
if (!subclassOf(this.body.componentClass, type)) return false;
|
||||
|
||||
|
@ -212,11 +220,7 @@ class ComposerState {
|
|||
* @return {boolean}
|
||||
*/
|
||||
composingReplyTo(discussion: Discussion) {
|
||||
const ReplyComposer = flarum.reg.checkModule('core', 'forum/components/ReplyComposer');
|
||||
|
||||
if (!ReplyComposer) return false;
|
||||
|
||||
return this.isVisible() && this.bodyMatches(ReplyComposer, { discussion });
|
||||
return this.isVisible() && this.bodyMatches('flarum/forum/components/ReplyComposer', { discussion });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user