how can i add reply message in conversejs

346 Views Asked by At

I am using converse.js to provide chat functionality. I am looking for a way to add reply to specific chat room message. any one know how can i do that?

for example: in group user1 send: hello and user2 wants reply to this message and say hello to

my initial code:

<script>
    converse.initialize({
        authentication: 'login',
        //
        auto_login: true,
        allow_logout: false,
        show_client_info: false,
        allow_adhoc_commands: false,
        allow_contact_requests: false,
        hidden_occupants: true,
        blacklisted_plugins: [
            'converse-register',
            'converse-rosterview',
            'converse-bookmarks',
            'converse-profile',
        ],
        jid: "[email protected]",
        password: "somepassword",
        auto_join_rooms: [
            {
                'jid': '[email protected]',
                'nick': 'myname',
                'name': 'title',
                'minimized': true
            },
        ],
        //
        auto_reconnect: true,
        bosh_service_url: 'https://example.com:7443/http-bind/',
        message_archiving: 'always',
        view_mode: 'fullscreen'
    });
</script>

thanks all.

1

There are 1 best solutions below

0
On BEST ANSWER

Finally I find way to solve this problem.

first in convers.js/src/plugins/chatview/view.js add this before onMessageEditButtonClicked:

onMessageReplyButtonClicked (message) {
        const currently_correcting = this.model.messages.findWhere('correcting');
        const unsent_text = this.el.querySelector('.chat-textarea')?.value;
        if (unsent_text && (!currently_correcting || currently_correcting.get('message') !== unsent_text)) {
            if (!confirm(__('You have an unsent message which will be lost if you continue. Are you sure?'))) {
                return;
            }
        }
        this.insertIntoTextArea(u.prefixMentions(message, true), true, false);
    },

and in convers.js/src/components/message-actions.js file add below code before onMessageEditButtonClicked

onMessageReplyButtonClicked(ev) {
        ev.preventDefault();
        this.chatview.onMessageReplyButtonClicked(this.model);
    }

and in convers.js/src/headless/utils/cores.js change the u.prefixMentions function to:

u.prefixMentions = function (message, reply = false) {
    /* Given a message object, return its text with @ chars
     * inserted before the mentioned nicknames.
     */
    let text = message.get('message');
    (message.get('references') || [])
        .sort((a, b) => b.begin - a.begin)
        .forEach(ref => {
            text = `${text.slice(0, ref.begin)}@${text.slice(ref.begin)}`
        });

    if (reply){
        const lines = text.split('\n');
        let newtxt = ""
        for(let i = 0;i < lines.length;i++){
            if(!lines[i].startsWith(">")){
                newtxt += "> " + lines[i] + "\n"
            }
        }
        return "> reply to " + message.get('nick') + ":\n" + newtxt
    }
    else
        return text;
};