CPChatService
@objc
public class CPChatService : MessageService, CPServiceProtocol
This class is used to manage chat services such as sending and receiving chat messages.
-
An application that needs notifications should implement a ChatDelegate compliant class and set this member as an instance of that class.
Declaration
Swift
@objc public var delegate: CPChatDelegate?
-
Initializes ChatService instance with given configuration.
Declaration
Swift
public init(userInfo: CPUserInfo, info: CPServiceInfo)
Parameters
userInfo
User Information
info
Service information specifying service type and options.
-
Public interface to create a chat conversation object derived from the Conversation base class.
Declaration
Swift
@objc public func createConversation(withParticipant: String) -> CPConversation?
Parameters
withParticipant
URI of remote conversation participant.
Return Value
Object of type ChatConversation derived from Conversation class.
-
Public interface to create a chat group conversation object derived from the Conversation base class.
Declaration
Swift
@objc public func createConversation(withGroup: CPChatGroup) -> CPConversation?
Parameters
withGroup
URI of remote conversation participant.
Return Value
Object of type ChatGroupConversation derived from Conversation class.
-
Public method to upload a file to the server.
Declaration
Swift
@objc public func upload(withFile: URL, progress: @escaping UploadProgressBlock, completion: @escaping UploadCompletionBlock) -> CPActivityHandle
Parameters
withFile
URL of file attachment.
progress
Code block to call when upload progress changes
completion
Code block to execute upon upload completion.
Return Value
Opaque activity handle with a cancel method that can be used to cancel the upload operation.
-
Returns MIME type of the given file.
Declaration
Swift
@objc public func mimeTypeFor(file: URL) -> String
Parameters
file
File URL
Return Value
MIME Type
-
Public method to download a file from the server.
Declaration
Swift
@objc public func download(fromUrl: URL, toFile: URL, progress: @escaping DownloadProgressBlock, completion: @escaping DownloadCompletionBlock) -> CPActivityHandle
Parameters
fromUrl
URL of remote file.
toFile
URL of local file destination.
progress
Code block to call when download progress changes.
completion
Code block to execute upon download completion.
-
Public interface to fetch only group conversation objects from the server.
Declaration
Swift
@objc public func fetchGroupConversations(completion: @escaping FetchBlock)
Parameters
completion
Code block to execute once the fetch has completed.
-
Public interface to fetch only one-to-one conversation objects from the server.
Declaration
Swift
@objc public func fetchOneToOneConversations(completion: @escaping FetchBlock)
Parameters
completion
Code block to execute once the fetch has completed.
-
Public interface to fetch one conversation object from the server. This would be used when refreshing a conversation after receiving a conversation:change event.
Declaration
Swift
@objc public func fetchConversation(withGroupID: String, completion: @escaping FetchBlock)
Parameters
withGroupID
Group key to be used for getting the conversation.
completion
Code block to execute once the fetch has completed.
-
Public interface to fetch one conversation object from the server. This would be used when refreshing a conversation after receiving a conversation:change event.
Declaration
Swift
@objc public func fetchConversation(withParticipant: String, completion: @escaping FetchBlock)
Parameters
withParticipant
Participant key to be used for getting the conversation.
completion
Code block to execute once the fetch has completed.
-
Public interface to delete a conversation object from the server.
Declaration
Swift
@objc public override func delete(conversation: CPConversation, completion: @escaping DeleteCompletionBlock)
Parameters
conversation
Conversation object representing the conversation to delete.
completion
Code block to execute once the delete has completed.
-
Delegate method to get a service’s information
Declaration
Swift
public func serviceInfo() -> CPServiceInfo
Return Value
service information object with service type and preferences.
-
Delegate method to get a list of notfications the service expects
Declaration
Swift
public func notifications() -> [String]
Return Value
list of notification names. These should match what is returned by subscribe() in completion callback.
-
Delegate method to subscribe for notifications from a remote channel
Declaration
Swift
public func subscribe(channelID: String, completion: @escaping SubscribeCompletion)
Parameters
channelID
The channel on which to subscribe for notifications.
completion
Code block to execute upon subscription completion.
-
Delegate method to unsubscribe for notifications
Declaration
Swift
public func unsubscribe(channelID: String, completion: @escaping UnsubscribeCompletion)
Parameters
channelID
The channel from which to unsubscribe for notifications.
completion
Code block to execute upon unsubscription completion.
-
Public method to create a chat group object.
Declaration
Swift
@objc public func createChatGroup(name: String, type: String, subject: String? = nil, image: URL? = nil, participants: [CPChatGroupParticipant], completion: @escaping CreateChatGroupBlock)
Parameters
name
User-friendly name of the chat group
type
“open” or “closed” - only “closed” supported in v1
subject
Topic of discussion for the chat group
image
URL of an image file to be used for the chat group
particpants
An array of participant members of the chat group
completion
Code block to execute upon completion of chat group creation
-
Public method to update a chat group object.
Declaration
Swift
@objc public func updateChatGroupProperties(groupID: String, name: String, subject: String? = nil, image: String? = nil, _ completion: @escaping ErrorCompletionBlock)
Parameters
groupID
Unique identifier assigned by the server to the chat group
name
User-friendly name of the chat group
subject
Topic of discussion for the chat group
image
URL of an image file to be used for the chat group
completion
Code block to execute upon completion of chat group update
-
Public method used to delete a chat group using its unique identifier
Declaration
Swift
@objc public func deleteChatGroup(groupID: String, _ completion: @escaping DeleteCompletionBlock)
Parameters
groupID
Unique identifier assigned by the server to the chat group
completion
Code block to call upon completion of the delete operation
-
Public method used to fetch all chat group objects from the server
Declaration
Swift
@objc public func fetchAllChatGroups(completion: @escaping FetchAllChatGroupsBlock)
Parameters
completion
Code block to call up completion of the fetch operation
-
Public method used to fetch a particular chat group object from the server
Declaration
Swift
@objc public func fetchChatGroup(withKey: String, completion: @escaping FetchChatGroupBlock)
Parameters
withKey
Unique server-assigned identifier
completion
Code block to call up completion of the fetch operation
-
Method which is can be used to change a group participant’s admin role
Declaration
Swift
@objc public func changeGroupAdminRole(status: Bool, groupID: String, forParticipant: String, _ completion: @escaping ErrorCompletionBlock)
Parameters
status
admin role status as bool
groupID
the group ID which participant exists
forParticipant
the participant’s ID
completion
Code block to execute upon completion of group admin role change