首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用stanza.io向未将消息存储在服务器上的存档表的邮件中添加自定义属性

使用stanza.io向未将消息存储在服务器上的存档表的邮件中添加自定义属性
EN

Stack Overflow用户
提问于 2018-02-05 11:02:57
回答 2查看 327关注 0票数 2

我正在研究离子框架,我正在使用stanza.io库来实现与xmpp服务器的聊天,我想在发送消息时添加一些自定义属性,因为我遵循了创建插件的步骤。我的代码如下..。

代码语言:javascript
复制
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表中。简单的代码如下。

代码语言:javascript
复制
this.client.sendMessage({
      to: this.recep,
      body: this.sMsg    
    });

在简单的代码中,我们只能将消息作为字符串发送到正文中。有人能帮我解决这个问题吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-02-07 04:46:04

我的服务器只存档包含文本的body元素的消息,这是一种非常常见的归档配置。其中一个技巧是尝试包含一个虚拟正文来触发消息归档,但是您必须检查服务器是在存储和返回完整的节,还是只是提取和保存正文文本。

使用扩展节以包括附加字段来正确地完成所有事情,但是需要调整服务器以得到我想要的。从这里确认。

票数 2
EN

Stack Overflow用户

发布于 2018-03-05 12:34:21

您需要在message中添加一个额外的param 存储,这使得消息默认存储在存档表中。

代码语言:javascript
复制
const store = stanzas.define({
  name: 'store',
  element: 'store',
  namespace: 'urn:xmpp:hints'
}); 

stanzas.withMessage(Message => {
  stanzas.extend(Message, store);
});

在消息节中发送存储属性为true

代码语言:javascript
复制
this.client.sendMessage({
  to: this.recep,
  body: this.sMsg,
  store: true
});

您应该看到存储在消息节中,如

代码语言:javascript
复制
<store xmlns='urn:xmpp:hints'/>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48621132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档