MUC: Register handler to parse for commands in the plugin index.js

This commit is contained in:
JC Brand 2022-02-14 15:16:51 +01:00
parent e1a919749f
commit 7c7b667745
3 changed files with 7 additions and 5 deletions

View File

@ -8,7 +8,7 @@ import 'plugins/modal/index.js';
import './adhoc-commands.js';
import MUCView from './muc.js';
import { api, converse } from '@converse/headless/core';
import { clearHistory, fetchAndSetMUCDomain } from './utils.js';
import { clearHistory, fetchAndSetMUCDomain, parseMessageForMUCCommands } from './utils.js';
import './styles/index.scss';
@ -80,5 +80,7 @@ converse.plugins.add('converse-muc-views', {
clearHistory(model.get('jid'));
}
});
api.listen.on('parseMessageForCommands', parseMessageForMUCCommands);
}
});

View File

@ -1,7 +1,7 @@
import MessageForm from 'plugins/chatview/message-form.js';
import tpl_muc_message_form from './templates/message-form.js';
import { _converse, api, converse } from "@converse/headless/core";
import { getAutoCompleteListItem, parseMessageForMUCCommands } from './utils.js';
import { getAutoCompleteListItem } from './utils.js';
export default class MUCMessageForm extends MessageForm {
@ -9,7 +9,6 @@ export default class MUCMessageForm extends MessageForm {
async connectedCallback () {
super.connectedCallback();
await this.model.initialized;
api.listen.on('parseMessageForCommands', parseMessageForMUCCommands);
}
toHTML () {

View File

@ -296,7 +296,9 @@ export function showOccupantModal (ev, occupant) {
export function parseMessageForMUCCommands (data, handled) {
if (handled || (
const model = data.model;
if (handled ||
model.get('type') !== _converse.CHATROOMS_TYPE || (
api.settings.get('muc_disable_slash_commands') &&
!Array.isArray(api.settings.get('muc_disable_slash_commands'))
)) {
@ -310,7 +312,6 @@ export function parseMessageForMUCCommands (data, handled) {
return false;
}
const model = data.model;
const args = text.slice(('/' + command).length + 1).trim();
const allowed_commands = model.getAllowedCommands() ?? [];