How can i get all chat history up to a certain date using strophe archive pluggin?

2k views Asked by At

I, as usual search all over the internet looking for documentation on a given functionality using strophe or one of the plugins. In this case is this: https://github.com/strophe/strophejs-plugins/blob/master/archive/strophe.archive.js. It might be that the specification on RSM is a bit over my head, but basically, if using this pluggin, how does one get all messages between the user and another user over a period of time. I found this to be the only sample code available: https://groups.google.com/forum/#!searchin/strophe/RSM/strophe/BjHUyxb-sYI/Ow-7ELNxNQoJ

And on a side note, due the lack of current development and strong documentation on strophe, plugins and what not, is this something almost nobody uses anymore?

1

There are 1 answers

0
Ernesto On BEST ANSWER

Here: After tweaking the piece of code I linked I managed to get it working, sort of. I did not want (at the moment) to limit the result set but the second parameter and the rsm vars are for that. Also, once you get the collections, there is a callback, you can iterate the collections and get the messages. Somecallback should process the messages. Strophe RSM pluggins is needed here and I think internally by the archive plugin.

connection.archive.listCollections(fullJID, null, fromDate, function (collections, responseRsm) {
//Loop the collections
for (var int = 0; int < collections.length; int++) {
    var lastCollection = collections[int]; 
    rsm = new Strophe.RSM({}); 
    lastCollection.retrieveMessages(rsm, function (messages, responseRsm) {
        someCallback(fullJID, messages);
    });
}

});

Notice the original plugin doesn't have the fromDate parameter. I needed it to add it to the list element so it would only retrieve from that date.

listCollections: function(jid, rsm, fromDate, callback) {
var xml = $iq({type: 'get', id: this._connection.getUniqueId('list')}).c('list', {xmlns:Strophe.NS.ARCHIVE, 'with': jid, 'from':fromDate});