Before you begin
- Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
- Configure QuickBlox SDK for your app. Check out Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See Authentication page to learn how to do it.
- Connect to the Chat server. See Connection page to learn how to do it.
Add listener
To use a contact list, you have to obtain it and set all needed listeners.QBRosterListener
.
Event | Description |
---|---|
entriesDeleted() | A contact list item is removed from the contact list. |
entriesAdded() | A new contact list item is added to the contact list. |
entriesUpdated() | A contact list item is updated. For example, a user’s name can be updated. |
presenceChanged() | A user presence is changed. Care should be taken when using the presence data delivered as part of this event. Specifically, when a user account is online with multiple devices, the UI should account for that. For example, say a user is online with their desktop computer and mobile phone. If the user logs out of the instant messaging client on their mobile phone, the user should not be shown in the contact list as offline since they’re still available on another device. |
You should call
chatService.getRoster()
only after successful connecting to Chat. To learn how to it, review this section.QBRosterListener
is a listener that is fired any time a contact list is changed or the presence of a user in the contact list is changed (for example, user becomes online/offline).QBSubscriptionListener
is a listener that is called subscriptionRequested
when the current user has been requested for adding to the Contact List from any user.Access contact list
The following function gives you access to all contact list items.QBRosterEntry
describes a user entity in your contact list. To get the Presence of a user, use getPresence(userID)
method. Then, you can get a user’s status.
Add user to your contact list
To add a user to the contact list, use the following snippet.subscriptionRequested
in QBSubscriptionListener
. This is a request to be added to the contact list.
Maximum number of contacts is 300.
Confirm the contact request
To confirm the request, usecontactsRoster.confirmSubscription()
method.
Reject the contact request
To reject the request, use thecontactsRoster.reject()
method.
Remove user from the contact list
To remove a previously added user from the contact list, use the following method.Contact list updates
The above-specifiedRosterListener
listener will give you all updates regarding contact list changes and users’ status updates.