Can't get all BookMarkedRooms when using PrivateDataManager with (a)Smack. Always returns only the last bookmark

StackOverflow https://stackoverflow.com/questions/20117756

Question

I added 3-4 Persistent Conference rooms and try to get connect ever conference room at app start time but when i tried to get all bookmarked rooms it will just returns me one room. and that room is last time added.

 muc = new MultiMUC(connection, "g2@conference.msngr.com");
        try {   
    muc.create("g2");
    Form form = muc.getConfigurationForm();
    Form submitForm = form.createAnswerForm();                
    FormField ff = new FormField("muc#roomconfig_persistentroom");
          ff.setType(FormField.TYPE_BOOLEAN);
          ff.addValue("0");
          ff.setRequired(true);
          ff.setLabel("Make Room Persistent?");
          submitForm.setAnswer("muc#roomconfig_persistentroom", true);              
          List owners = new ArrayList();                  
          owners.add("userdev@msngr.com");  
          submitForm.setAnswer("muc#roomconfig_roomowners", owners);
          muc.sendConfigurationForm(submitForm);
             Bookmarks bookmarks = new Bookmarks();
             BookmarkedConferenceImpl conference = new BookmarkedConferenceImpl("g2@conference.msngr.com");
             conference.setName("My Favorite Room");
             conference.setAutoJoin(true);            
             bookmarks.addBookmarkedConference(conference);  

                 try
                 {

                 PrivateDataManager manager = new PrivateDataManager(connection,"userdev@msngr.com");
                 manager.setPrivateData(bookmarks);          
                 }
                 catch (Exception e) {  }

but when i am try to get all BookMarkedRoom it return one last added Coference room.

 BookmarkManager bm = BookmarkManager.getBookmarkManager(connection);
              Collection<BookmarkedConference> rooms=bm.getBookmarkedConferences() ; 
            for(BookmarkedConference room:rooms){                   
                    MultiUserChat  muc = new MultiMUC(connection, room.getJid());
                    muc.join(uid);              
                    muc.addMessageListener(listener);

                    }
Was it helpful?

Solution

It seems that you are always overwriting the Bookmarks PrivateData with the latest MUC that got created.

Instead of using the PrivateDataManager directly, use the specialized BookmarkManager for this job. BookmarkManager comes with three methods that should do the job for you conviniently

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top