1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 16:36:47 +02:00

chore: simplify checking of current composer

This commit is contained in:
Sami Mazouz
2024-10-25 14:48:16 +01:00
parent 6e5180dcfe
commit 53ac644516
5 changed files with 14 additions and 23 deletions

View File

@@ -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() {

View File

@@ -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 });
}
/**