Skip to content
Snippets Groups Projects

#262 Reply to message

Merged Emmanuel Vodor requested to merge 262_reply_to_message into beta
1 file
+ 17
3
Compare changes
  • Side-by-side
  • Inline
/**
* Add an action button to reply to a message.
* TODO: Add settings to handle this plugin
*/
converse.plugins.add('sib-reply-to-message', {
initialize() {
const _converse = this._converse;
const { api, __ } = _converse;
const { utils } = converse.env;
const { utils, _ } = converse.env;
function removeQuotedMessages(text) {
return text.replace(/^>.*(\n)?/gm, '');
}
api.listen.on('getMessageActionButtons', (el, buttons) => {
// Do not add if the message is not from a MUC
// Do not add if the message is from the current user
if (el.model.get('type') !== 'groupchat' || el.model.get('from_real_jid') === _converse.bare_jid) {
if (el.model.get('type') !== 'groupchat' || el.model.get('sender') === 'me') {
return buttons;
}
@@ -19,7 +24,16 @@ converse.plugins.add('sib-reply-to-message', {
'i18n_text': __('Reply'),
'handler': ev => {
const chat_textarea = utils.ancestor(el, '.chatbox')?.querySelector('.chat-textarea');
chat_textarea.value = `@${el.model.get('nick')} `;
chat_textarea.value = '';
// Add the previous message without quoted messages (to avoid blockquotes into blockquotes)
const message = _.truncate(removeQuotedMessages(el.model.get('message')), { length: 100 });
if (message.length > 0) {
chat_textarea.value += `${message.replace(/^/gm, '>')}\n`;
}
// Add mention to the initial user and focus textarea
chat_textarea.value += `@${el.model.get('nick')} `;
chat_textarea.focus();
},
'button_class': 'chat-msg__action-reply',
Loading