Skip to main content

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

Dart
static Future\<int\> getChannels(GetChannelsParams params, OprationHandler\<List\<BaseChannel\\>> handler);

Parameters

ParameterTypeDescription
paramsGetChannelsParamsQuery parameters
handlerOprationHandler\<List\<BaseChannel\\>>Result callback returning the channel list

GetChannelsParams properties

PropertyTypeDefaultDescription
identifiersList\<ChannelIdentifier\>RequiredChannel identifiers including type and ID
startTimeint0Timestamp (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.
countint20Page size (0 < count ≤ 50)

ChannelIdentifier properties

PropertyTypeDescription
channelTypeChannelTypeChannel type
channelIdStringChannel ID
subChannelIdString?Subchannel ID (community channels only)

Code example

Dart
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

Dart
Future\<int\> reload(OprationHandler\<BaseChannel\> handler);

Code example

Dart
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

Dart
static Future\<int\> getUnreadChannels(List\<ChannelType\> types, OprationHandler\<List\<BaseChannel\\>> handler);

Code example

Dart
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.