javascript - ejabberd MAM doesn't work with Strophe js -


i trying show conversation between 2 users after users logout , login. mean when user1 logged out , again logged in, should see conversations made user2. using ejabberd xmpp server , strophe js retrive messages.

as found strophe.mam.js plugin raising error , cant messages.

here code:

function onconnect(status)     {         // functions runs while users trys login xmpp server         var iq = null;          switch (status)         {             case strophe.status.connecting:                 log('connecting.');                 break;             case strophe.status.connfail:                 log('failed connect.');                 $('#connect').get(0).value = 'connect';                 break;             case strophe.status.disconnecting:                 log('disconnecting.');                 break;             case strophe.status.disconnected:                 log('disconnected.');                 $('#connect').get(0).value = 'connect';                 break;             case strophe.status.connected:                 log('connected.');                 connection.addhandler(onmessage, null, 'message', null, null,  null);                 connection.addhandler(onpresence, null, 'presence', null, null, null);                  iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});                 connection.sendiq(iq, onroster);                  break;             default:                 break;         }     }  function onmessage(msg) {     debugger;     var fromjid = msg.getattribute("from"),         barefromjid = strophe.getbarejidfromjid(fromjid),         type = msg.getattribute("type"),         elems = msg.getelementsbytagname("body");      if (type == "chat" && elems.length > 0) {         var body = elems[0],             message = strophe.gettext(body);          showmessage(barefromjid + ": " + message);               connection.mam.query("yashwanth@localhost", {   "with": barefromjid,   onmessage: function(message) {             console.log("message " + barefromjid,                 ": " + message);             return true;   },   oncomplete: function(response) {             console.log("got messages");   }     });     }      return true; }  function send() {     // handles sending message     var = $('#to-jid').get(0).value,         mybarejid = strophe.getbarejidfromjid(connection.jid);         message = $('#message').get(0).value,         reply = $msg({to: to, type: 'chat'})             .c("body")             .t(message);      connection.send(reply.tree());     showmessage(mybarejid + ": " + message); }  $(document).ready(function () {     connection = new strophe.connection(bosh_service);     messagebox = $("#messages");     messagebox.val("");     logbox = $("#log-messages");     logbox.val("");     rosterbox = $("#roster");     rosterbox.val("");     connection.rawinput = function (data) { log('recv: ' + data); };     connection.rawoutput = function (data) { log('send: ' + data); };      strophe.log = function (level, msg) { log('log: ' + msg); };      login();     $('#send').bind('click', send); }); 

so whenever user receives message there in console. returns me error in logs

recv: <body xmlns='http://jabber.org/protocol/httpbind'><iq xmlns='jabber:client'  from='yashwanth@localhost' to='yashwanth@localhost/22064184271436881211352579'  id='yashwanth@localhost' type='error'><query xmlns='urn:xmpp:mam:0'><x xmlns='jabber:x:data'><field  var='form_type'><value>urn:xmpp:mam:0</value></field><field var='with'> <value>shabda@localhost</value></field></x><set xmlns='http://jabber.org/protocol/rsm'/></query> <error code='400' type='modify'><bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error> </iq></body> 

please me out this

your mam query not correctly formatted.

you missing attribute type="submit" on x element xmlns jabber:x:data feature. type mandatory in xep-0004 data forms

you iq should be:

<iq type='set' id='juliet1'>   <query xmlns='urn:xmpp:mam:0'>     <x xmlns='jabber:x:data' type='submit'>       <field var='form_type' type='hidden'>         <value>urn:xmpp:mam:0</value>       </field>       <field var='with'>         <value>shabda@localhost</value>       </field>     </x>     <set xmlns='http://jabber.org/protocol/rsm'/>   </query> </iq> 

see example 6 in xep-0313 message archive management.

the mam strophe plugin had bug. prepared fix here: https://github.com/processone/strophejs-plugins/commit/5a7857e2ab625c0521c68719d7e220f00c32c593

and submitted pull request: https://github.com/strophe/strophejs-plugins/pull/65


Comments