1

sorry to bother anyone,but i really need help for this,i want to retrieve chat from database(which i already ask this question before),but i try to googling and read all the documentation,and i assumed that i have found the solution,i read the converse.js documentation about developer api,in the Archiving group section,and i got this :

   require(['converse'], function (converse) {

converse.plugins.add('myplugin', {
    initialize: function () {

     this._converse.api.archive.query({'with': 'admin2@localhost'});

    }
});


        converse.initialize({

                jid: 'admin3@localhost',
                authentication: 'prebind',
                prebind_url: 'bind/bind.php',
                allow_logout: false,
                debug : true,
                whitelisted_plugins: ['converse-inverse','converese-mam','converse-singleton','converse-muc-embedded','myplugin'],
                archived_messages_page_size : 20,
                message_archiving : "always",
                auto_list_rooms: false, 
                show_chatstate_notifications:true,
                message_carbons : true,
                sounds_path : "sounds/",
                auto_reconnect : true,
                use_vcard : true,
                auto_subscribe: false,
                keepalive : true,
                show_send_button:true,
                archived_messages_page_size : 20,
                bosh_service_url: 'http://localhost:5280/http-bind', 
                hide_muc_server: false,
                play_sounds : true,
                show_controlbox_by_default: false,
                xhr_user_search: false

        });


    });

i try it,but i got this error :

Cannot read property 'getUniqueId' of undefined
    at Object._converse.queryForArchivedMessages (converse-mam.js:266)
    at Object.initialize (dev.html:30)
    at PluginSocket.initializePlugin (pluggable.js:196)
    at arrayEach (lodash.js:537)
    at Object.forEach (lodash.js:9359)
    at PluginSocket.initializePlugins (pluggable.js:227)
    at Object.initPlugins (converse-core.js:1854)
    at Object._converse.initialize (converse-core.js:1875)
    at Object.initialize (converse-core.js:2037)
    at dev.html:36

i am sorry if this question's kinda simple or stupid,but i really new in using converse.js,and i really like to use and learn more about converse.js in the future because it full features and documentation.

Prem
  • 15
  • 1
  • 10

1 Answers1

0

The initialize method of a Converse.js plugin gets called when Converse.js itself gets initialized.

This happens before the user has been logged in (regardless whether that happens automatically or manually).

So you're calling this._converse.api.archive.query({'with': 'admin2@localhost'}); before the user has been logged and an XMPP connection and session has been established.

Instead, you should first listen for the connection event, and then do your query.

converse.plugins.add('myplugin', {
    initialize: function () {
        var _converse = this._converse;

        _converse.on('connected', function () {
            _converse.api.archive.query({'with': 'admin2@localhost'});    
        });
    }
});
JC Brand
  • 2,652
  • 18
  • 18
  • thanks jc,i got problem with mam,and just found out that my xmpp server doesn't support urn:xmpp:mam:2,so it' can't retrieve backfrom database – Prem Oct 25 '17 at 03:31