From 1f90250c2041178b47f8ec4f17dbdc8d2a208ce9 Mon Sep 17 00:00:00 2001 From: ubermanu <e.vodor@gmail.com> Date: Mon, 15 Mar 2021 14:20:24 +0100 Subject: [PATCH] minor: add the previous message on a reply --- src/plugins/sib-reply-to-message.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/sib-reply-to-message.js b/src/plugins/sib-reply-to-message.js index 4871e3e..2b7e8d0 100644 --- a/src/plugins/sib-reply-to-message.js +++ b/src/plugins/sib-reply-to-message.js @@ -6,7 +6,11 @@ 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) => { @@ -20,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', -- GitLab