我正在研究离子框架,我正在使用stanza.io库来实现与 xmpp 服务器的聊天,我想在发送消息时添加一些自定义属性,因为我已经按照创建插件的步骤进行操作。我的代码如下...
sendMsg() {
console.log("Sending message");
function customMessage(client, stanzas) {
const NS = 'http://www.w3.org/2005/Atom';
var types = stanzas.utils;
const messageAttribute = stanzas.define({
name: 'messageAttribute',
element: 'messageAttribute',
namespace: NS,
fields: {
title: types.textSub(NS, 'title'),
summary: types.textSub(NS, 'summary'),
published: types.textSub(NS, 'published'),
updated: types.textSub(NS, 'updated'),
cont: types.textSub(NS, 'cont')
}
});
stanzas.withMessage((Message) => {
stanzas.extend(Message, messageAttribute);
});
}
this.client.use(customMessage);
this.client.sendMessage({
to: this.recep,
body: "",
messageAttribute: {
'title': "some title",
'summary': "message",
'published': "time stamp here",
'updated': "time stamp here",
'cont': "cht"
}
});
console.log("Message sent " + this.sMsg);
}
但是这样做消息不会存储在服务器上的存档表中。这将产生从服务器获取历史记录的问题。如果我们使用简单的代码,那么消息将存储在服务器上的存档表中。简单的代码如下..
this.client.sendMessage({
to: this.recep,
body: this.sMsg
});
在简单的代码中,我们只能将消息作为正文中的字符串发送。谁能帮我解决这个问题?