From 4bc14e6cea9ac152301c868203cc52165ac72693 Mon Sep 17 00:00:00 2001 From: ubermanu <e.vodor@gmail.com> Date: Tue, 16 Mar 2021 06:31:08 +0100 Subject: [PATCH] clean up code --- src/plugins/sib-reactions.js | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/plugins/sib-reactions.js b/src/plugins/sib-reactions.js index 4ff93a9..daed99d 100644 --- a/src/plugins/sib-reactions.js +++ b/src/plugins/sib-reactions.js @@ -110,15 +110,14 @@ converse.plugins.add('sib-reactions', { return reaction?.emojis || []; } - const Message = _converse.api.elements.registry['converse-chat-message']; - const renderMessageText = Message.prototype.renderMessageText; - + /** + * Extends the Message element. + * @type {*} + */ const MessageMixin = { renderMessageText() { - // console.log('renderMessageText', this.model.get('id'), this.model.get('reactions')); - return html` - ${renderMessageText.call(this)} + ${_renderMessageText.call(this)} ${this.hasReactions() && this.renderReactions()} `; }, @@ -208,8 +207,9 @@ converse.plugins.add('sib-reactions', { }, }; - // Apply message mixin + const Message = _converse.api.elements.registry['converse-chat-message']; + const _renderMessageText = Message.prototype.renderMessageText; Object.assign(Message.prototype, MessageMixin); /** @@ -220,7 +220,6 @@ converse.plugins.add('sib-reactions', { * @returns {*} */ function parseMessage(stanza, attrs) { - // console.log('parseMessage', stanza, attrs) const reactions = sizzle(`reactions[xmlns="${Strophe.NS.REACTIONS}"]`, stanza).pop(); if (!!reactions) { @@ -258,13 +257,8 @@ converse.plugins.add('sib-reactions', { } emojis.push(emoji); - - // Update the ui - // TODO: This should be updated in ChatBox#onMessage? - el.model.set('reactions', {}); // Forces refresh - el.model.save('reactions', emojis); - picker.remove(); + sendReactionStanza(el.model, emojis); }); }, @@ -275,8 +269,5 @@ converse.plugins.add('sib-reactions', { return buttons; }); - - // TODO: Remove (debugging) - // api.listen.on('message', d => console.log('message', d, d.stanza)); }, }); -- GitLab