Get channels
The client SDK generates channels in the local database based on sent and received messages. Retrieve the channel list from the local database.
Get the channel list
Retrieve channels from the local database with pagination. Channels are sorted by time (newest first), with pinned channels at the top.
Method
static Future\<int\> getChannels(GetChannelsParams params, OprationHandler\<List\<BaseChannel\\>> handler);
Parameters
| Parameter | Type | Description |
|---|---|---|
| params | GetChannelsParams | Query parameters |
| handler | OprationHandler\<List\<BaseChannel\\>> | Result callback returning the channel list |
GetChannelsParams properties
| Property | Type | Default | Description |
|---|---|---|---|
identifiers | List\<ChannelIdentifier\> | Required | Channel identifiers including type and ID |
startTime | int | 0 | Timestamp (ms). Retrieves channels older than this time. Pass 0 for the latest. For pagination, pass the operationTime of the last channel from the previous page. |
count | int | 20 | Page size (0 < count ≤ 50) |
ChannelIdentifier properties
| Property | Type | Description |
|---|---|---|
channelType | ChannelType | Channel type |
channelId | String | Channel ID |
subChannelId | String? | Subchannel ID (community channels only) |
Code example
final params = GetChannelsParams(
identifiers: [
ChannelIdentifier(channelType: ChannelType.direct, channelId: 'user1'),
ChannelIdentifier(channelType: ChannelType.group, channelId: 'group1'),
],
startTime: 0,
count: 20,
);
int? ret = await BaseChannel.getChannels(params, (List\<BaseChannel\>? channels, NCError? error) {
if (error == null || error.isSuccess) {
print('Channel count: ${channels?.length}');
} else {
print('Failed, error code: ${error.code}');
}
});
Reload a channel
Reload the latest details for a specific channel from the local database. This is a BaseChannel instance method.
Method
Future\<int\> reload(OprationHandler\<BaseChannel\> handler);
Code example
BaseChannel channel = ...;
int? ret = await channel.reload((BaseChannel? updated, NCError? error) {
if (error == null || error.isSuccess) {
print('Unread count: ${updated?.unreadCount}');
}
});
Get channels with unread messages
Retrieve channels that have unread messages. Supports direct, group, and system channels. Channels are sorted by time (newest first) with pinned channels at the top.
Method
static Future\<int\> getUnreadChannels(List\<ChannelType\> types, OprationHandler\<List\<BaseChannel\\>> handler);
Code example
final types = [ChannelType.direct, ChannelType.group, ChannelType.system];
int? ret = await BaseChannel.getUnreadChannels(types, (List\<BaseChannel\>? channels, NCError? error) {
if (error == null || error.isSuccess) {
print('Channels with unread messages: ${channels?.length}');
}
});
FAQ
Q: After reinstalling the app, the channel list is empty or partially missing?
A: The channel list is stored in the SDK's local database, which is cleared when the app is uninstalled. If missed message compensation is enabled, logging in on a new device triggers compensation to retrieve some historical channels (default: current day). To extend the compensation period (up to 7 days), submit a ticket. Setting a long period may cause processing pressure on clients with high message volumes.