使用strophe.js检索群聊历史记录

Retrieve groupchat history using strophe.js

本文关键字:历史 记录 检索 strophe js 使用      更新时间:2023-09-26

我正在使用ejabberd 15.06版本的Strophe.js。从后端数据库检索一对一聊天可以正常工作。但是我怎样才能从数据库中检索群聊历史呢??

例如,如果我有一个"strophe"组。当新用户加入strophe组时,应该显示其他用户在该组中完成的聊天记录。

我正在使用这个代码

var pres = $pres({ to:  room + "/" + nickname, from: connection.jid });
connection.send( msg.c('x', {xmlns: NS_MUC}));
if(chat_history != null){
    var msg_history = msg.c('x', { "xmlns": "http://jabber.org/protocol/muc"}).c("history", chat_history, {maxstanzas: 50});
    debugger;   
    console.log(msg_history);           
}

在我的控制台上它看起来像

h.Builder {nodeTree: presence, node: x}

我卡住了如何获取群聊的历史记录。请帮助

通常,除非聊天室已配置为不发送任何历史记录,否则发送加入状态应该足以让您接收最新的聊天室消息。请注意,旧消息上有延迟标签,以提供原始消息发送的时间,因此请确保您的客户端没有丢弃这些消息。

如果你想控制历史记录的大小,你可以使用Strophe MUC插件加入房间,并将最大节和时间限制作为history_attrs变量发送。您的服务器和房间也必须配置为提供历史记录。

conn.muc.join(room, nick, msg_handler_cb, pres_handler_cb, roster_cb, password,{ maxstanzas: 10, seconds: 3600 });