iOS
Group Channel

Group Channel

A group channel is a chat that provides close interactions among limited number of users. It can be private or public. A private group channel can let a user join the chat through an invitation by another user who is already a member of the chatroom. For 1-on-1 messaging, you can create a private group channel with two members. A public group chat can let a user join the chat without invitation from others. A group channel can consist of one to one hundred members by default setting. This default number of members can increase per request.

A user can receive all messages from the group channels that they are a member of, and sends a message to those channels. They can also receive push notifications, typing indicators, unread counts and read receipts from the joined channels when they go offline. For more information, see the Push Notifications page which describes how to turn on and manage the push preference.


Choose a type of a channel

With our iOS SDK, you can use a variety of behaviour related properties when creating different types of group channels. You can create a group channel after configuring these properties.

Private vs. Public

A private group channel (default setting) can be accessed only by users that have accepted an invitation from an existing member of that group. On the other hand, a public group channel can be accessed by any user without an invitation, like an open channel.

Ephemeral vs. Persistent

Messages sent in an ephemeral group channel are not saved in the database of the SendBird system. Therefore, the old messages that scroll up beyond the user's display due to new messages can't be retrieved. On the other hand, messages sent in a persistent group channel (default setting) are stored permanently in the database.

1-on-1 vs. 1-on-N

A distinct group channel can be reused for the same users. If a user is invited as a new member, or if a member leaves the channel, then the distinct property is disabled automatically. For example, when attempting to create a new group channel with 3 users, A, B, and C, if a channel with same users already exists, a reference to the existing channel is just returned to who has attempted the new channel.

Consequently, we recommend that you turn on the distinct property in 1-on-1 messaging channels to reuse the existing channel when a user directly sends a message to another user. If the property is turned off, a new group channel is created with the same user even if there is a previous chat between them, and you can't see the old messages or data.


Create a channel

A user can create a group channel from inviting other users anytime in their client app. At the implemention level, you just need to write your code which passes the IDs of users to invite as a parameter to the creation method.

Before you write the code for creating a group channel for a typical 1-on-1 chat, you should make sure that you turn on the distinct property of the channel. Otherwise, if you turn off the distinct property, a new channel will be created with the same partner user even if there is already an existing channel between them. In this case, multiple 1-on-1 channels between the same two users can exist, each with its own chat history and data.

Note: If you want to retrieve a list of group channels, which also includes the current user's empty channels without any chat, you should set the includeEmptyChannel option of a SBDGroupChannelListQuery instance to true for the retrieval.

Objective-C
Swift
Light Color Skin
Copy
[SBDGroupChannel createChannelWithUserIds:USER_IDS isDistinct:IS_DISTINCT completionHandler:^(SBDGroupChannel * _Nullable groupChannel, SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
SBDGroupChannel.createChannel(withUserIds: USER_IDS, isDistinct: IS_DISTINCT) { (groupChannel, error) in
    guard error == nil else {   // Error. 
        return
    }
}

When creating a channel, you can also append additioanl information like cover image and description by specifying several arguments.

Objective-C
Swift
Light Color Skin
Copy
[SBDGroupChannel createChannelWithName:NAME isDistinct:IS_DISTINCT userIds:USER_IDS coverUrl:COVER_IMAGE_URL data:DATA customType:CUSTOM_TYPE completionHandler:^(SBDGroupChannel * _Nullable groupChannel, SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
SBDGroupChannel.createChannel(withName: NAME, isDistinct: IS_DISTINCT, userIds: USER_IDS, coverUrl: COVER_IMAGE_URL, data: DATA, customType: CUSTOM_TYPE) { (groupChannel, error) in
    guard error == nil else {   // Error. 
        return
    }
}
ParameterDescription

NAME

Type: NSString
Specifies the channel topic, or the name of the channel.

IS_DISTINCT

Type: BOOL
Specifies the channel topic, or the name of the channel.

USER_IDS

Type: NSArray
Specifies a list of one or more IDs of the users to invite to the channel.

COVER_IMAGE_URL

Type: NSString
Specifies the cover image URL of the channel.

DATA

Type: NSString
Specifies additional data that you can store for the channel.

CUSTOM_TYPE

Type: NSString
Specifies the custom channel type which is used for channel grouping.

You can get a cover image URL using the coverUrl property of a SBDGroupChannel object, and update the channel's cover image using a method like updateChannelWithName:isDistinct:coverUrl:data:completionHandler:.

Note: You can also create a group channel using the Platform API which helps you control channel creations and member invitations on your server-side.

Otherwise, you can configure SBDGroupChannelParams and create a new channel with that like below.

Objective-C
Swift
Light Color Skin
Copy
NSMutableArray<NSString *> *users = [[NSMutableArray alloc] init];
[users addObject:@"John"];
[users addObject:@"Harry"];
[users addObject:@"Jay"];

NSMutableArray<NSString *> *ops = [[NSMutableArray alloc] init];
[ops addObject:@"Jeff"];

SBDGroupChannelParams *params = [[SBDGroupChannelParams alloc] init];
[params setPublic:NO];
[params setEphemeral:NO];
[params setDistinct:NO];
[params addUserIds:users];
[params setOperatorUserIds:ops];    // Or setOperators:
[params setName:@"NAME"];
[params setChannelUrl:@"UNIQUE_CHANNEL_URL"];   // In a group channel, you can create a new channel by specifying its unique channel URL in a 'SBDGroupChannelParams' object.
[params setCoverImage:FILE];        // Or setCoverUrl:
[params setData:@"DATA"];
[params setCustomType:@"CUSTOM_TYPE"];

[SBDGroupChannel createChannelWithParams:params completionHandler:^(SBDGroupChannel * _Nullable groupChannel, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
var users: [String] = []
users.append("John")
users.append("Harry")
users.append("Jay")

var ops: [String] = []
ops.append("Jeff")

var params = SBDGroupChannelParams()
params.isPublic = false
params.isEphemeral = false
params.isDistinct = false
params.addUserIds(users)
params.operatorUserIds = ops        // Or .operators 
params.name = "NAME"
params.channelUrl = "UNIQUE_CHANNEL_URL"    // In a group channel, you can create a new channel by specifying its unique channel URL in a 'GroupChannelParams' object.
params.coverImage = FILE            // Or .coverUrl
params.data = "DATA"
params.customType = "CUSTOM_TYPE"

SBDGroupChannel.createChannel(with: params) { (groupChannel, error) in
    guard error == nil else {   // Error.
        return
    }
}

Invite users as members

Only members of a group channel can invite new users to the channel. You can also determine whether the newly invited user sees the past messages in the channel or not.

Note: In your dashboard, go to the Settings > Application > Messages tab, and there is the Chat history option. If the option is turned on, new users can view all messages sent before they have joined the channel. If turned off, new users only see messages sent after they have been invited. By default, this option is turned on.

Objective-C
Swift
Light Color Skin
Copy
[groupChannel inviteUserIds:userIds completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
groupChannel.inviteUserIds(userIds) { (error) in
    guard error == nil else {   // Error.
        return
    }
}

Accept or decline an invitation from another user

A user who is invited to a group channel can accept or decline the invitation. If a user accepts an invitation, they join the channel as a new member and can start chatting with other members. If a user declines an invitation, the invitation is canceled.

Objective-C
Swift
Light Color Skin
Copy
// Accepting an invitation
[groupChannel acceptInvitationWithCompletionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];

// Declining an invitation
[groupChannel declineInvitationWithCompletionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
// Accepting an invitation
groupChannel.acceptInvitation { (error) in
    guard error == nil else {   // Error. 
        return
    }
}

// Declining an invitation
groupChannel.declineInvitation { (error) in
    guard error == nil else {   // Error. 
        return
    }
}

By implementing the didReceiveInvitation: and didDeclineInvitation: of a channel delegate, you can make the client apps of other members in the foreground to be notified of the results of two actions above. If you want more information, see the Event Delegate page.

Note: By using the setChannelInvitationAutoAccept:completionHandler:, you can determine for users within an application whether or not to automatically join a private group channel promptly from an invitation without having to accept it. By default, the value of channel invitation preference is true. If you want to give them the ability to decide whether to accept or decline an invitation, you should set the value of the preference to false through the setChannelInvitationAutoAccept:completionHandler: like the following sample code.

Objective-C
Swift
Light Color Skin
Copy
BOOL autoAccept = NO;   // The value of `true` (default) means that a user will automatically join a group channel with no choice of accepting and declining an invitation. 
[SBDMain setChannelInvitationPreferenceAutoAccept:autoAccept completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) {     // Error.
        return;
    }
}];
Light Color Skin
Copy
var autoAccept = false  // The value of `true` (default) means that a user will automatically join a group channel with no choice of accepting and declining an invitation.
SBDMain.setChannelInvitationPreferenceAutoAccept(autoAccept) { (error) in
    guard error == nil else {       // Error.
        return
    }
}

Join a channel as a member

This is only for public group channels. Any user can join a public group channel as a member without an invitation and chat with other members in the channel.

Objective-C
Swift
Light Color Skin
Copy
if (groupChannel.isPublic) {
    [groupChannel joinWithCompletionHandler:^(SBDError * _Nullable error) {
        if (error != nil) { // Error.
            return;
        }
    }];
}
Light Color Skin
Copy
if groupChannel.isPublic {
    groupChannel.join { (error) in
        guard error == nil else {   // Error. 
            return
        }
    }
}

Leave a channel

If a user leaves a group channel, the user can't receive messages from the channel anymore.

Objective-C
Swift
Light Color Skin
Copy
[groupChannel leaveChannelWithCompletionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
channel.leave { (error) in
    guard error == nil else {   // Error. 
        return
    }
}

Freeze and unfreeze a channel

You can temporarily disable various functions of a group channel to stop members from chatting in the channel, and enable the functions so that the members chat with each other. Note that in a frozen channel, normal members can't chat each other but the operators can send a message to the channel.

Objective-C
Swift
Light Color Skin
Copy
// Freezing a channel
[groupChannel freezeWithCompletionHandler:^(SBDError * _Nullable error) {
    if (error != nil) {     // Error.
        return;
    }
    
    // TODO: Custom implementation for what should be done after freezing.
}];

// Unfreezing a channel
[groupChannel unfreezeWithCompletionHandler:^(SBDError * _Nullable error) {
    if (error != nil) {     // Error.
        return;
    }

    // TODO: Custom implementation for what should be done after unfreezing.
}];
Light Color Skin
Copy
// Freezing a channel
groupChannel?.freeze(completionHandler: { (error) in
    guard error == nil else {       // Error.
        return
    }

    // TODO: Custom implementation for what should be done after freezing.
})

// Unfreezing a channel
groupChannel?.unfreeze(completionHandler: { (error) in
    guard error == nil else {       // Error.
        return
    }

    // TODO: Custom implementation for what should be done after unfreezing.
})

Retrieve a list of channels

You can retrieve a list of the current user's group channels using the loadNextPageWithCompletionHandler: method of a SDBGroupChannelListQuery instance which returns a list of SBDGroupChannel objects.

Note: Using the includeEmptyChannel option of a SBDGroupChannelListQuery instance, you can determine whether or not to include empty channels in the result. The empty channels indicate group channels that have been created but currently contain no messages. By default, empty channels are included (displayed).

Objective-C
Swift
Light Color Skin
Copy
SBDGroupChannelListQuery *query = [SBDGroupChannel createMyGroupChannelListQuery];
query.includeEmptyChannel = NO;
[query loadNextPageWithCompletionHandler:^(NSArray<SBDGroupChannel *> * _Nullable groupChannels, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
let query = SBDGroupChannel.createMyGroupChannelListQuery()
query?.includeEmptyChannel = false 
query?.loadNextPage(completionHandler: { (groupChannels, error) in
    guard error == nil else {   // Error. 
        return
    }
})

Retrieve a channel by URL

Since a channel URL is a unique identifier of a group channel, you can use a URL when retrieving a channel object.

Objective-C
Swift
Light Color Skin
Copy
[SBDGroupChannel getChannelWithUrl:CHANNEL_URL completionHandler:^(SBDGroupChannel * _Nonnull groupChannel, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }

    // TODO: Implement what is needed with the contents of the response in the groupChannel parameter.
}];
Light Color Skin
Copy
SBDGroupChannel.getWithUrl(CHANNEL_URL) { (groupChannel, error) in
    guard error == nil else {   // Error.
        return
    }

    // TODO: Implement what is needed with the contents of the response in the groupChannel parameter.
}

Note: We recommend that you store a user's channel URLs to handle the lifecycle or state changes of your client app, or other unexpected situations. For example, when a user is disconnected from SendBird server due to switching to another app temporarily, you can provide a smooth restoration of the user's state using a stored URL to fetch the appropriate channel instance.


Hide or archive a channel from a list of channels

The following code will allow you to hide or archive a specific group channel from a list of the channels.

Objective-C
Swift
Light Color Skin
Copy
[groupChannel hideChannelWithHidePreviousMessages:IS_HIDE_PREVIOUS_MESSAGES allowAutoUnhide:IS_ALLOW_AUTO_UNHIDE completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];


[groupChannel unhideChannelWithCompletionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
groupChannel.hideChannel(withHidePreviousMessages:IS_HIDE_PREVIOUS_MESSAGES, allowAutoUnhide:IS_ALLOW_AUTO_UNHIDE) { (error) in
    guard error == nil else {   // Error.
        return
    }
}

groupChannel.unhideChannel(withCompletionHandler: { error in
    guard error == nil else {   // Error.
        return
    }
})
ParameterDescription

IS_HIDE_PREVIOUS_MESSAGES

Type: BOOL
When the channel gets appeared back in the list, determines whether to conceal the messages sent and received before hiding or archiving the channel. If set to true, the previous messages aren't displayed in the channel. (Default: false)

IS_ALLOW_AUTO_UNHIDE

Type: BOOL
Determines the state and operating behavior of the channel in the list. If set to true, the channel is hidden from the list, automatically gets unhidden when receiving a new message from other members, and appears back. If set to false, the channel is archived and disappeared from the list, and never appears back unless the unhideChannelWithCompletionHandler: is called for unarchiving. (Default: true)

Using the channel.hiddenState, you can check the channel state with regard to the list.

Objective-C
Swift
Light Color Skin
Copy
if (channel.hiddenState == SBDGroupChannelHiddenStateUnhidden) {
    // The channel is displayed in the list.
} else if (channel.hiddenState == SBDGroupChannelHiddenStateHiddenAllowAutoUnhide) {
    // The channel is hidden from the list, and appears in the list on condition.
} else if (channel.hiddenState == SBDGroupChannelHiddenStateHiddenPreventAutoUnhide) {
    // The channel is archived, and appears only when the unhideChannelWithCompletionHandler: is called.
}
Light Color Skin
Copy
if channel.hiddenState == SBDChannelHiddenStateFilter.hiddenStateUnhidden {
    // The channel is displayed in the list.
} else if channel.hiddenState == SBDChannelHiddenStateFilter.hiddenAllowAutoUnhide {
    // The channel is hidden from the list, and appears in the list on condition.
} else if channel.hiddenState == SBDChannelHiddenStateFilter.hiddenPreventAutoUnhide {
    // The channel is archived, and appears only when the unhideChannel() is called.
}

You can also filter channels by their state like the following:

Objective-C
Swift
Light Color Skin
Copy
SBDGroupChannelListQuery *filteredQuery = [SBDGroupChannel createMyGroupChannelListQuery];
filteredQuery.channelHiddenStateFilter = SBDGroupChannelHiddenStateFilterHiddenPreventAutoUnhide;
// The filter options are limited to `SBDGroupChannelHiddenStateFilterUnhiddenOnly`, `SBDGroupChannelHiddenStateFilterHiddenOnly`, `SBDGroupChannelHiddenStateFilterHiddenAllowAutoUnhide`, or `SBDGroupChannelHiddenStateFilterHiddenPreventAutoUnhide`.
// If set to `SBDGroupChannelHiddenStateFilterHiddenOnly`, hidden and archived channels are returned.
[filteredQuery loadNextPageWithCompletionHandler:^(NSArray<SBDGroupChannel *> * _Nullable groupChannels, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
    
    // Only archived group channels are returned.
}];
Light Color Skin
Copy
let query = SBDGroupChannel.createMyGroupChannelListQuery()
query?.channelHiddenStateFilter = SBDChannelHiddenStateFilter.hiddenPreventAutoUnhide
// The filter options are limited to `SBDChannelHiddenStateFilter.unhiddenOnly`, `SBDChannelHiddenStateFilter.hiddenOnly`, `SBDChannelHiddenStateFilter.hiddenAllowAutoUnhide`, or `SBDChannelHiddenStateFilter.hiddenPreventAutoUnhide`.
// If set to `SBDChannelHiddenStateFilter.hiddenOnly`, hidden and archived channels are returned.
query?.loadNextPage(completionHandler: { groupChannels, error in
    guard error == nil else {   // Error.
        return
    }
        
    // Only archived group channels are returned.
})

Filter channels by user IDs

Using the SBDGroupChannelListQuery's userIdsExactFilter or userIdsIncludeFilter, you can filter group channels by user IDs. Let's assume the ID of the current user is Harry and the user is a member of two group channels:

  • channelA consists of Harry, John, and Jay.
  • channelB consists of Harry, John, Jay, and Jin.

A userIdsExactFilter returns a list of the current user's group channels containing exactly the queried user IDs. In case you specify only one user ID in the filter, the filter returns a list of the current user's one (distinct) or more 1-on-1 group channels with the specified user.

Objective-C
Swift
Light Color Skin
Copy
SBDGroupChannelListQuery *filteredQuery = [SBDGroupChannel createMyGroupChannelListQuery];
[filteredQuery setUserIdsExactFilter:@[@"John", @"Jay"]];
[filteredQuery loadNextPageWithCompletionHandler:^(NSArray<SBDGroupChannel *> * _Nullable groupChannels, SBDError * _Nullable error) {
    // Only 'channelA' is returned.
}];
Light Color Skin
Copy
let query = SBDGroupChannel.createMyGroupChannelListQuery()
query?.userIdsExactFilter = ["John", "Jay"]
query?.loadNextPage(completionHandler: { (groupChannels, error) in
    // Only 'channelA' is returned.
})

A userIdsIncludeFilter returns a list of the current user's group channels including the queried user IDs partially and exactly. Two different results can be returned according to the value of the queryType parameter.

Objective-C
Swift
Light Color Skin
Copy
SBDGroupChannelListQuery *filteredQuery = [SBDGroupChannel createMyGroupChannelListQuery];
[filteredQuery setUserIdsIncludeFilter:@[@"John", @"Jay", @"Jin"] queryType:SBDGroupChannelListQueryTypeAnd];
[filteredQuery loadNextPageWithCompletionHandler:^(NSArray<SBDGroupChannel *> * _Nullable groupChannels, SBDError * _Nullable error) {
    // Only 'channelB' that include the ids {"John", "Jay", "Jin"} as a subset is returned.
}];

[filteredQuery setUserIdsIncludeFilter:@[@"John", @"Jay", @"Jin"] queryType:SBDGroupChannelListQueryTypeOr];
[filteredQuery loadNextPageWithCompletionHandler:^(NSArray<SBDGroupChannel *> * _Nullable groupChannels, SBDError * _Nullable error) {
    // 'channelA' and 'channelB' that include {"John"}, plus 'channelA' and 'channelB' that include {"Jay"}, plus 'channelB' that include {"Jin"}.
    // Actually 'channelA' and 'channelB' are returned.
}];
Light Color Skin
Copy
let filteredQuery = SBDGroupChannel.createMyGroupChannelListQuery()
filteredQuery?.setUserIdsIncludeFilter(["John", "Jay", "Jin"], queryType: SBDGroupChannelListQueryType.and)
filteredQuery?.loadNextPage(completionHandler: { (groupChannels, error) in
    // Only 'channelB' that include the ids {"John", "Jay", "Jin"} as a subset is returned.

})

filteredQuery?.setUserIdsIncludeFilter(["John", "Jay", "Jin"], queryType: SBDGroupChannelListQueryType.or)
filteredQuery?.loadNextPage(completionHandler: { (groupChannels, error) in
    // 'channelA' and 'channelB' that include {"John"}, plus 'channelA' and 'channelB' that include {"Jay"}, plus 'channelB' that include {"Jin"}.
    // Actually 'channelA' and 'channelB' are returned.
})

Send a message

To a joined group channel, a user can send messages of the following types:

  • UserMessage: a text message sent by a user.
  • FileMessage: a binary file message sent by a user.

You can additionally specify a CUSTOM_TYPE to further subclassify a message. When you send a text message, you can additionally attach arbitrary strings via a data field. You can utilize this field to send structured data such as font size, font type, or a custom JSON object.

Message delivery failures due to the network issues return an exception. By implementing the completionHandler of the method, you can display messages that are successfully sent to a channel.

Objective-C
Swift
Light Color Skin
Copy
SBDUserMessageParams *params = [[SBDUserMessageParams alloc] init];
[params setMessage:MESSAGE];
[params setCustomType:CUSTOM_TYPE];
[params setData:DATA];
[params setMentionType:SBDMentionTypeUsers];        // Either SBDMentionTypeUsers or SBDMentionTypeChannel 
[params setMentionedUserIds:@[@"Jeff", @"Julia"]];  // Or setMentionedUsers:LIST_OF_USERS_TO_MENTION
[params setMetaArrayKeys:@[@"linkTo", @"itemType"]];
[params setTargetLanguages:@[@"fr", @"de"]];        // French and German
[params setPushNotificationDeliveryOption:SBDPushNotificationDeliveryOptionDefault];

[groupChannel sendUserMessageWithParams:params completionHandler:^(SBDUserMessage * _Nullable userMessage, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
var params = SBDUserMessageParams()
params.message = MESSAGE
params.customType = CUSTOM_TYPE
params.data = DATA
params.mentionType = SBDMentionTypeUsers        // Either SBDMentionTypeUsers or SBDMentionTypeChannel
params.mentionedUserIds = ["Jeff", "Julia"]     // Or .mentionedUsers = LIST_OF_USERS_TO_MENTION
params.metaArrayKeys = ["linkTo", "itemType"]
params.targetLanguages = ["fr", "de"]           // French and German
params.pushNotificationDeliveryOption = SBDPushNotificationDeliveryOptionDefault

groupChannel.sendUserMessage(with: params) { (userMessage, error) in
    guard error == nil else {   // Error.
        return
    }
}

A user can also send any binary file through the SDK. The two ways to send a binary file are provided: by sending the file itself, or by sending a URL.

Sending a raw file indicates that you upload it to SendBird server and it can be downloaded from the server when needed in client apps. As another option, you can choose to send a file hosted on your server by passing a URL that represents the location of the file as a parameter. In this case, your file isn't hosted on SendBird server, and can be downloaded only from your own server instead.

Note: If you upload a file directly, a size limit is imposed per file depending on your plan. You can see your limit in the dashboard and adjust the limit via our sales team. No file size limit is imposed if you send a file message with its URL since the file isn't uploaded to SendBird server.

Objective-C
Swift
Light Color Skin
Copy
// Sending a file message with a raw file
NSMutableArray<SBDThumbnailSize *> *thumbnailSizes = [[NSMutableArray alloc] init];

[thumbnailSizes addObject:[SBDThumbnailSize makeWithMaxCGSize:CGSizeMake(100.0, 100.0)]];   // Allowed number of thumbnail images: 3
[thumbnailSizes addObject:[SBDThumbnailSize makeWithMaxWidth:200.0 maxHeight:200.0]];

SBDFileMessageParams *params = [[SBDFileMessageParams alloc] init];
[params setFile:FILE];                  // or setFileUrl:FILE_URL (You can also send a file message with a file URL.)
[params setFileName:FILE_NAME];
[params setFileSize:FILE_SIZE];
[params setMimeType:MIME_TYPE];
[params setThumbnailSizes:thumbnailSizes];
[params setCustomType:CUSTOM_TYPE];
[params setData:DATA];
[params setMentionType:SBDMentionTypeUsers];            // Either SBDMentionTypeUsers or SBDMentionTypeChannel
[params setMentionedUserIds:@[@"Jeff", @"Julia"]];      // or setMentionedUsers:LIST_OF_USERS_TO_MENTION
[params setMetaArrayKeys:@[@"linkTo", @"itemType"]];
[params setTargetLanguages:@[@"fr", @"de"]];            // French and German
[params setPushNotificationDeliveryOption:SBDPushNotificationDeliveryOptionDefault];

[groupChannel sendFileMessageWithParams:params completionHandler:^(SBDFileMessage * _Nonnull fileMessage, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
// Sending a file message with a raw file
var thumbnailSizes = [SBDThumbnailSize]()

thumbnailSizes.append(SBDThumbnailSize.make(withMaxCGSize: CGSize(width: 100.0, height: 100.0))!)       // Allowed number of thumbnail images: 3
thumbnailSizes.append(SBDThumbnailSize.make(withMaxWidth: 200.0, maxHeight: 200.0)!)

var params = SBDFileMessageParams()
params.file = FILE                  // Or .fileUrl = FILE_URL (You can also send a file message with a file URL.)
params.fileName = FILE_NAME
params.fileSize = FILE_SIZE
params.mimeType = MIME_TYPE
params.thumbnailSizes = thumbnailSizes
params.customType = CUSTOM_TYPE
params.data = DATA
params.mentionType = SBDMentionTypeUsers        // Either SBDMentionTypeUsers or SBDMentionTypeChannel
params.mentionedUserIds = ["Jeff", "Julia"]     // Or .mentionedUsers = LIST_OF_USERS_TO_MENTION
params.metaArrayKeys = ["linkTo", "itemType"]
params.targetLanguages = ["fr", "de"]           // French and German
params.pushNotificationDeliveryOption = SBDPushNotificationDeliveryOptionDefault

groupChannel.sendFileMessage(with: params) { (fileMessage, error) in
    guard error == nil else {   // Error.
        return
    }
}

If an app goes to the background while uploading a file such as a profile image or a picture, the app can complete the uploading process by using application:handleEventsForBackgroundURLSession:completionHandler: method in your AppDelegate. To complete the uploading, a background event delegate should be added and implemented in the following delegation. If you don't want to upload the file on the background mode, remove the following delegation in the AppDelegate.

Objective-C
Swift
Light Color Skin
Copy
// AppDelegate.m
@implementation AppDelegate

- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler {
    if (completionHandler != nil) {
        completionHandler();
    }
}

@end
Light Color Skin
Copy
// AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
        debugPrint("method for handling events for background URL session is waiting to be process. background session id: \(identifier)")
        completionHandler()
    }
}

Receive messages through a channel delegate

Messages can be received through the didReceiveMessage: method of a SBDChannelDelegate. A SBDBaseMessage object for each received message is one of the following three message types.

  • UserMessage: a text message sent by a user.
  • FileMessage: a binary file message sent by a user.
  • AdminMessage: a text message sent by an admin through the Platform API.

The UNIQUE_DELEGATE_ID is a unique identifier to register multiple concurrent delegates.

Objective-C
Swift
Light Color Skin
Copy
@interface GroupChannelChattingViewController : UIViewController<SBDChannelDelegate>

@end

@implementation GroupChannelChattingViewController

- (void)initGroupChannelChattingViewController {
    [SBDMain addChannelDelegate:self identifier:UNIQUE_DELEGATE_ID];
}

- (void)channel:(SBDBaseChannel * _Nonnull)sender didReceiveMessage:(SBDBaseMessage * _Nonnull)message {
    // TODO: Implement what is needed with the contents of the response in the the 'message' parameter.
    if (message isKindOfClass:[SBDUserMessage class]]) {
        // ...
    }
    else if (message isKindOfClass:[SBDFileMessage class]]) {
        // ...
    }
    else if (message isKindOfClass:[SBDAdminMessage class]]) {
        // ...
    }
}

@end
Light Color Skin
Copy
class GroupChannelChattingViewController: UIViewController, SBDChannelDelegate {
    SBDMain.add(self as SBDChannelDelegate, identifier: self.delegateIdentifier)

    func channel(_ sender: SBDBaseChannel, didReceive message: SBDBaseMessage) {
        // TODO: Implement what is needed with the contents of the response in the the 'message' parameter.
        if message is SBDUserMessage {
            // ...
        }
        else if message is SBDFileMessage {
            // ...
        }
        else if message is SBDAdminMessage {
            // ...
        }
    }
}

If the UI isn't valid anymore, remove the channel delegate.

Objective-C
Swift
Light Color Skin
Copy
[SBDMain removeChannelDelegateForIdentifier:UNIQUE_DELEGATE_ID];
Light Color Skin
Copy
SBDMain.removeChannelDelegate(forIdentifier: UNIQUE_DELEGATE_ID)

Mention other members in a message

When a member wants to call the attention of other members of a group channel, they can mention those members in a message. To do so, you should:

  1. Specify a list of the user IDs to mention.
  2. Add the list to either SBDUserMessageParams or FileMessageParams which may contain options for further action.
  3. Pass the params to either sendUserMessageWithParams:...: or sendFileMessageWithParams:...:.
  4. Then only up to 10 members mentioned in the message will be notified.
Objective-C
Swift
Light Color Skin
Copy
NSMutableArray<NSString *> *userIDsToMention = [[NSMutableArray alloc] init];
[userIDsToMention addObject:@"Harry"];
[userIDsToMention addObject:@"Jay"];
[userIDsToMention addObject:@"Jin"];

SBDUserMessageParams *params = [[SBDUserMessageParams alloc] initWithMessage:MESSAGE];
...
[params setMentionedUserIds:userIDsToMention];

[groupChannel sendUserMessageWithParams:params completionHandler:^(SBDUserMessage * _Nullable userMessage, SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
var userIDsToMention: [String] = []
userIDsToMention.append("Harry")
userIDsToMention.append("Jay")
userIDsToMention.append("Jin")

let params = SBDUserMessageParams(message: MESSAGE)
...
params?.mentionedUserIds = userIDsToMention 

guard let paramsBinded: SBDUserMessageParams = params else {
    return
}

groupChannel.sendUserMessage(with: paramsBinded) { (userMessage, error) in
    guard error == nil else {   // Error. 
        return
    }
}

Load previous messages

By using the loadPreviousMessagesWithLimit:reverse:completionHandler: method of a SBDPreviousMessageListQuery instance which returns a list of SBDBaseMessage objects, you can retrieve a set number of previous messages in a group channel. With a returned list, you can display the past messages in your UI once they have loaded.

Note: You can decide whether a user can see the messages sent prior to the user joining a group channel. In your dashboard, go to the Settings > Application > Messages tab, there is the Chat history option. If turned on, new users are allowed to view a message history in joined group channels. If turned off, new users aren't allowed to see the messages prior to joining a group channel.

Objective-C
Swift
Light Color Skin
Copy
// There should only be one single instance per channel view.
SBDPreviousMessageListQuery *previousMessageQuery = [groupChannel createPreviousMessageListQuery];

...

// Retrieving previous messages.
[self.previousMessageQuery loadPreviousMessagesWithLimit:LIMIT reverse:REVERSE completionHandler:^(NSArray<SBDBaseMessage *> * _Nullable messages, SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
// There should be only one single instance per channel.
let previousMessageQuery = self.groupChannel.createPreviousMessageListQuery()

...

// Retrieving previous messages.
previousMessageQuery?.loadPreviousMessages(withLimit: LIMIT, reverse: REVERSE, completionHandler: { (messages, error) in
    guard error == nil else {   // Error. 
        return
    }
})
ParameterDescription

LIMIT

Type: NSInteger
Specifies the number of results to return per call. Acceptable values are 1 to 100, inclusive. The recommended value for this parameter is 30.

REVERSE

Type: BOOL
Determines whether to sort the retrieved messages in the reversed order. If true, returns a list of messages which the latest comes at first and the earlist at last. the results are sorted in the reversed order. If false, returns a list of messages which the earlist comes at first and the latest at last.

A LIMIT parameter indicates how many messages to be included in a returned list. A SBDPreviousMessageListQuery instance itself does pagination of a result set according to the value of the LIMIT parameter, and internally manages a token to retrieve the next page in the result set.

Each time the loadPreviousMessagesWithLimit:reverse:completionHandler: method is called, the instance retrieves a set number of messages in the next page and then updates the token's value to complete the current call and prepare a next call.

If you create a new query instance and call the loadPreviousMessagesWithLimit:reverse:completionHandler: method, a set number of the most recent messages are retrieved because its token has nothing to do with the previously created instance. So we recommend that you create a single query instance and store it as a member variable for traversing through the entire message history.

Note: Before calling loadPreviousMessagesWithLimit:reverse:completionHandler: method again, you should receive a success callback through the completionHandler first.


Load messages by timestamp or message ID

You can retrieve a set number of messages sent previously before a specific timestamp in a group channel, using the getPreviousMessagesByTimestamp:limit:reverse:messageType:customType:completionHandler: method.

Objective-C
Swift
Light Color Skin
Copy
[groupChannel getPreviousMessagesByTimestamp:TIMESTAMP limit:LIMIT reverse:REVERSE messageType:MESSAGE_TYPE customType:CUSTOM_TYPE completionHandler:^(NSArray<SBDBaseMessage *> * _Nullable messages, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }

    // A list of messages sent before the specified timestamp is successfully retrieved.
}];
Light Color Skin
Copy
groupChannel.getPreviousMessages(byTimestamp: TIMESTAMP, limit: LIMIT, reverse: REVERSE, messageType: MESSAGE_TYPE, customType: CUSTOM_TYPE) { (messages, error) in
    guard error == nil else {   // Error. 
        return
    }

    // A list of messages sent before the specified timestamp is successfully retrieved.
}
ParameterDescription

TIMESTAMP

Type: long long
Specifies the timestamp to be the reference point of a retrieval, in Unix milliseconds.

LIMIT

Type: NSInteger
Specifies the number of messages to retrieve. Note that the actual number of results may be larger than the set value when there are multiple messages with the same timestamp as the earliest message.

REVERSE

Type: BOOL
Determines whether to sort the retrieved messages in the reversed order.

MESSAGE_TYPE

Type: SBDMessageTypeFilter
Specifies the message type to filter the messages with the corresponding type. Acceptable values are SBDMessageTypeFilterAll, SBDMessageTypeFilterUser, SBDMessageTypeFilterFile, and SBDMessageTypeFilterAdmin.

CUSTOM_TYPE

Type: NSString
Specifies the custom message type to filter the messages with the corresponding custom type.

Note: To retrieve messages sent after a specific timestamp, use the getNextMessagesByTimestamp:limit:...: in a similar fashion. You can also retrieve previous and next messages on both sides of a specific timestamp, using the getPreviousAndNextMessagesByTimestamp:prevLimit:nextLimit:...: method.

You can also retrieve a set number of messages sent previously before a specific message ID in a group channel, using the getPreviousMessagesByMessageId:limit:reverse:messageType:customType:completionHandler: method.

Objective-C
Swift
Light Color Skin
Copy
[groupChannel getPreviousMessagesByMessageId:MESSAGE_ID limit:LIMIT reverse:REVERSE messageType:SBDMessageTypeFilterAll customType:CUSTOM_TYPE completionHandler:^(NSArray<SBDBaseMessage *> * _Nullable messages, SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }

    // A list of messages, the IDs of which are ahead of the specified message ID, is successfully retrieved.
}];
Light Color Skin
Copy
groupChannel.getPreviousMessages(byMessageId: MESSAGE_ID, limit: LIMIT, reverse: REVERSE, messageType: MESSAGE_TYPE, customType: CUSTOM_TYPE) { (messages, error) in
    guard error == nil else {   // Error. 
        return
    }

    // A list of messages, the IDs of which are ahead of the specified message ID, is successfully retrieved.
}
ParameterDescription

MESSAGE_ID

Type: long long
Specifies the unique ID of the message to be the reference point of a retrieval.

LIMIT

Type: NSInteger
Specifies the number of messages to retrieve. Note that the actual number of results may be larger than the set value when there are multiple messages with the same timestamp as the earliest message.

REVERSE

Type: BOOL
Determines whether to sort the retrieved messages in the reversed order.

MESSAGE_TYPE

Type: SBDMessageTypeFilter
Specifies the message type to filter the messages with the corresponding type. Acceptable values are SBDMessageTypeFilterAll, SBDMessageTypeFilterUser, SBDMessageTypeFilterFile, and SBDMessageTypeFilterAdmin.

CUSTOM_TYPE

Type: NSString
Specifies the custom message type to filter the messages with the corresponding custom type.

Note: To retrieve messages sent after a specific message ID, use the getNextMessagesByMessageId:limit:...: in a similar fashion. You can also retrieve previous and next messages on both sides of a specific message ID, using the getPreviousAndNextMessagesByMessageId:prevLimit:nextLimit:...: method.


Update a message

A user can update any of their own text and file messages sent. An error is returned if a user attempts to update another user's messages. In addition, channel operators can update any messages sent in a channel.

Objective-C
Swift
Light Color Skin
Copy
// For a text message
SBDUserMessageParams *params = [[SBDUserMessageParams alloc] initWithMessage:NEW_TEXT_MESSAGE];
params.customType = NEW_CUSTOM_TYPE;
params.data = NEW_DATA;

// The USER_MESSAGE_ID below indicates the unique message ID of a UserMessage object to update.
[groupChannel updateUserMessageWithMessageId:USER_MESSAGE_ID userMessageParams:params completionHandler:^(SBDUserMessage * _Nullable userMessage, SBDError * _Nullable error) {
    if (error != nil) {     // Error.
        return;
    }
}];

...

// For a file message
SBDFileMessageParams *params = [[SBDFileMessageParams alloc] initWithFileUrl:NEW_FILE_URL];
params.fileName = NEW_FILE_NAME;
params.fileSize = NEW_FILE_SIZE;
params.data = NEW_DATA;

// The FILE_MESSAGE_ID below indicates the unique message ID of a FileMessage object to update.
[groupChannel updateFileMessageWithMessageId:FILE_MESSAGE_ID fileMessageParams:params completionHandler:^(SBDFileMessage * _Nullable fileMessage, SBDError * _Nullable error) {
    if (error != nil) {     // Error.
        return;
    }
}];
Light Color Skin
Copy
// For a text Message
var params = SBDUserMessageParams(message: NEW_TEXT_MESSAGE)
params.customType = NEW_CUSTOM_TYPE
params.data = NEW_DATA

// The USER_MESSAGE_ID below indicates the unique message ID of a UserMessage object to update.
groupChannel.updateUserMessage(withMessageId: USER_MESSAGE_ID, userMessageParams: params) { (userMessage, error) in
    guard error == nil else {   // Error.
        return
    }
}

...

// For a file message
var params = SBDFileMessageParams(fileUrl: NEW_FILE_URL)
params.fileName = NEW_FILE_NAME
params.fileSize = NEW_FILE_SIZE
params.data = NEW_DATA

// The FILE_MESSAGE_ID below indicates the unique message ID of a FileMessage object to update.
groupChannel.updateFileMessage(withMessageId: FILE_MESSAGE_ID, fileMessageParams: params) { (fileMessage, error) in
    guard error == nil else {   // Error.
        return
    }
}

The didUpdateMessage: method of a channel delegate will receive a callback from the server when a message is updated, and all members of the channel will be notified, including who has updated their own message.

Objective-C
Swift
Light Color Skin
Copy
@interface GroupChanneChattinglViewController : UIViewController<SBDChannelDelegate>

@end

@implementation GroupChannelChattingViewController

- (void)initGroupChannelChattingViewController {
    [SBDMain addChannelDelegate:self identifier:UNIQUE_DELEGATE_ID];
}

- (void)channel:(SBDBaseChannel *)sender didUpdateMessage:(SBDBaseMessage *)message {
    
}

@end 
Light Color Skin
Copy
class GroupChannelChattingViewController: UIViewController, SBDChannelDelegate {
    SBDMain.add(self as SBDChannelDelegate, identifier: self.delegateIdentifier)

    func channel(_ sender: SBDBaseChannel, didUpdate message: SBDBaseMessage) {

    }
}

Delete a message

A user can delete any messages which were sent by themselves. An error is returned if a user attempts to delete the messages of other members. Also channel operators can delete any messages in a channel.

Objective-C
Swift
Light Color Skin
Copy
// The BASE_MESSAGE below indicates a BaseMessage object to delete.
[groupChannel deleteMessage:BASE_MESSAGE completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) {     // Error.
        return;
    }
}];
Light Color Skin
Copy
// The BASE_MESSAGE below indicates a BaseMessage object to delete.
self.groupChannel.delete(BASE_MESSAGE, completionHandler: { (error) in
    guard error == nil else {       // Error.
        return
    }
})

The messageWasDeleted: method of a channel delegate will receive a callback from the server when a message is deleted, and the result also notified to all other members in the channel, including who has deleted their own message.

Objective-C
Swift
Light Color Skin
Copy
@interface GroupChannelChattingViewController : UIViewController<SBDChannelDelegate>

@end

@implementation GroupChannelChattingViewController

- (void)initGroupChannelChattingViewController {
    [SBDMain addChannelDelegate:self identifier:UNIQUE_DELEGATE_ID];
}

- (void)channel:(SBDBaseChannel * _Nonnull)sender messageWasDeleted:(long long)messageId {

}

@end
Light Color Skin
Copy
class GroupChannelChattingViewController: UIViewController, SBDChannelDelegate {
    SBDMain.add(self as SBDChannelDelegate, identifier: UNIQUE_DELEGATE_ID)

    func channel(_ sender: SBDBaseChannel, messageWasDeleted messageId: Int64) {

    }
}

Clear the chat history

By using the resetMyHistoryWithCompletionHandler: method, you can help the current user clear the chat history in a group channel and start a fresh conversation with other members in the same channel. As the method's name implies, the chat history will be cleared only from the channel view of the current user, and will no longer be shown in that view. But the messages are not deleted from the database of the SendBird system, and other members can still see all the messages in their channel views.

This method simply clears the messages for the user by updating the lastMessage and readReceipts properties of a group channel object in addition to other internally managed data such as the number of the user’s unread message.

Note: This ability is effective only when the Chat history option is turned on in your dashboard under Settings > Application > Messages.

Objective-C
Swift
Light Color Skin
Copy
[groupChannel resetMyHistoryWithCompletionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
groupChannel?.resetMyHistory(completionHandler: { (error) in
    guard error == nil else {   // Error.
        return
    }
})

When a user is online, all data associated with the group channels they are a member of are automatically updated by the SendBird instance. However, when a user is disconnected from SendBird server and reconnects later, you should call the refreshWithCompletionHandler: method to update the channels with the latest information.

Objective-C
Swift
Light Color Skin
Copy
[groupChannel refreshWithCompletionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
groupChannel?.refresh(completionHandler: { (error) in
    guard error == nil else {   // Error.
            return
    }
})

Note: If you want to make your users see the channels updated to the most recent when their client apps are in the foreground, we recommend you call the refreshWithCompletionHandler: in the didSucceedReconnection method which receives a callback from SendBird server when successfully reconnected.


Retrieve a list of all members

You can retrieve a list of members in a group channel using the members property of a SBDGroupChannel object.

Objective-C
Swift
Light Color Skin
Copy
NSArray<SBDMember *> *members = [channel members];
Light Color Skin
Copy
let members = channel?.members

Members of a group channel are automatically updated when a user is online. But when a user is disconnected from SendBird server and then reconnected, you should use the refreshWithCompletionHandler: method to update their channels with the latest information. See the Refresh all data related to a group channel section for the sample code.


Retrieve the online status of members

To stay updated on the online status of each member in a group channel, call the refreshWithCompletionHandler: method before using the members property of a SBDGroupChannel object to retrieve the members of the channel.

By checking the connectionStatus property of each SBDMember object in the members property, you can then retrieve the user's current connection status. The connectionStatus property has one of the following two values:

Objective-C
  • SBDUserConnectionStatusOffline: the user is not connected to SendBird server.
  • SBDUserConnectionStatusOnline: the user is connected to SendBird server.
Swift
  • SBDUserConnectionStatus.offline: the user is not connected to SendBird server.
  • SBDUserConnectionStatus.online: the user is connected to SendBird server.

Note: If your client app needs to keep track of the connection status of users in real time, we recommend that you call periodically the loadNextPageWithCompletionHandler: method of a SBDApplicationUserListQuery instance after specifying its userIdsFilter filter, perhaps in intervals of one minute or more.


Retrieve a list of banned or muted users

You can create a query to get a list of banned or muted users from a group channel. This query is only available for users who are registered as operators of a group channel.

Objective-C
Swift
Light Color Skin
Copy
// Retrieving banned users 
SBDBannedUserListQuery *bannedListQuery = [groupChannel createBannedUserListQuery];
[bannedListQuery loadNextPageWithCompletionHandler:^(NSArray<SBDUser *> * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];

// Retrieving muted users
SBDGroupChannelMemberListQuery *memberUserListQuery = [groupChannel createMemberListQuery];
[memberUserListQuery setMutedMemberFilter:SBDGroupChannelMutedMemberFilterMuted];
[memberUserListQuery loadNextPageWithCompletionHandler:^(NSArray<SBDMember *> * _Nullable users, SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }
}];
Light Color Skin
Copy
// Retrieving banned users 
let bannedListQuery = groupChannel.createBannedUserListQuery()
bannedListQuery?.loadNextPage(completionHandler: { (users, error) in
    guard error == nil else {   // Error. 
        return
    }
})

// Retrieving muted users
let memberUserListQuery = groupChannel?.createMemberListQuery()
memberUserListQuery?.mutedMemberFilter = SBDGroupChannelMutedMemberFilter.muted
memberUserListQuery?.loadNextPage(completionHandler: { (members, error) in
    guard error == nil else {   // Error. 
        return
    }
})

Ban and unban a user

Operators of a group channel can remove any users that behave inappropriately in the channel by using our Ban feature. Banned users are immediately expelled from a channel and allowed to join the channel again after the time period set by the operators. The operators can ban and unban users from group channels using the following code.

Objective-C
Swift
Light Color Skin
Copy
[SBDGroupChannel getChannelWithUrl:CHANNEL_URL completionHandler:^(SBDGroupChannel * _Nullable groupChannel, SBDError * _Nullable error) {
    if (error != nil) { // Error. 
        return;
    }

    if (groupChannel.myRole == SBDRoleOperator) {
        [groupChannel banUser:USER seconds:SECONDS description:DESCRIPTION completionHandler:^(SBDError * _Nullable error) {
            if (error != nil) { // Error. 
                return;
            }
            
            // Custom implementation for what should be done after banning.
        }];

        [groupChannel unbanUser:USER completionHandler:^(SBDError * _Nullable error) {
            if (error != nil) { // Error. 
                return;
            }

            // Custom implementation for what should be done after unbanning.
        }];
    }
}];
Light Color Skin
Copy
SBDGroupChannel.getWithUrl(CHANNEL_URL) { (groupChannel, error) in
    guard error == nil else {   // Error. 
        return
    }

    if groupChannel?.myRole == SBDRole.operator {
        groupChannel?.ban(USER, seconds: SECONDS, description: DESCRIPTION, completionHandler: { (error) in
            guard error == nil else {   // Error.
                return
            }

            // Custom implementation for what should be done after banning.
        })

        groupChannel?.unbanUser(USER, completionHandler: { (error) in
            guard error == nil else {   // Error.
                return
            }
            
            // Custom implementation for what should be done after unbanning.
        })
    }
}

Note: Instead of banUser:seconds:completionHandler: and unbanUser:completionHandler: methods, you can use banUserWithUserId:seconds:completionHandler: and unbanUserWithUserId:completionHandler:, as they have the same abilities.


Mute and unmute a user

Operators of a group channel can prohibit the selected users from sending messages using our Mute feature. Muted users remain in the channel and are allowed to view the messages, but can't send any messages until the operators unmute them. Operators can mute and unmute users in the channel using the following code:

Objective-C
Swift
Light Color Skin
Copy
[SBDGroupChannel getChannelWithUrl:CHANNEL_URL completionHandler:^(SBDGroupChannel * _Nullable groupChannel, SBDError * _Nullable error) {
    if (groupChannel.myRole == SBDRoleOperator) {
        [groupChannel muteUser:USER completionHandler:^(SBDError * _Nullable error) {
            if (error != nil) { // Error. 
                return;
            }
            
            // TODO: Custom implementation for what should be done after muting.
        }];

        [groupChannel unmuteUser:USER completionHandler:^(SBDError * _Nullable error) {
            if (error != nil) { // Error. 
                return;
            }
            
            // TODO: Custom implementation for what should be done after unbanning.
        }];
    }
}];
Light Color Skin
Copy
SBDGroupChannel.getWithUrl(CHANNEL_URL) { (groupChannel, error) in
    if groupChannel?.myRole == SBDRole.operator {
        groupChannel?.muteUser(USER, completionHandler: { (error) in
            guard error == nil else {   // Error.
                return
            }

            // TODO: Custom implementation for what should be done after muting.
        })

        groupChannel?.unmuteUser(USER, completionHandler: { (error) in
            guard error == nil else {   // Error.
                return
            }

            // TODO: Custom implementation for what should be done after unbanning.
        })
    }
}

Note: Instead of muteUser:completionHandler: and unmuteUser:completionHandler:methods, you can also use muteUserWithUserId:completionHandler: and unmuteUserWithUserId:completionHandler:, as they have the same abilities.


Report a message, a user, or a channel

In a group channel, a user can report suspicious or harrassing messages as well as the other users who use abusive language. The user can also report channels if there are any inappropriate content or activity within the channel. Based on this feature and our report API, you can build your own in-app system for managing objectionable content and subject.

Objective-C
Swift
Light Color Skin
Copy
// Reporting a message
[groupChannel reportMessage:MESSAGE_TO_REPORT reportCategory:REPORT_CATEGORY reportDescription:DESCRIPTION completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];

// Reporting a user
[groupChannel reportUser:OFFENDING_USER reportCategory:REPORT_CATEGORY reportDescription:DESCRIPTION completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];

// Reporting a channel
[groupChannel reportWithCategory:REPORT_CATEGORY reportDescription:DESCRIPTION completionHandler:^(SBDError * _Nullable error) {
    if (error != nil) { // Error.
        return;
    }
}];
Light Color Skin
Copy
// Reporting a message
groupChannel.reportMessage(MESSAGE_TO_REPORT, reportCategory: REPORT_CATEGORY, reportDescription: DESCRIPTION, completionHandler: { (error) in
    guard error == nil else {   // Error.
        return
    }
})

// Reporting a user
groupChannel.reportUser(OFFENDING_USER, reportCategory: REPORT_CATEGORY, reportDescription: DESCRIPTION, completionHandler: { (error) in
    guard error == nil else {   // Error.
        return
    }
})

// Reporting a channel
groupChannel.report(withCategory: REPORT_CATEGORY, reportDescription: DESCRIPTION, completionHandler: { (error) in
    guard error == nil else {   // Error.
        return
    }
})
ParameterTypeDescription

MESSAGE_TO_REPORT

object

Specifies the message to report for its suspicious, harassing, or inappropriate content.

OFFENDING_USER

object

Specifies the user who uses offensive or abusive language such as sending explicit messages or inappropriate comments.

REPORT_CATEGORY

enum

Specifies a report category which indicates the reason for reporting. Acceptable values are SBDReportCategorySuspicious, SBDReportCategoryHarassing, SBDReportCategoryInappropriate, and SBDReportCategorySpam.

DESCRIPTION

string

Specifies additional information to include in the report.