Conversations
Channelize.io server supports two types of conversation i.e private 1-to-1 and Group conversations. This section contains what all 1-to-1 conversations related actions can be performed using Channelize.io iOS SDK functions.
List Conversations
Retrieve the list of conversations of a user using getChats
function of CHService
class. Pass ConversationFilters
object of QueryBuilder
class to filter the results.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
memberId | string | no | Restricts the search scope to only retrieve the target user's conversations. |
isGroup | boolean | no | Restricts the search scope to only retrieve private 1-to-1 or group conversations. If set to true, group conversations are returned. If set to false, private 1-to-1 conversations are returned in the response. |
includeDeleted | boolean | no | Determines whether to include deleted conversation in response. |
includeOnlyActive | string | no | Restricts the search scope to retrieve only conversations in which the user is active. |
sort | string | no | Specifies the sorting criteria for the returned results. Allowed values are updatedAt ASC and updatedAt DESC. |
include | string | no | Specifies extra fields if you want extra information to be appended with the conversation objects. Allowed values are membersList and messages. |
limit | int | no | Specifies the number of results to return. |
skip | int | no | Specifies the number of results you want to skip from the beginning. |
Request Example
let conversationQuery = QueryBuilder.instance.createConversationListFilter()
conversationQuery.includeDeleted = true
conversationQuery.includeOnlyActive = true
conversationQuery.inclued = "membersList"
conversationQuery.sorting = .ASC
conversationQuery.limit = 30
conversationQuery.offset = 0
conversationQuery.memberId = 20002
CHService.main.getChats(queryFilter: conversationQuery, completion: {(conversation,error) in
guard error == nil else{
return debugPrint(error.debugDescription)
}
})
Completion Handlers
conversations
Indicates the response which will be an array of conversation's object. If memberId is set, the response is conversation's object instead of an array.error
Indicates if there is an error. It will be null if there is no error.
Get Conversations Count
Retrieves the total number of conversations of a user using getRecentChatCount
method of CHService
class.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
isGroup | boolean | no | Determines whether to include group conversation count or private 1-to-1 conversation count. |
includeDeleted | boolean | no | Determines whether to include deleted conversation count. |
includeOnlyActive | boolean | no | Determines whether to include conversations count in which the user is active. |
Request Example
let convCountQueryBuilder = QueryBuilder.instance.createConversationsCountFilter()
convCountQueryBuilder.includedDeleted = true
convCountQueryBuilder.isGroup = true
convCountQueryBuilder.includeOnlyActive = true
CHService.main.getRecentChatCount(queryFilter: convCountQueryBuilder, completion: {(count,error) in
guard error == nil else{
return debugPrint(error.debugDescription)
}
})
Completion Handlers
count
Indicates response object having count as property.error
Indicates if there is an error. It will be null if there is no error.
Get a Conversation (Using Conversation Id)
Retrieves a conversation object using a conversation Id.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatID | string | yes | The unique ID of the targeted conversation. |
Request Example
/// ## Usage:
CHService.main.getConversationWithId(chatId:"20456",completion:{(conversation,error) in
guard error == nil else{
print("Error in Getting Conversation")
return
}
})
Completion Handlers
conversation
Indicates the response.error
Indicates if there is an error. It will be null if there is no error.
Get a Conversation (Using User Id)
Retrieves a conversation object using a User Id.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
recipientId | string | yes | The unique ID of the targeted user whose conversation to retrieve. |
Request Example
/// ## Usage:
CHService.main.getConversationWithRecipientId(recipientId:"20456",completion:{(conversation,error) in
guard error == nil else{
print("Error in Getting Conversation")
return
}
})
Completion Handlers
conversation
Indicates the response.error
Indicates if there is an error. It will be null if there is no error.
Create a Conversation
Creates a new group conversation.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
groupTitle | string | yes | The name of the conversation. |
profileImageData | data | no | The data of the conversation's profile image. |
memberIds | [string] | yes | Specifies an array of user IDs to add to the conversation. E.g. ["20236", "20697", "19116"] |
If your class confirms to CHConversationDataDelegate
then following delegate function will be called
func didGetChatInfo(conversation: CHConversation?) {
}
Request Example
/// ## Usage:
CHService.main.createGroup(groupTitle:"New Group 51",profileImageData:imageData,memberIds:["20456","20657"],completion:{(conversation,error) in
guard error == nil else {
print("Error in Creating New Group")
return
}
})
Completion Handlers
conversation
Indicates the response.error
Indicates if there is an error. It will be null if there is no error.
Get Members
Retrieve the list of members in a conversation.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatId | string | yes | Specifies the unique ID of the targeted conversation. |
Request Example
/// ## Usage:
CHService.main.getConversationMembers(chatId:"2004589",completion:{(users,error) in
guard error == nil else {
print("Error occured")
return
}
})
Completion Handlers
users
Indicates the response.error
Indicates if there is an error. It will be null if there is no error.
Add Members
Add a new member to the coversation.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatId | string | yes | Specifies the unique ID of the targeted conversation. |
userIds | [string] | yes | Specifies an array of user IDs to add to the conversation. E.g. ["20236", "20697", "19116"] |
To get real-time updates confirm your class to CHConversationDataDelegate
and implement delegate function.
func didGetChatInfo(conversation: CHConversation?) {
}
func didReceiveNewMessage(message: CHMessage?){
}
Request Example
/// ## Usage:
let chatId = "2004859"
let usersIds = ["20456","20152"]
CHService.main.addMembersToConversation(chatId:chatId,userIds:usersIds,completion:{(status,error) in
if status{
"Do your Stuff Here"
} else {
"Operation Failed"
}
})
Completion Handlers
status
Indicates the response of task completion.error
Indicates if there is an error. It will be null if there is no error.
Remove Members
Removes a member from the conversation.
Function Params
This table lists all possible parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatId | string | yes | The unique ID of the conversation. |
membersIds | [string] | yes | Specifies an array of user IDs to remove from the conversation. E.g. ["20236", "20697", "19116"] |
To get real-time updates confirm your class to CHConversationDataDelegate
and implement following delegate functions
func didGetChatInfo(conversation: CHConversation?) {
}
func didReceiveNewMessage(message: CHMessage?){
}
Request Example
/// ## Usage:
CHService.main.removeGroupMember(chatId:"2004589",membersIds:["55"],completion:{(status,error) in
if status{
"Do your Stuff Here"
} else {
"Operation Failed"
}
})
Completion Handlers
status
Indicates the response of task completion.error
Indicates if there is an error. It will be null if there is no 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.
Function Params
This table lists all possible parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatId | string | yes | The unique ID of the conversation. |
userId | string | yes | The unique ID of the user who is going to be the new group conversation admin. |
To get real-time updates confirm your class to CHConversationDataDelegate
and implement following delegate functions.
func didAdminAdded(conversationId:String?, isAdmin:Bool, userId:String?){
}
func didReceiveNewMessage(message: CHMessage?){
}
Request Example
/// ## Usage:
CHService.main.addGroupAdmin(chatId:"2004589",userId:"55",completion:{(status,error) in
if status{
"Do your Stuff Here"
} else {
"Operation Failed"
}
})
Completion Handlers
status
Indicates the response of task completion.error
Indicates if there is an error. It will be null if there is no error.
Leave a Conversation
Leaves the targeted conversation for a user.
Function Params
This table lists all possible parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatId | string | yes | The unique ID of the conversation to leave. |
To get real-time updates confirm your class to CHConversationDataDelegate
and implement following delegate functions
func didGetChatInfo(conversation: CHConversation?) {
}
Request Example
/// ## Usage:
CHService.main.leaveConversation(chatId:"2004589",completion:{(status,error) in
if status{
"Do your Stuff Here"
} else {
"Operation Failed"
}
})
Completion Handlers
status
Indicates the response of task completion.
error
Indicates if there is an error. It will be null if there is no error.
Delete Conversation
Deletes a targeted conversation usingdeleteConversation
method of CHService
class. Parameters needed are:
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatID | string | yes | The unique ID of the conversation to clear. |
If your class confirms to CHConversationDataDelegate
then following delegate method will be called
func didDeleteChat(conversation: CHConversation?){
}
Request Example
CHService.main.deleteConversation(chatId: conversation.id, completion: {(status,error) in
if status{
print("Success -> Conversation Deleted")
} else{
debugPrint("Failed -> Conversation Delete Operation Failed with \(error.debugDescription)")
}
})
Completion Handlers
status
Indicates the status of the delete action.error
Indicates if there is an error. It will be null if there is no error.
Clear Conversation
Clears a targeted conversation using clearConversation
method of CHService
class.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatID | string | yes | The unique ID of the conversation to clear. |
If your class confirms to CHConversationDataDelegate
then following delegate method will be called
func didClearChat(conversation: CHConversation?){
// Do your Stuff here
}
Request Example
CHService.main.clearConversation(chatId: "3333", completion: {(status,error) in
if status{
// Clear Conversation Passed
} else{
// Clear Conversation API failed
}
})
Completion Handlers
status
Indicates the status of the clear action.error
Indicates if there is an error. It will be null if there is no error.
Mark Messages Read
Mark all messages 'Read' in a targeted conversation for a user using markAllMessageAsRead
function of CHService
class. Parameters needed are:
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatID | string | yes | The unique ID of the conversation in which messages are to be mark Read. |
Request Example
/// ## Usage:
CHService.main.markAllMessageAsRead(chatId:"2004589",completion:{(status,error) in
if status{
"Do your action here"
} else {
"Operation Failed"
}
})
Completion Handlers
status
Indicates the status of the read action performed on conversation.error
Indicates if there is an error. It will be null if there is no error.
Mute or UnMute a Conversation
Mutes or Unmutes a coversation for a user using muteUnmuteConversation
function of CHService
class.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatID | string | yes | The unique ID of the conversation on which mute or unmute action to perform. |
isMuted | Boolean | Yes | Determines whether to mute or unmute the conversation. If set to true, conversation will mute. If set to false, conversation will unmute. |
Request Example
/// ## Usage:
CHService.main.muteUnmuteConversation(chatId:"2004589",isMuted:true,completion:{(status,error) in
if status{
"Do your Stuff Here"
} else {
"Operation Failed"
}
})
Completion Handlers
status
Indicates the response.error
Indicates if there is an error. It will be null if there is no error.
Update Title
Updates the title of a group conversation and send a meta-message in the conversation.
Function Params
This table lists all possible parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
chatId | string | yes | The unique ID of the conversation to update. |
To get real-time updates confirm your class to CHConversationDataDelegate
and implement following delegate functions
func didGetChatInfo(conversation: CHConversation?) {
}
func didReceiveNewMessage(message: CHMessage?){
}
Request Example
/// ## Usage:
CHService.main.updateConversationTitle(title:"New Title",chatId:"205578344",completion:{(status,error) in
if status{
"Do your Stuff Here"
} else {
"Operation Failed"
}
})
Completion Handlers
status
Indicates the response of task completion.error
Indicates if there is an error. It will be null if there is no error.
Update Profile Photo
Updates the profile image of a group conversation and send a meta-message in the conversation.
Function Params
This table lists all possible parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
groupId | string | yes | The unique ID of the group conversation to update. |
profileImageData | data | no | Specifies the profile image data of the conversation. |
To get real-time updates confirm your class to CHConversationDataDelegate
and implement following delegate functions
func didGetChatInfo(conversation: CHConversation?) {
}
func didReceiveNewMessage(message: CHMessage?){
}
Request Example
/// ## Usage:
CHService.main.updateGroupProfilePhoto(profileImageData:imageData,groupId:"20000545938",completion:{(status,error) in
if status{
"Do your Stuff Here"
} else {
"Operation Failed"
}
})
Completion Handlers
status
Indicates the response of task completion.error
Indicates if there is an error. It will be null if there is no error.
Set typing status
Set typing status of a Conversation using publishUserTypingStatus
function of CHConversation
object. Parameter needed is isTyping
indicating wether user is typing or not.
Function Params
The following table lists the parameters this function supports.
Parameter | Type | Required | Description |
---|---|---|---|
isTyping | string | yes | Indicates whether the user is typing or not. |
If your class confirms to CHConversationDataDelegate
then following delegate method is called
func didChangeTypingStatus(conversationId:String?,userId:String?,isTyping:Boolean){
}
Request Example
conversation.publishUserTypingStatus(isTyping: Boolean)