Permalink
Browse files

Support for MAM_2

  • Loading branch information...
Philip Roberts
Philip Roberts committed Mar 14, 2017
1 parent e318dc1 commit a02603da6a463203b553a3a4b007b27631ed6dc8
Showing with 5 additions and 22 deletions.
  1. +5 −22 lib/plugins/mam.js
View
@@ -28,7 +28,7 @@ function timeoutPromise(targetPromise, queryid, delay) {
module.exports = function (client) {
client.disco.addFeature('urn:xmpp:mam:0');
client.disco.addFeature('urn:xmpp:mam:2');
client.getHistorySearchForm = function (jid, cb) {
return client.sendIq({
@@ -64,7 +64,7 @@ module.exports = function (client) {
val = val.toISOString();
}
if (name === 'FORM_TYPE') {
val = 'urn:xmpp:mam:0';
val = 'urn:xmpp:mam:2';
}
var existing = false;
@@ -103,38 +103,23 @@ module.exports = function (client) {
results.push(msg.mamItem);
});
var collectResults = new Promise(function (resolve) {
self.once('mam:result:' + queryid, 'session', function (msg) {
if (!allowed[msg.from.full]) {
return;
}
msg.mamResult.items = results;
resolve(msg);
});
});
var mamQuery = this.sendIq({
type: 'set',
to: to,
id: queryid,
mam: opts
});
timeoutPromise(Promise.all([
mamQuery,
collectResults
]), queryid, (self.config.timeout * 1000) || 15000).then(function (results) {
var mamRes = results[1];
return timeoutPromise(mamQuery, queryid, (self.config.timeout * 1000) || 15000).then(function (mamRes) {
mamRes.mamResult.items = results;
self.off('mam:item:' + queryid);
self.off('mam:result:' + queryid);
if (cb) {
cb(null, mamRes);
}
return mamRes;
}, function (err) {
self.off('mam:item:' + queryid);
self.off('mam:result:' + queryid);
if (cb) {
cb(err);
} else {
@@ -159,10 +144,8 @@ module.exports = function (client) {
client.on('message', function (msg) {
if (msg.mamItem) {
client.emit('mam:item', msg);
client.emit('mam:item:' + msg.mamItem.queryid, msg);
}
if (msg.mamResult) {
client.emit('mam:result:' + msg.mamResult.queryid, msg);
}
});
};

1 comment on commit a02603d

@itsazzad

This comment has been minimized.

Show comment
Hide comment
@itsazzad

itsazzad Dec 21, 2017

@latentflip @legastero
I am geting service-unavailable error with the mam:2

  • outgoing
<iq xmlns="jabber:client" type="set" id="...">
   <query xmlns="urn:xmpp:mam:2" queryid="...">
      <set xmlns="http://jabber.org/protocol/rsm">
         <max>10</max>
         <before>...</before>
      </set>
      <x xmlns="jabber:x:data" type="submit">
         <field var="FORM_TYPE">
            <value>urn:xmpp:mam:2</value>
         </field>
         <field var="with">
            <value>...@...</value>
         </field>
      </x>
   </query>
</iq>
  • incoming
<iq xmlns="jabber:client" from="...@..." to="...@.../..." type="error" xml:lang="en" id="...">
   <query xmlns="urn:xmpp:mam:2" queryid="...">
      <set xmlns="http://jabber.org/protocol/rsm">
         <max>10</max>
         <before>...</before>
      </set>
      <x xmlns="jabber:x:data" type="submit">
         <field var="FORM_TYPE">
            <value>urn:xmpp:mam:2</value>
         </field>
         <field var="with">
            <value>...@...</value>
         </field>
      </x>
   </query>
   <error code="503" type="cancel">
      <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
   </error>
</iq>
  • But it was working with mam:0 like below:
<iq xmlns="jabber:client" type="set" id="...">
   <query xmlns="urn:xmpp:mam:0" queryid="...">
      <set xmlns="http://jabber.org/protocol/rsm">
         <max>10</max>
         <before>...</before>
      </set>
      <x xmlns="jabber:x:data" type="submit">
         <field var="FORM_TYPE">
            <value>urn:xmpp:mam:0</value>
         </field>
         <field var="with">
            <value>...@...</value>
         </field>
      </x>
   </query>
</iq>

itsazzad commented on a02603d Dec 21, 2017

@latentflip @legastero
I am geting service-unavailable error with the mam:2

  • outgoing
<iq xmlns="jabber:client" type="set" id="...">
   <query xmlns="urn:xmpp:mam:2" queryid="...">
      <set xmlns="http://jabber.org/protocol/rsm">
         <max>10</max>
         <before>...</before>
      </set>
      <x xmlns="jabber:x:data" type="submit">
         <field var="FORM_TYPE">
            <value>urn:xmpp:mam:2</value>
         </field>
         <field var="with">
            <value>...@...</value>
         </field>
      </x>
   </query>
</iq>
  • incoming
<iq xmlns="jabber:client" from="...@..." to="...@.../..." type="error" xml:lang="en" id="...">
   <query xmlns="urn:xmpp:mam:2" queryid="...">
      <set xmlns="http://jabber.org/protocol/rsm">
         <max>10</max>
         <before>...</before>
      </set>
      <x xmlns="jabber:x:data" type="submit">
         <field var="FORM_TYPE">
            <value>urn:xmpp:mam:2</value>
         </field>
         <field var="with">
            <value>...@...</value>
         </field>
      </x>
   </query>
   <error code="503" type="cancel">
      <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
   </error>
</iq>
  • But it was working with mam:0 like below:
<iq xmlns="jabber:client" type="set" id="...">
   <query xmlns="urn:xmpp:mam:0" queryid="...">
      <set xmlns="http://jabber.org/protocol/rsm">
         <max>10</max>
         <before>...</before>
      </set>
      <x xmlns="jabber:x:data" type="submit">
         <field var="FORM_TYPE">
            <value>urn:xmpp:mam:0</value>
         </field>
         <field var="with">
            <value>...@...</value>
         </field>
      </x>
   </query>
</iq>
Please sign in to comment.