我正在研究离子框架,我正在使用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);
}但是这样做,消息不会存储在服务器上的Archive表中。这将造成从服务器获取历史记录的问题。如果我们使用简单的代码,那么将消息存储在服务器上的Archive表中。简单的代码如下。
this.client.sendMessage({
to: this.recep,
body: this.sMsg
});在简单的代码中,我们只能将消息作为字符串发送到正文中。有人能帮我解决这个问题吗?
发布于 2018-02-07 04:46:04
我的服务器只存档包含文本的body元素的消息,这是一种非常常见的归档配置。其中一个技巧是尝试包含一个虚拟正文来触发消息归档,但是您必须检查服务器是在存储和返回完整的节,还是只是提取和保存正文文本。
使用扩展节以包括附加字段来正确地完成所有事情,但是需要调整服务器以得到我想要的。从这里确认。
发布于 2018-03-05 12:34:21
您需要在message中添加一个额外的param 存储,这使得消息默认存储在存档表中。
const store = stanzas.define({
name: 'store',
element: 'store',
namespace: 'urn:xmpp:hints'
});
stanzas.withMessage(Message => {
stanzas.extend(Message, store);
});在消息节中发送存储属性为true
this.client.sendMessage({
to: this.recep,
body: this.sMsg,
store: true
});您应该看到将存储在消息节中,如
<store xmlns='urn:xmpp:hints'/>https://stackoverflow.com/questions/48621132
复制相似问题