【问题标题】:Retrieve groupchat history using strophe.js使用 strophe.js 检索群聊历史
【发布时间】:2015-10-25 13:12:51
【问题描述】:

我正在使用带有 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}

我不知道如何获取群聊的历史记录。请帮忙

【问题讨论】:

    标签: javascript ejabberd strophe multiuserchat


    【解决方案1】:

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

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

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

    【讨论】:

    • 通常情况下,即使您不发送 maxstanzas 参数,ejabberd 也会默认发送历史记录(默认 = 最后 10 条消息)。
    猜你喜欢
    • 2017-01-02
    • 2015-02-13
    • 2017-06-03
    • 2013-01-16
    • 2013-02-16
    • 2019-01-16
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多