我如何在 conversejs 中添加回复消息

how can i add reply message in conversejs

我正在使用 converse.js 来提供聊天功能。我正在寻找一种方法来添加 回复特定的聊天室消息 。有人知道我该怎么做吗?

例如: 在组 user1 中发送:你好 用户 2 想回复此消息并向

问好

我的初始代码:

<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: "person@example.com",
        password: "somepassword",
        auto_join_rooms: [
            {
                'jid': 'group@conference.example.com',
                '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>

谢谢大家。

终于找到解决这个问题的方法了

首先在 convers.js/src/plugins/chatview/view.js 之前添加这个 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);
    },

并在 convers.js/src/components/message-actions.js 文件中,在 onMessageEditButtonClicked

之前添加以下代码
onMessageReplyButtonClicked(ev) {
        ev.preventDefault();
        this.chatview.onMessageReplyButtonClicked(this.model);
    }

并在 convers.js/src/headless/utils/cores.js 中将 u.prefixMentions 函数更改为:

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;
};