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

Yas*_*nth 1 javascript ejabberd strophe multiuserchat

我正在使用Strophe.js的ejabberd 15.06版本.从我的后端数据库中检索一对一聊天工作正常.但是如何从数据库中检索群聊历史?

例如,如果我有一个"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);           
}
Run Code Online (Sandbox Code Playgroud)

在我的控制台中看起来像

h.Builder {nodeTree: presence, node: x}
Run Code Online (Sandbox Code Playgroud)

我被困在如何获取群聊的历史.请帮忙

Mar*_*k S 5

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

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

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