|
@@ -1,7 +1,7 @@
|
|
import { __ } from 'i18n';
|
|
import { __ } from 'i18n';
|
|
import { _converse } from "@converse/headless/core";
|
|
import { _converse } from "@converse/headless/core";
|
|
import { html } from 'lit';
|
|
import { html } from 'lit';
|
|
-
|
|
|
|
|
|
+import { api } from "@converse/headless/core";
|
|
|
|
|
|
export function clearHistory (jid) {
|
|
export function clearHistory (jid) {
|
|
if (_converse.router.history.getFragment() === `converse/chat?jid=${jid}`) {
|
|
if (_converse.router.history.getFragment() === `converse/chat?jid=${jid}`) {
|
|
@@ -39,9 +39,29 @@ export async function clearMessages (chat) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-export function parseMessageForCommands (chat, text) {
|
|
|
|
|
|
+export async function parseMessageForCommands (chat, text) {
|
|
|
|
+ /**
|
|
|
|
+ * *Hook* which allows plugins to add more commands to a chat's textbox.
|
|
|
|
+ * Data provided is the chatbox model and the text typed - {model, text}.
|
|
|
|
+ * Check `handled` to see if the hook was already handled.
|
|
|
|
+ * @event _converse#parseMessageForCommands
|
|
|
|
+ * @example
|
|
|
|
+ * api.listen.on('parseMessageForCommands', (data, handled) {
|
|
|
|
+ * if (!handled) {
|
|
|
|
+ * const command = (data.text.match(/^\/([a-zA-Z]*) ?/) || ['']).pop().toLowerCase();
|
|
|
|
+ * // custom code comes here
|
|
|
|
+ * }
|
|
|
|
+ * return handled;
|
|
|
|
+ * }
|
|
|
|
+ */
|
|
const match = text.replace(/^\s*/, '').match(/^\/(.*)\s*$/);
|
|
const match = text.replace(/^\s*/, '').match(/^\/(.*)\s*$/);
|
|
if (match) {
|
|
if (match) {
|
|
|
|
+ let handled = false;
|
|
|
|
+ handled = await api.hook('parseMessageForCommands', {model: chat, text}, handled);
|
|
|
|
+ if (handled) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (match[1] === 'clear') {
|
|
if (match[1] === 'clear') {
|
|
clearMessages(chat);
|
|
clearMessages(chat);
|
|
return true;
|
|
return true;
|
|
@@ -54,6 +74,7 @@ export function parseMessageForCommands (chat, text) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
export function resetElementHeight (ev) {
|
|
export function resetElementHeight (ev) {
|