使用stanza.io向服务器上的存档table中不存储消息的消息添加自定义属性

adding custom attribute to message not storing message in Archive table on server using stanza.io

我正在使用 ionic-framework 并且我正在使用 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);
  }

但这样做的消息不会存储在服务器上的存档 table 中。这将产生从服务器获取历史记录的问题。如果我们使用简单的代码,那么消息将存储在服务器上的存档 table 中。简单代码如下..

this.client.sendMessage({
      to: this.recep,
      body: this.sMsg    
    });

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

我的服务器仅归档包含带文本的正文元素的邮件,这是一种非常常见的归档配置。一个技巧是尝试包含一个虚拟正文文本以触发消息存档,但您必须检查服务器是否正在存储和返回完整的节,或者只是提取并保存正文文本。

通过扩展 Stanza 以包含其他字段,正确地完成了所有操作,但需要调整服务器以获得我想要的内容。从 here.

确认

您需要在消息节中添加一个额外的参数store,使消息默认存储在存档table中。

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 inside message stanza like

<store xmlns='urn:xmpp:hints'/>