Event Handlers
Channelize.io iOS SDK provides a simple way to notify client applications for real-time events happening across the application. Achieve this by registering event handlers for the events. Whenever an event occurs, the respective handler is executed. You can also add multiple handlers for an event.
Users Related Event Handlers
To receive events happening for users from Channelize.io server confirm your class with CHUserEventDelegates
protocol and register your class to this protocol with a unique ID.
Register Delegate and use Call Back Functions
To register your class to get user related events, implement below example
class ContactsViewController: CHUserEventDelegates {
var screenIdentifier: UUID!
override func viewDidLoad() {
super.viewDidLoad()
self.screenIdentifier = UUID()
Channelize.addUserEventDelegate(delegate: self, identifier: self.screenIdentifier)
}
// MARK: - CHUserEventDelegates Callback Functions
/// When a user blocks another user. This event will update both the users.
func didUserBlocked(model: CHUserBlockModel?) {
}
/// When a user unblocks another user. This event will update both the users.
func didUserUnBlocked(model: CHUserUnblockModel?) {
}
/// When a user online or offline status is updated.
func didUserStatusUpdated(model: CHUserStatusUpdatedModel?) {
}
/// When two users become friends. This event will update both the users.
func didUserAddedAsFriend(model: CHUserAddedFriendModel?) {
}
/// When a user removes someone from its friend or the following list. This event will update both the users.
func didUserRemovedAsFriend(model: CHUserRemovedFriendModel?) {
}
}
Unregister Delegate
To stop receiving users related events callback.
Channelize.removeUserEventDelegate(identifier: self.screenIdentifier)
Conversations Related Event Handler
To receive events happening in the conversations from Channelize.io server, confirm your class with CHConversationEventDelegate
protocol and register your class to this protocol with a unique ID.
Register Delegate and use Call Back Functions
class RecentConversationsViewController: CHConversationEventDelegate {
var screenIdentifier: UUID!
override func viewDidLoad() {
super.viewDidLoad()
self.screenIdentifier = UUID()
Channelize.addConversationEventDelegate(delegate: self, identifier: self.screenIdentifier)
}
CHConversationEventDelegate
Callback Functions
Use Use following functions in class confirming to CHConversationEventDelegate
protocol
New Message Recieved
func didRecieveNewMessage(model: CHNewMessageRecievedModel?) {
}
CHNewMessageRecievedModel
properties
Name | Type | Description |
---|---|---|
message | CHMessage | New message object. |
timeStamp | Date | Timestamp of the event. |
Current user Joined a conversation
func didCurrentUserJoinedConversation(model: CHCurrentUserJoinConversationModel?) {
}
CHCurrentUserJoinConversationModel
properties
Name | Type | Description |
---|---|---|
conversation | CHConversation | Joined Conversation object. |
timeStamp | Date | Timestamp of the event. |
Current user Left or removed from Conversation
func didCurrentUserRemovedFromConversation(model: CHCurrentUserRemovedModel?) {
}
CHCurrentUserRemovedModel
properties
Name | Type | Description |
---|---|---|
conversation | CHConversation | Related Conversation object. |
timeStamp | Date | Timestamp of the event. |
New Members added to the conversation
func didNewMembersAddedToConversation(model: CHNewMemberAddedModel?) {
}
CHNewMemberAddedModel
properties
Name | Type | Description |
---|---|---|
conversation | CHConversation | Related Conversation object. |
addedMembers | [CHMember] | Array of added members. |
timeStamp | Date | Timestamp of the event. |
Members removed from the Conversation
func didMembersRemovedFromConversation(model: CHMembersRemovedModel?) {
}
CHMembersRemovedModel
properties
Name | Type | Description |
---|---|---|
conversation | CHConversation | Related Conversation object. |
removedUsers | [CHUser] | Array of removed users. |
timeStamp | Date | Timestamp of the event. |
New Admin added to the conversation
func didNewAdminAddedToConversation(model: CHNewAdminAddedModel?) {
}
CHNewAdminAddedModel
properties
Name | Type | Description |
---|---|---|
conversation | CHConversation | Related Conversation object. |
adminUser | CHUser | User object of the admin. |
timeStamp | Date | Timestamp of the event. |
Conversation Mute status updated
func didUpdateConversationMuteStatus(model: CHConversationMuteStatusModel?) {
}
CHConversationMuteStatusModel
properties
Name | Type | Description |
---|---|---|
conversation | CHConversation | Related Conversation object. |
mutedUser | CHUser | User object of muted user is case on 1-1 conversation. |
timeStamp | Date | Timestamp of the event. |
Conversation Info Updated
func didConversationInfoUpdated(model: CHConversationUpdatedModel?) {
}
CHConversationUpdatedModel
properties:
Name | Type | Description |
---|---|---|
conversationID | String | Id of updated conversation. |
type | String | Type of updated conversation. |
customType | String | Sub type of updated conversation. |
isGroup | Bool | Wether conversation is a group conversation. |
title | String | New Title of the conversation if updated. |
profileImageUrl | String | Profile image url of updated conversation. |
memberCount | Int | Members count of updated conversation. |
createdAt | Date | Creation date of updated Conversation. |
timeStamp | Date | Timestamp of the event. |
Conversation Cleared
func didConversationCleared(model: CHConversationClearModel?) {
}
CHConversationClearModel
properties
Name | Type | Description |
---|---|---|
conversation | CHConversation | Cleared Conversation object. |
timeStamp | Date | Timestamp of the event. |
Conversation Deleted
func didConversationDeleted(model: CHConversationDeleteModel?) {
}
CHConversationDeleteModel
properties:
Name | Type | Description |
---|---|---|
conversation | CHConversation | Deleted Conversation object. |
timeStamp | Date | Timestamp of the event. |
Conversation Messages Deleted
func didConversationMessageDeleted(model: CHMessageDeletedModel?) {
}
CHMessageDeletedModel
properties:
Name | Type | Description |
---|---|---|
conversation | CHConversation | Related Conversation object. |
deletedMessages | [CHMessage] | Array of deleted messages objects. |
timeStamp | Date | Timestamp of the event. |
Message Deleted for Everyone
func didConversationMessageDeletedForEveryOne(model: CHMessageDeletedModel?) {
}
CHMessageDeletedModel
properties:
Name | Type | Description |
---|---|---|
conversation | CHConversation | Related Conversation object. |
deletedMessages | [CHMessage] | Array of deleted messages objects. |
timeStamp | Date | Timestamp of the event. |
Conversation Marked as Read
func didConversationMarkAsRead(model: CHConversationMarkReadModel?) {
}
CHConversationMarkReadModel
properties:
Name | Type | Description |
---|---|---|
conversation | CHConversation | Related Conversation object. |
user | CHUser | User object who mark the conversation read. |
timeStamp | Date | Timestamp of the event. |
Typing status updated
func didTypingUserStatusUpdated(model: CHUserTypingStatusModel?) {
}
CHUserTypingStatusModel
properties:
Name | Type | Description |
---|---|---|
conversation | CHConversation | Related Conversation object. |
user | CHUser | User object whose typing status changed. |
isTyping | Bool | Wether user is typing or not. |
timeStamp | Date | Timestamp of the event. |
Reaction Related Events
To recieve events related to Message reactions, call joinReactionsSubscribers
method of ChannelizeAPIService
class and pass conversation id in method parameters.
To stop recieving events related to message reactions, call leaveReactionsSubscribers
method of ChannelizeAPIService
class and pass conversation id in method parameters.
Note Please call joinReactionsSubscribers
function when you open the conversation screen and leaveReactionsSubscribers
when you completely close the conversation screen. Do not unnecessarily call this function.
let conversationId = "5a928b10-4258-11ea-9c07-831a487bf6af"
ChannelizeAPIService.joinReactionsSubscribers(conversationId: conversationId)
let conversationId = "5a928b10-4258-11ea-9c07-831a487bf6af"
ChannelizeAPIService.leaveReactionsSubscribers(conversationId: conversationId)
Make sure your class confirms to CHConversationEventDelegate
protocol as describe above. Implement following functions to recieve reactions related events.
Reaction Added
func didMessageReactionAdded(model: CHReactionEventModel?) {
}
Reaction Removed
func didMessageReactionRemoved(model: CHReactionEventModel?) {
}
CHReactionEventModel
properties:
Name | Type | Description |
---|---|---|
message | CHMessage | Message object on which reaction is added. |
reactionKey | String | Added or removed reaction key. |
reactingUserId | String | Id of the user who reacted. |
reactingUserName | String | Display name of the user who reacted. |
timeStamp | Date | Timestamp of the event. |