Retrieve subchannel list
You can retrieve subchannel lists using both client-side SDK methods and the Server API. Choose the approach that best fits your use case.
Retrieve the full subchannel list from the server
Get the complete subchannel list for a community channel through the Server API (/v4/community-channel/subchannel/list).
A single user can join up to 100 community channels and create or join up to 50 subchannels within each community.
The Chat SDK generates a local subchannel list based on messages in the local database. This list only includes subchannels that have local messages and may not represent the complete list. We recommend maintaining the subchannel list on your app server.
Your app server can also organize subchannels into groups, as shown in the UI framework design in the Community channel overview.
Retrieve local subchannels
The Chat SDK creates local channel records from sent and received messages. In Swift, call getSubChannels(completion:) on a CommunityChannel instance to retrieve the locally cached subchannels for one community. The Objective-C equivalent is shown in the secondary tab.
- Swift
- Objective-C
import NexconnChatSDK
guard let community = CommunityChannel(channelId: "communityId") else {
return
}
community.getSubChannels { channels, error in
guard let channels, error == nil else {
print("Failed to retrieve subchannels: \(error?.localizedDescription ?? "unknown error")")
return
}
for channel in channels {
print(
"Subchannel ID: \(channel.subChannelId), unread: \(channel.unreadCount), mentions: \(channel.mentionedCount)"
)
}
}
NCCommunityChannel *community = [[NCCommunityChannel alloc] initWithChannelId:@"communityId"];
[community getSubChannelsWithCompletion:^(NSArray<NCCommunitySubChannel *> * _Nullable channels, NCError * _Nullable error) {
if (error == nil) {
for (NCCommunitySubChannel *channel in channels) {
NSLog(@"Subchannel ID: %@, unread: %d, mentions: %d",
channel.subChannelId,
channel.unreadCount,
channel.mentionedCount);
}
} else {
NSLog(@"Failed to retrieve subchannels: %@", error);
}
}];
API reference
- Swift
- Objective-C
import NexconnChatSDK
func getSubChannels(completion: @escaping OperationHandler<[CommunitySubChannel]>)
- (void)getSubChannelsWithCompletion:(void (^)(NSArray<NCCommunitySubChannel *> * _Nullable channels, NCError * _Nullable error))completion;
The result excludes the main channel itself and only includes subchannel conversations that have a subChannelId.
Community channel operations
Create a community channel instance
- Swift
- Objective-C
import NexconnChatSDK
guard let community = CommunityChannel(channelId: "communityId") else {
return
}
NCCommunityChannel *community = [[NCCommunityChannel alloc] initWithChannelId:@"communityId"];
Get the unread message count
Use getUnreadCount(completion:) on the current community to read the locally tracked unread total for that community:
- Swift
- Objective-C
import NexconnChatSDK
func getUnreadCount(completion: ChannelUnreadCountHandler?)
- (void)getUnreadCountWithCompletion:(void (^)(NSInteger unreadCount, NCError * _Nullable error))completion;
- Swift
- Objective-C
import NexconnChatSDK
guard let community = CommunityChannel(channelId: "communityId") else {
return
}
community.getUnreadCount { unreadCount, error in
if let error {
print("Failed to get unread count: \(error.localizedDescription)")
return
}
print("Community unread count: \(unreadCount)")
}
NCCommunityChannel *community = [[NCCommunityChannel alloc] initWithChannelId:@"communityId"];
[community getUnreadCountWithCompletion:^(NSInteger unreadCount, NCError * _Nullable error) {
if (error == nil) {
NSLog(@"Community unread count: %ld", (long)unreadCount);
} else {
NSLog(@"Failed to get unread count: %@", error);
}
}];