Channel Management
Channel Members
When a user joins a channel, they are able to observe and chat with other users in that channel. They are also automatically considered a member of that channel. The Chat SDK provides the ability to view which users are currently in the channel as well as invite other users to join the channel.
Channel Type | Discoverable by | Message sending privileges | Moderation access |
Community | All users and admins | Users and admins | All Moderation tools |
Live | Only members and admins | Users and admins | All Moderation tools |
Broadcast | All users and admins | Admins | Admin Moderation tools |
Conversation | Only members | Users | No Moderation tools |
Each channel is identified by an unique channelId
, which is any string that uniquely identifies the channel and is immutable through its lifetime. When creating channels, you can specify your own channelId
, or leave it to Amity's Chat SDK to automatically generate one for you.
There can be only one and one only channel with a given
channelId
an error will be thrown when trying to generate two channels with the samechannelId
.
There are three ways of obtaining a channel: via create, join, or get. They all return a LiveObject with the complete channel model. However, createChannel
guarantees that the requested channel is a new channel, whereas joinChannel
will attempt to join an existing channel. If there is a requirement to create a new channel, then use of createChannel
then call joinChannel
. Lastly calling getChannel
only gives you back the channel LiveObject, but it won't make the current user join said channel.
Create Channel
ChannelRepository
provides createChannel
method to create a new channel. It supports creating of 3 types of channels Community
, Live
and Conversation
. Each channel type has specific builder classes which helps you to create that particular channel. Build your channel information first and then create the particular channel.
The above code creates a channel and notifies you through observer block.
In the case that there is already an existing channel with the same
channelId
, the LiveObject will notify you with anerror
object.The
channelId
parameter increateChannel
can beundefined
when this happens, the SDK will generate an uniquechannelId
for this channel, ensuring no unique ID conflicts.3 channel types can be created through SDK i.e
Community
,Live
andConversation
. Creation ofPrivate
andStandard
type has been removed. Creation ofBroadcast
channel type is not supported through the SDK. But for queryqueryChannels
method supports all channel types includingBroadcast
,Private
andStandard
.
Create Conversation:
The Chat SDK provides a convenient method which creates a conversation channel type.
Conversation channel is unique based on its membership. When creating conversation the system will check if channel with the same membership already exists, if such channel already exists the system will return existing channel instead of creating a new one.
Get Channel
Join Channel
Channel Query
ChannelRepository
provides a way to query list of channels using queryChannels
method. It returns aLiveCollection
of all the matching channels available. This live collection returned will automatically update and notify you on any channel modifications.
Channel Filtering
You can filter channels by various criteria such as tags
, excludingTags
, isDeleted
channels etc.
Set Channel Properties
All channels have the following properties:
Channel display name
Channel Avatar
Tags
Metada
You can set each property using their respective setter methods.
Set Display Name
Every channel contains an optional displayName
property. This property is mainly used to identify the channel in push notifications, but it is also exposed to the application via Channel
object.
You can set a channel's displayName
with the following method:
An optional completion callback is available to inform you on whether the request has succeeded or not.
Set Avatar
There is no specific method for setting a channel's avatarFileId
but you can use the updateChannel
method for this task. Refer to Update Channel section.
You need to upload the avatar first and retrieve the avatar file ID which you need to pass as a parameter when updating the channel. You can refer to Files page to create and get the file information.
Set Tags
Tags are usually one to three words that provide details about a channel as well as post, comment, community, and message. They are simple descriptions and are mostly used in querying related items that have the same tags.
Tags are optional. Up to five tags can be added and each tag can be up to 24 characters long.
You can set a channel's tags
with the following method:
Set Metadata
Metadata is a general purpose data store that is automatically synchronized to all the channel members. It is meant as an elegant mechanism to store contextual information about a specific channel. The data can be any number of JSON key value pairs up to 100 kb. Example use cases include:
Conversation title or cover photo
Global conversation settings
Metadata is implemented with last writer wins semantics: multiple mutations by independent users to the metadata object will result in a single stored value. No locking, merging, or other coordination is performed across multiple writes on the data.
The completion block will be triggered with the outcome of the request. The latest metadata of the channel is always exposed as part of the metadata
property on the channel model.
Update Channel
You can update the following channel properties using the updateChannel
method:
Channel display name
Channel Avatar
Tags
Metada
To set metadata
, call the setMetadataForChannel:
method:
Refer to this table for the parameters you can pass to the updateChannel
method.
Parameter | Data type | Description |
---|---|---|
|
| Channel display name |
|
| Avatar file ID |
|
| Tags used in querying |
|
| Metadata of channel |
The completion block will be triggered with the outcome of the request. The latest metadata of the channel is always exposed as part of the metadata
property on the channel model.
To update any of the channel properties, simply pass the channel ID along with the channel properties that you want to update and the new property values.
When updating the channel avatar, you need to upload the avatar first and retrieve the avatar file ID. You can refer to Files page to create and get the file information.
The updateChannel
method will throw an error if an incorrect parameter is passed.
When updating the channel avatar, you need to upload the avatar first and retrieve the avatar file ID. You can refer to Files page to create and get the file information.
Leave Channel
The leaveChannel
method will remove the active user as a member of the channel. If a user leaves a channel, the user can't receive messages from the channel anymore.
Required parameter
channelId
(string)
- the ID of the channel to leave
Delete Channel
Deleting a channel is not supported in SDK. Refer to this section for the instructions on how to delete a channel via API.
Last updated