使用Ejabbard 18.06和Shtrophe js进行聊天无法获取存档消息(聊天记录)

时间:2018-09-10 10:36:43

标签: ejabberd strophe

您好,我正在使用Ejabbard 18.06Shtrophe js进行聊天,我无法使用存档消息(“聊天记录”)存储到具有特定JIDs的数据库中。

这是我正在使用的以下代码。

  var iq = $iq({type: 'set', id: jid_id})
            .c('query', {xmlns:'urn:xmpp:mam:1'})
            .c('field',{'var':'with'})
            .c('value')
            .t(jid);
    Gab.connection.sendIQ(iq, function (message) {
           try {
                var id = message.querySelector('result').getAttribute('id');
                var fwd = message.querySelector('forwarded');
                var d = fwd.querySelector('delay').getAttribute('stamp');
                var msg = fwd.querySelector('message');
                var msg_data = {
                    id: id,
                    with:Strophe.getBareJidFromJid(msg.getAttribute('to')),
                    timestamp: (new Date(d)),
                    timestamp_orig: d,                                      
                     from:Strophe.getBareJidFromJid(msg.getAttribute('from')),
                    to: Strophe.getBareJidFromJid(msg.getAttribute('to')),
                    type: msg.getAttribute('type'),
                    body: msg.getAttribute('body'),                                   
    message:Strophe.getText(msg.getElementsByTagName('body')[0])
                };
          archive.val(archive.val() + msg_data.from + ":" + 
                           msg_data.message + "\n" + msg_data.to + ":" + msg_data.message + "\n");
                archive.scrollTop(archive[0].scrollHeight - archive.height());
                console.log('xmpp.history.message', msg_data.message);
            } catch (err) {
                if (typeof (err) == 'TypeError') {
                    try {
                        console.log(err.stack)
                    } catch (err2) {
                        console.log(err, err2);
                    }
                }
            }

         }); 

0 个答案:

没有答案