Yograj Shinde
Yograj Shinde

Reputation: 839

Get List of all users from Openfire Server in Android

Hello i am developing a chat app in android using xmpp and open-fire for server,

currently i can create new user and login with that user.

i have searched a lot of on net and tried different solutions but nothing is worked.

at server all users are automatically get added to one default group. when new user get created.

but i am unable to get list of all users until i will add them to my roster.

my requirement is to show all user's list and allow user to add friend from them, how to get all users list those who are not my friend?

i have tried to get list of users from group, but still no success, i can only retrieve list of users those are my friends with following code.

Roster roster = xmppConnection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();

            for(RosterEntry entry1 : entries)
            {
                System.out.println("UserID:- " + entry1.getUser());
                System.out.println("Name:- " + entry1.getName());
                System.out.println("Status:- " + entry1.getStatus());
                System.out.println("type:- " + entry1.getType());   
            }

to retrieve user entry from group i used following code

    Roster roster = xmppConnection.getRoster();
    Collection<RosterGroup> groups = roster.getGroups();
    for(RosterGroup group: groups )
            {
                System.out.println("Group Name:- " + group.getName());
            Collection<RosterEntry> entries = roster.getEntries();

            for(RosterEntry entry1 : entries)
            {
                System.out.println("UserID:- " + entry1.getUser());
                System.out.println("Name:- " + entry1.getName());
                System.out.println("Status:- " + entry1.getStatus());
                System.out.println("type:- " + entry1.getType());   
            }   
        }

any help/solution or suggestion to get all users list is appreciated.

Thank you.

Upvotes: 1

Views: 3009

Answers (2)

Prashant Patil
Prashant Patil

Reputation: 187

following code is working for me :

UserSearchManager usm = new UserSearchManager(connection);

Form searchForm = usm.getSearchForm("search." + connection.getServiceName());
//Here i am searching for the service name

Form answerForm = searchForm.createAnswerForm();

UserSearch userSearch = new UserSearch();
answerForm.setAnswer("Username", true);

answerForm.setAnswer("search", "*");

ReportedData data = userSearch.sendSearchForm(connection, answerForm, "search." + connection.getServiceName());

if (data.getRows() != null) {
    System.out.println("not null");

    Iterator<ReportedData.Row> it = data.getRows();

    arryAllUsers.clear();

    while (it.hasNext()) {

        //System.out.println("row");

        ReportedData.Row row = it.next();

        Iterator iterator = row.getValues("jid");

        if (iterator.hasNext()) {

            String jid = iterator.next().toString(); //here i get all the user's of the open fire..
            // l.add(value);

        }

        // Log.i("Iteartor values......"," "+value);

    }
}

Upvotes: 3

vitalyster
vitalyster

Reputation: 5266

I can suggest the following:

  1. setup "shared roster" on the server, take a look at https://community.igniterealtime.org/docs/DOC-1619 - every user will have all server users in the roster.
  2. when user mark someone as "friend" - add that user to some group, e.g. "Friends". And display that group as user's roster.

Upvotes: 0

Related Questions