使用 strophe.js 检索群聊历史记录
Retrieve groupchat history using strophe.js
我在 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);
}
在我的控制台中它看起来像
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 });
我在 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);
}
在我的控制台中它看起来像
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 });