Conversations
Channelize.io server supports two types of conversation i.e private 1-to-1 and Group conversations. This section contains what all conversations related actions can be performed using Channelize.io Android API SDK functions.
List Conversations
Retrieve the list of conversations of a user.
* @param conversationQuery Query for filtering the results.
ConversationQuery conversationQuery = new ConversationQuery.Builder()
.setMemberId("USER_ID") // Represents the userID of a conversation member/participant. This param is used if you want to get the conversation between logged in user and targeted user.
.isGroup(true) // Set to true, if you want to retrieve only group conversations. Remove this to retrieve both types of conversations.
.includeDeletedConversations(true) // Represent if deleted conversations (Soft deleted) should be included in the response. (Default: false)
.includeActiveConversations(true) // Retrieves the conversations in which the user is active. (Default: true)
.setSorting(ConversationQuery.SORT_ASCENDING) // Represents sorting criteria.
.setInclude(ConversationQuery.MEMBERS_LIST) // Represents extra fields which you want to include in conversation list response.
.setSearchQuery(QUERY) // Searches for conversations whose display name or member name matches the specified value.
.setLimit(20) // Represents the number of conversations to retrieve in a single request.
.setOffset(0) // Represents the number of items to skip from the beginning. (Useful in pagination)
.build();
channelizeApi.getConversationsList(conversationQuery, new CompletionHandler<ListConversationResponse>() {
@Override
public void onComplete(ListConversationResponse result, ChannelizeError error) {
if (result != null) {
List<Conversation> conversationList = result.getConversation();
}
}
});
Get Conversations Count
Retrieves the count of conversations of a user.
* @param conversationQuery Query for filtering the results.
ConversationQuery conversationQuery = new ConversationQuery.Builder()
.isGroup(true) // Set to true, if you want to retrieve only group conversations. Remove this to retrieve both types of conversations.
.includeActiveConversations(true) // Retrieves the conversations in which the user is active. (Default: true)
.includeDeletedConversations(true) // Represent if deleted conversations (Soft deleted) should be included in the response. (Default: false)
.build();
channelizeApi.getConversationsCount(conversationQuery, new CompletionHandler<TotalCountResponse>() {
@Override
public void onComplete(TotalCountResponse result, ChannelizeError error) {
int count = result.getCount();
}
});
Get a 1-to-1 conversation
- Retrieves information about a 1-to-1 conversation for a particular user.
* @param USER_ID The unique ID of the receiver.
channelizeApi.getOneToOneConversation(USER_ID, new CompletionHandler<ListConversationResponse>() {
@Override
public void onComplete(ListConversationResponse result, ChannelizeError error) {
}
});
- Retrieves information about a 1-to-1 conversation with a specific conversation ID.
* @param CONVERSATION_ID The unique ID of the conversation to retrieve.
* @param conversationQuery Query for filtering the results.
ConversationQuery conversationQuery = new ConversationQuery.Builder()
.setInclude(ConversationQuery.MEMBERS_LIST) // Specifies extra fields if you want extra information to be appended with the conversation list (MembersList or Messages)
.build();
channelizeApi.getConversation(CONVERSATION_ID, conversationQuery, new CompletionHandler<Conversation>() {
@Override
public void onComplete(Conversation conversation, ChannelizeError error) {
}
});
Create a Conversation
Creates a new conversation.
* @param GROUP_TITLE (Required, String): The name of the conversation.
* @param MEMBER_IDS (Required, JSONArray): Specifies an array of user IDs to add to the conversation.
channelizeApi.createConversation("GROUP_TITLE", MEMBER_IDS, new CompletionHandler<Conversation>() {
@Override
public void onComplete(Conversation conversation, ChannelizeError error) {
}
});
Get Members
Retrieves a list of all members of a conversation.
* @param CONVERSATION_ID ConversationId for which Member list Needs to be fetched.
channelizeApi.getMembersList(CONVERSATION_ID, new CompletionHandler<ListMemberResponse>() {
@Override
public void onComplete(ListMemberResponse conversation, ChannelizeError error) {
}
});
Add Members
Adds a member to the conversation.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation.
* @param MEMBER_IDS (Required, JSONArray): Specifies an array of user IDs to add to the conversation.
channelizeApi.addMembers(CONVERSATION_ID, MEMBER_IDS, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse result, ChannelizeError error) {
}
});
Remove Members
Removes a member from the conversation.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation.
* @param MEMBER_IDS (Required, JSONArray): Specifies an array of user IDs to remove from the conversation.
channelizeApi.removeMembers(CONVERSATION_ID, MEMBER_IDS, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse result, ChannelizeError error) {
}
});
Add Admin
Grants group admin permission to a user. Only an existing member/participant of the group can be admin of the group conversation.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation.
* @param USER_ID (Required, String): The unique ID of the user who is going to be the new group conversation admin.
channelizeApi.addAdmin(CONVERSATION_ID, USER_ID, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse result, ChannelizeError error) {
}
});
Leave a Conversation
Leaves the targeted conversation for a user.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation which you want to leave.
channelizeApi.leaveConversation(CONVERSATION_ID, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse result, ChannelizeError error) {
}
});
Delete Conversation
Deletes a targeted conversation for a user. The conversation is deleted at logged-in user’s end but appears at other member’s end.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation which you want to delete.
channelizeApi.deleteConversation(CONVERSATION_ID, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse response, ChannelizeError error) {
}
});
Clear Conversation
Clears a targeted conversation for a user.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation which you want to clear.
channelizeApi.clearConversation(CONVERSATION_ID, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse response, ChannelizeError error) {
}
});
Mark Messages Read
Mark all messages Read in a targeted conversation for a user.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation in which all messages needs to be marked as read.
channelizeApi.markAllMessageRead(CONVERSATION_ID, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse response, ChannelizeError error) {
}
});
Mute a Conversation
Mutes a coversation for a user.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation.
channelizeApi.muteConversation(CONVERSATION_ID, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse response, ChannelizeError error) {
}
});
Unmute a Conversation
Unmute a coversation for a user.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation.
channelizeApi.unmuteConversation(CONVERSATION_ID, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse response, ChannelizeError error) {
}
});
Update Title
Updates the title of a group conversation and send a meta-message in the conversation.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation.
* @param TITLE (Required, String): Specifies the updated title for the conversation.
channelizeApi.updateConversationTitle(CONVERSATION_ID, TITLE, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse result, ChannelizeError error) {
}
});
Update Profile Photo
Updates the profile image of a group conversation and send a meta-message in the conversation.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation.
* @param FILE_PATH (Required, String): Specifies the file path.
channelizeApi.updateConversationProfilePhoto(CONVERSATION_ID, FILE_PATH, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse result, ChannelizeError error) {
}
});
Set Typing Status
Updates the typing status of a user for all active members in a conversation.
* @param CONVERSATION_MEMBERS (Required: Set<String>): Array of user Ids of the active members of a conversation..
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation.
* @param IS_TYPING (Required, boolean): Determines the typing status of a user. Set true, when a member starts typing. Set false, when a member stops typing.
channelizeApi.setTyping(CONVERSATION_MEMBERS, CONVERSATION_ID, IS_TYPING);