Skip to main content

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.

tip

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
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)"
)
}
}

API reference

swift
import NexconnChatSDK

func getSubChannels(completion: @escaping OperationHandler<[CommunitySubChannel]>)

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
import NexconnChatSDK

guard let community = CommunityChannel(channelId: "communityId") else {
return
}

Get the unread message count

Use getUnreadCount(completion:) on the current community to read the locally tracked unread total for that community:

swift
import NexconnChatSDK

func getUnreadCount(completion: ChannelUnreadCountHandler?)
swift
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)")
}