0

I am creating an simple one to one chat app, I've done with the message send and receive. Now I am trying to show the status of the user to another(contacts) like "online/offline" etc. For that I have to use Presence and Roster.But I don't know where and how to use that, I mean the complete flow of subscription request and accept and after the subscription, the status of the users i.e. Online/Offline etc.

Nirmal Prajapat
  • 1,735
  • 1
  • 12
  • 23

1 Answers1

1

First of all you need to send and accept contact request

From Open-fire you can also do it from back-end

Steps : First click on Users/Groups >> click on "UserName" >> click on roster >> add roster

Here i attach screen of steps

  • click on add new item

click on add new item

  • add roster add roster

  • edit roster and select subscription both edit roster and select subscription both

then after you will get roster list using this code

ArrayList<RosterEntry> rosterLists = new ArrayList<>();

 public List<RosterEntry> getFriendsList() throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException {
    rosterLists = new ArrayList<>();
    roster = Roster.getInstanceFor(Config.conn1);//connection object of AbstractXMPPConnection
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
        Log.e("Roster :", "Reload and wait");
    }

    Collection<RosterEntry> entries = roster.getEntries();
    Log.e("Size of Roster :", entries.size() + "");

    for (RosterEntry entry : entries) {
        rosterLists.add(entry);
        Log.d("Buddies", "Here: " + entry.toString());
        Log.d("Buddies", "User: " + entry.getUser());//get userinfo
        Log.d("Buddies", "User Name:" + entry.getName());//get username
        Log.d("Buddies", "User Status: " + entry.getStatus());//get status of user
    }
    listAdapter = new FriendUserListAdapter(UserListActivity.this, rosterLists);
    user_list.setAdapter(listAdapter);
    return rosterLists;
}

what is the difference between subscription type both and from??? When any user add bot has his/her contact, then in the end of whole process, subscription status of ofRoster(openfire) table is set to ‘from’. The desired result of this process is ‘both’

Community
  • 1
  • 1
Adil
  • 812
  • 1
  • 9
  • 29
  • I have created two users in Openfire ,and as I tried users to add in roster, I can see the roster list in openfire for both users. but there's one confusion that subscription type is from in my case. Both user subscribed programmatically. So what is the difference between subscription type both and from??? – Nirmal Prajapat Feb 06 '18 at 09:56
  • When any user add bot has his/her contact, then in the end of whole process, subscription status of ofRoster(openfire) table is set to ‘from’. The desired result of this process is ‘both’. – Adil Feb 06 '18 at 10:31
  • refer this -https://www.igniterealtime.org/projects/openfire/plugins/subscription/readme.html – Adil Feb 06 '18 at 10:32
  • hope my ans will helpfull can you please do upvote and right tick? – Adil Feb 06 '18 at 10:35
  • where you want to get roster list it will return in list of users – Adil Feb 06 '18 at 11:00
  • ok, and how to find which user is online/offline etc.. . . I know for that I hv to use presence, but how – Nirmal Prajapat Feb 06 '18 at 11:03
  • please edit your question i will post that ans, thank you – Adil Feb 06 '18 at 11:04
  • refer this ans -https://stackoverflow.com/questions/34367920/how-to-set-and-get-presence-in-xmpp-android – Adil Feb 06 '18 at 11:06
  • ok adil, I just did up vote to your answer, let me try this once only then I'll check this answer right. Hope u get me.thnku – Nirmal Prajapat Feb 06 '18 at 11:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/164607/discussion-between-adilhusen-and-nirmal-prajapat). – Adil Feb 06 '18 at 11:11