Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should fountain existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before embark talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any limitations here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to liquidate other users. But only dialog’s creator(possessor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s plain talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To entirely liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Beginning from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "acquaintance" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Beginning from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should geyser existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any confinements here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to liquidate other users. But only dialog’s creator(possessor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To downright liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Embarking from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "mate" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Beginning from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should flow existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any confinements here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to liquidate other users. But only dialog’s creator(possessor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To entirely eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Kicking off from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "acquaintance" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Beginning from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Embarked with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets showcase how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To begin use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should stream existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any limitations here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to liquidate other users. But only dialog’s creator(holder) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To entirely eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Embarking from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Embarking from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Elementary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets showcase how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To begin use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should flow existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any limitations here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(proprietor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s ordinary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To entirely liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "mate" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Kicking off from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Embarked with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should fountain existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any limitations here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(holder) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To totally liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Embarking from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Beginning from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Elementary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To begin use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should stream existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any limitations here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to liquidate other users. But only dialog’s creator(holder) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s plain talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To fully liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Kicking off from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Commencing from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Devices
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should explosion existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before embark talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any confinements here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets display how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to liquidate other users. But only dialog’s creator(proprietor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To fully eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Kicking off from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Beginning from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should flow existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any limitations here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to eliminate other users. But only dialog’s creator(possessor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s ordinary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To downright liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "friend" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Beginning from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets showcase how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To begin use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should blast existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any confinements here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(holder) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To totally liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "mate" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Commencing from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Embarked with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should flow existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before embark talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any limitations here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to eliminate other users. But only dialog’s creator(proprietor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s ordinary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To downright eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "acquaintance" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Kicking off from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Embarked with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should geyser existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before embark talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any confinements here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to liquidate other users. But only dialog’s creator(holder) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s ordinary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To totally eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "friend" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Commencing from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Embarked with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To begin use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should stream existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to eliminate other users. But only dialog’s creator(holder) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To downright eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Beginning from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "mate" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Embarking from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Instruments
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets showcase how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should explosion existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any confinements here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets display how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to liquidate other users. But only dialog’s creator(proprietor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To totally liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "friend" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Beginning from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Instruments
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should blast existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any limitations here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to liquidate other users. But only dialog’s creator(possessor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s plain talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To entirely eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Kicking off from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Devices
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should flow existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(possessor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To downright liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Beginning from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should geyser existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before embark talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any limitations here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets display how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to eliminate other users. But only dialog’s creator(holder) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s ordinary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To totally liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "acquaintance" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Embarking from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Embarked with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should geyser existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(possessor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To fully liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Beginning from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Elementary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets showcase how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To begin use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should flow existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before embark talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to eliminate other users. But only dialog’s creator(possessor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To fully eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Beginning from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "friend" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Commencing from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should explosion existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any confinements here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(possessor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s ordinary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To fully eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Embarking from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "acquaintance" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Beginning from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Elementary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Instruments
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Embarked with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should flow existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any limitations here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(holder) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s plain talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To entirely liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "mate" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Embarking from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should flow existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before embark talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any limitations here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(proprietor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s plain talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To downright eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Embarking from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "friend" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Embarking from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets showcase how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should geyser existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any confinements here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets display how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(holder) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s plain talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To downright liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "friend" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Commencing from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Devices
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should explosion existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(possessor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To entirely eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Beginning from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Embarking from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Instruments
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should stream existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to liquidate other users. But only dialog’s creator(possessor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s ordinary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To fully liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Beginning from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "acquaintance" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Beginning from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Elementary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets showcase how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should blast existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets display how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to liquidate other users. But only dialog’s creator(holder) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s ordinary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To fully eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "mate" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Kicking off from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Plain code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Instruments
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets display how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should blast existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, pic, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets display how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to liquidate other users. But only dialog’s creator(possessor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To totally liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Kicking off from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Beginning from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Elementary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To begin use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should fountain existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets demonstrate how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to eliminate other users. But only dialog’s creator(proprietor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s plain talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To fully liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "acquaintance" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Kicking off from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Contraptions
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To begin use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should stream existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to eliminate other users. But only dialog’s creator(holder) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s plain talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To downright liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will liquidate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Beginning from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "friend" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Kicking off from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should explosion existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any limitations here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets display how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to liquidate other users. But only dialog’s creator(holder) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s plain talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To downright liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Kicking off from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B emerge in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-built status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Commencing from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Elementary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Devices
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets showcase how to upload a file to Content module and set it as a photo of a dialog:
Set custom-made parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should explosion existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Trio.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before commence talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets display how to upload a file to Content module and send it as an fasten:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(proprietor) can liquidate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s ordinary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To entirely eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic thrust notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Kicking off from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Embarking from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Devices
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Embarked with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To begin use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should stream existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just link it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, photo, audio file or movie file. We don’t have any limitations here – you can link any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-made Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-built parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(proprietor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To fully liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive thrust notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Trio.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "mate" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To liquidate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Embarking from SDK version Trio.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Elementary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Instruments
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Began with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To embark use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-built parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for utter talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should explosion existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Three.Three.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before embark talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any confinements here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-made parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (eliminate yourself) or to eliminate other users. But only dialog’s creator(holder) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will liquidate this dialog for current user, but other users still will be able to talk there. To entirely liquidate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Thrust notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic shove notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "friend" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Liquidate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an act
- permit – can be true/false.
Kicking off from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.
Ordinary code sample for Android XMPP Talk (via QuickBlox SDK API)
Quickblox Docs
Enterprise
Implements
- Home
- Documentation
- Pricing
- Enterprise
- Contact
Sources
This sample demonstrates how to work with QuickBlox Talk API.
It permits you to organise the group talk & talk one on 1
- Organize talk inbetween two users
- Organize group talk
Setup
Android Studio IDE
Doesn’t require extra configuration. Gradle does it for you.
Guide: Getting Commenced with Talk API
Getting a QuickBlox account
Creating applications in the Admin panel
In addition, there is this helpful five minute guide.
Prepare Talk service
To initialise talk service use:
To configure talk socket use QBChatService.ConfigurationBuilder;
Login to Talk
Note: In order to login to the talk please read the information about Talk login/password formation.
In order to use QuickBlox Talk APIs you must:
- Create session & Sign In to QuickBlox OR just create session with user
- Sign In to QuickBlox Talk
Please go after the lines below:
Create session with User & Sign In to QuickBlox Talk
To treat different connection states use ConnectionListener:
Talk in background mode
Android provides ‘true’ background mode but the better way to treat correctly talk offline messages is to do ‘Talk logout’ when app goes to background and does ‘Talk login’ when app goes to foreground.
Logout from Talk
Next code does talk logout:
Reconnection
By default Android SDK reconnects automatically when connection to server is lost.
But there is a way to disable this and then manage this by hand:
Dialogs
Creating dialogs
Creating dialogs example:
To notify occupants you’ve created talk dialog you can use QBSystemMessagesManager :
Create a Public group talk dialog
It’s also possible to create a public group talk, so any user from you application can join it. There is no a list with occupants, this talk is just open for everybody.
To create a public group talk use the same logic as for group talk, but switch the gialog’s type to QBDialogType.PUBLIC_GROUP and don’t pass the occupantsIds value.
Set dialog’s avatar
The Talk dialog contains a field photo. It’s a string field, can contain any value:
- An ID of a file in Content module: Android example
- An ID of a file in Custom-made Objects module: Android example
- Can be an url to any file in Internet
You can set avatar for dialog with type = 1 (PUBLIC_GROUP) or Two (GROUP).
For example, we use Content module to store the dialog’s photo. Next snippets demonstrate how to upload a file to Content module and set it as a photo of a dialog:
Set custom-built parameters
Dialogs can store extra parameters. These parameters can be used to store an extra data. Also these parameters can be used in dialogs retrieval requests.
To commence use extra parameters it needs to create an extra schema of your parameters. This is a CustomObjects class. Just create an empty class with all needed fields. These fields will be your dialog extra parameters.
When you create a dialog then set a dialog’s field customData:
It’s also possible to use custom-made parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
Retrieve dialogs
Filters
There are some filters to get only talk dialogs you need, not just all.
You can apply filters for the following fields:
- _id (string)
- type (integer)
- name (string)
- last_message_date_sent (integer)
- created_at (date)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get dialogs’ request above:
Also possible to use custom-built parameters in a dialogs retrieval requests so dialogs can be filtered through custom-made parameters:
You can request single dialog using code:
Talking in dialog
QBChatDialog model
QBChatDialog model is responsible for total talking functionality : sending/receiving messages, typing statuses etc.
To use QBChatDialog you should fountain existed dialogs from server or create a fresh one on server.
QBChatDialog is initialized with active talk connection when it is created on server or loaded.
So, if you not logged into talk service you can’t send and receive messages via QBChatDialog.
In order to talking you should make login before using QBChatDialog.
If you make logout at some point in application your QBChatDialog detaches from talk service and lose connection.
If you save QBChatDialog model and make re-login to talk, you can still use QBChatDialog without reloading. In this case just initialize QBChatDialog with active talk service:
Passing QBChatDialog inwards app
Staring from sdk Trio.Trio.0 QBChatDialog can be passed inbetween Activities or Fragments components via Intents.
To make received dialog able to talking after receiving just fasten it to active talk service :
Receiving incoming messages
In SDK version Three.0 was inroduced QBIncomingMessagesManager to listen for all incoming messages from all dialogs. Pay attention, messages from group talk dialogs will be received in QBIncomingMessagesManager only after joining to this group talk dialog.
For using QBIncomingMessagesManager just retrieve it from QBChatService after login in talk:
To listen for messages from any talk dialogs just register QBChatDialogMessageListener:
Talk in private dialog
To send a message in 1-1 talk use the QBChatDialog example:
If you receive message from participant from Dialog, you haven’t had before, you can construct Dialog for talking by dialogId.
Talk in group dialog
Before begin talking in a group dialog you should join this dialog.
You can set autojoin settings in QBChatService to automatically join loaded or created on server dialogs:. In that way you don’t need to join talk dialog by hand in code.
After join you can send and receive messages:
Get online users
You can request online users in group talk dialog without joining talk:
Method chatDialog.getOnlineUsers is deprecated.
And you also can treat online users in real time:
Leave group talk dialog
Send and receive a message with attachment
Send attachment
It’s possible to add attachments to message: for example, picture, audio file or movie file. We don’t have any limitations here – you can fasten any type of file.
To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:
- A file in Content module: Android example
- A file in Custom-built Objects module: Android example
- Can be an url to any file in Internet
To send a message with attachment you have to upload a file to Content module, Custom-built Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.
For example, we use Content module to store attachments. Next snippets showcase how to upload a file to Content module and send it as an link:
Receive attachment
For example we use Content module to store attachments. Next snippets permit to receive a message with an attachment and download it:
Use custom-built parameters in a message
You can use custom-made parameters for the messages you send in the talk, for example to send some extra info or to send control messages:
Unread messages count
You can request total unread messages count or unread count for particular dialog:
Update group dialog
User can update group talk dialog name, add fresh occupants or leave this group talk. Use QBDialogRequestBuilder to add more occupants or to leave group talk (liquidate yourself) or to eliminate other users. But only dialog’s creator(proprietor) can eliminate any users from occupants_ids. Refer to http://quickblox.com/developers/Talk#Update_dialog
To notify all occupants that you updated a group talk we use talk notifications – it’s elementary talk message with extra parameters inwards. These parameters used to separate talk notifications from regular text talk messages:
Delete dialogs
To delete a dialog use next snippet:
This request will eliminate this dialog for current user, but other users still will be able to talk there. To totally eliminate a dialog use parameter forceDelete. Refer to http://quickblox.com/developers/Talk#Delete_dialog
To delete many dialogs use next :
Talk history
You can choose a way to save talk message to history or not. If you determined to store – you should call method setSaveToHistory( true ):
List talk messages
If you determined to use chatMessage.setSaveToHistory(true) parameter – all talk messages will be stored to history and user can request a talk history for particular dialog.
Create/send talk message via REST request
It’s also possible to create/send talk message via REST request:
Retrieve list of messages
To get a talk history for particular dialog use next request:
Filters
There are some filters to get only talk messages you need, not just all.
You can apply filters for the following fields:
- _id (string)
- message (string)
- date_sent (timestamp)
- sender_id (integer)
- recipient_id (integer)
- attachments.type (string)
- updated_at (date)
You can apply sort for the following fields:
To use filters, you should build a QBRequestGetBuilder request and pass it to ‘get messages’ request above:
Update talk messages
To update talk messages use QBMessageUpdateBuilder like in next snippet:
Mark messages as read
You can mark many messages as read on server using snippet:
It’s possible to mark all messages as read – just don’t pass messagesIDs.
Delete talk messages
To delete talk messages use next snippets:
This request will eliminate talk messages for current user, but other users still will be able to request them.
Shove notifications to the offline users
QuickBlox provides a way to setup automatic shove notifications for the offline users. It means if your opponent is offline while you sending a message – he will automatically receive shove notification.
Read how to setup automatic thrust notifications in Admin panel in Alerts section.
Dashboard
QuickBlox dashboard provide a way to view and manage all dialogs for your application. Go to admin panel, Talk module. Read more info here.
Talk BOSH integration
Commencing from Android SDK Three.Two you can use BOSH protocol in talk.
For using talk functions over BOSH protocol in QuickBlox Android SDK you need :
- Add dependency on quickblox-android-sdk-chat-extensions module to the buil.gradle file of your project
That’s all, now QBChatService will use BOSH type connection.
BOSH configuration supports also connection over proxy. To set your proxy settings for BOSH connection use:
Note: By using BOSH protocol all talk requests are executed synchronously. To increase app’s spectacle you can use asynchronous methods for standard talk features to run requests on non-main thread. QuickBlox Android SDK provides asynchronous implementation for next talk methods:
and other main methods.
Other Talk components
Contact list
Contact list mode
In traditional IM applications, the "pal" system is rather straightforward. User A sends a request to become "friends" with user B. User B accepts the friend request. And now user A and B show up in each other’s roster.
But, alternatively, you can use twitter like logic. User A sends a presence subscription request to user B. Think about this more like following on twitter. User A is requesting permission to receive presence information from user B (following their presence). User B can accept this request, but may not be interested in receiving presence info from user B. Again, this is more like twitter following, but with the addition of required permission.So when user B accepts the request, this *only* means that user A will receive presence from user B. It does *not* mean that user B will receive presence from user A. Again, twitter-style, user A is now "following" user B. In diagram form, presence is flowing like this:
Now, if B also wants to receive presence from user A, then user B must request this permission. And furthermore, user A must accept the request. Just because B has granted A permission to receive presence, doesn’t mean that B gets a free pass to receive presence from A.
By default this SDK provides ‘twitter like’ mode.
To enable Facebook like logic pass QBRoster.SubscriptionMode.mutual value when you are obtaining a roser:
Access to the Contact list
Main setup
To access contact list you have to obtain it and set all needed listeners:
QBRosterListener is a listener that is fired any time a roster is switched or the presence of a user in the roster is switched (user becomes online/offline)
QBSubscriptionListener is a listener that is fired on "subscribe" (add to contact list) request from any user.
Access contact list users
To get users from contact list:
QBRosterEntry describes a user entity in your contact list. To get user’s ID use getUserId() getter.
To request user’s status (online/offline):
Add/Eliminate users
To add users to the contact list just use the method below:
This user will receive the request to be added to the contact list
To confirm the request:
To reject the request:
To eliminate a previously added user from the contact list:
Last activity
It is often helpful to know the time of the last activity for user whether he is in your contact list or no. You can use methods below to detect when a disconnected user last accessed its server.
Custom-made status
A client MAY provide detailed status information to his contacts by constructing a presence object by himself:
In this case there is no need to use QBChatService.getInstance().startAutoSendPresence(60);, you have to manage it by yourself.
Privacy lists
Privacy list API permits to enable or disable communication with other users in a talk. Privacy list API also enables a user to create, modify, or delete his privacy lists, define a default list.
Retrieve privacy lists
User can have numerous privacy lists. To get a list of all your privacy lists’ use next request:
Create a privacy list or edit existing list
A privacy list must have at least one element in order to create it. If no elements are specified then the list with given name will be deleted. When you want to update a privacy list, it must include all of the desired items (i.e., not a "delta").
QBPrivacyListItem class takes three arguments:
- type – use USER_ID block a user in 1-1 talk or GROUP_USER_ID to block in a group talk.
- valueForType – ID of a user to apply an activity
- permit – can be true/false.
Embarking from SDK version Three.0 privacy list support mutual user blocking:
- mutualBlock – can be true/false. – to block user’s message in both directions.
Creating mutual blocking privacy item:
Pay attention, if you want to update or set fresh privacy list instead of current you should firstly decline current default and active lists:
Activate a privacy list
User can have numerous privacy lists, but default can be only one. In order to activate rules from a privacy list you must set it as default.