gpt4 book ai didi

javascript - Strophe MAM 如何显示消息?

转载 作者:行者123 更新时间:2023-11-30 08:35:04 26 4
gpt4 key购买 nike

我已经设法使用 Strophe MAM 将存档的消息放入 RAWInput,并显示最后一条消息(但仅显示最后一条)。我如何显示来自 RAWInput 的所有消息?但不仅仅是最后一个?

我如何提取消息的发件人?

我已将消息限制为最后 5 条。

connection.mam.query("test3@macbook-pro.local", {
"with": "test4@macbook-pro.local","before": '',"max":"5",
onMessage: function(message) {


console.log( $(message).text());




},
onComplete: function(response) {
console.log("Got all the messages");

}
});

最佳答案

您可以使用`strophe.mam.js 获取所有消息插件

这是我的工作代码:

// Retrives the messages between two particular users.

var archive = [];

var q = {
onMessage: 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);
}
}
}
return true;
},
onComplete: function(response) {
console.log('xmpp.history.end',{query:q, response:response});
}
};

$(document).ready(function)(){
archive = $("#archive-messages");
archive.val("");
$("#to-jid").change(function() {
$("#archive-messages").val("");
var to = {"with": $(this).val()};
$.extend(q, to, before, max);
// It takes around 800ms to auto login. So after this timeout we have to retrieve the messages of particular User.
setTimeout(function(){
connection.mam.query(Strophe.getBareJidFromJid(connection.jid), q);
}, 1000);
});
});

关于javascript - Strophe MAM 如何显示消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32242088/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com