您好,我正在使用Ejabbard 18.06
和Shtrophe 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);
}
}
}
});