Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Upcoming

🔄 Changed

- Deprecated `SortOption.new` constructor in favor of `SortOption.desc` and `SortOption.asc`.

## 9.13.0

- Bug fixes and improvements
Expand Down
1 change: 1 addition & 0 deletions packages/stream_chat/lib/src/core/api/sort_order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SortOption<T extends ComparableFieldProvider> {
/// ```dart
/// final sorting = SortOption("last_message_at") // Default: descending order
/// ```
@Deprecated('Use SortOption.desc or SortOption.asc instead')
const SortOption(
this.field, {
this.direction = SortOption.DESC,
Expand Down
4 changes: 2 additions & 2 deletions packages/stream_chat/test/src/client/channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ void main() {

test('should work fine with `query`', () async {
const query = 'test-search-query';
const sort = [SortOption('test-sort-field')];
const sort = [SortOption.asc('test-sort-field')];
const pagination = PaginationParams();

final results = List.generate(3, (index) => GetMessageResponse());
Expand Down Expand Up @@ -1306,7 +1306,7 @@ void main() {

test('should work fine with `messageFilters`', () async {
final messageFilters = Filter.query('key', 'text');
const sort = [SortOption('test-sort-field')];
const sort = [SortOption.desc('test-sort-field')];
const pagination = PaginationParams();

final results = List.generate(3, (index) => GetMessageResponse());
Expand Down
4 changes: 2 additions & 2 deletions packages/stream_chat/test/src/client/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,7 @@ void main() {

test('`.queryPolls`', () async {
final filter = Filter.in_('id', const ['test-poll-id']);
final sort = [const SortOption<Poll>('created_at')];
final sort = [const SortOption<Poll>.desc('created_at')];
const pagination = PaginationParams(limit: 20);

final polls = List.generate(
Expand Down Expand Up @@ -2285,7 +2285,7 @@ void main() {
test('`.queryPollVotes`', () async {
const pollId = 'test-poll-id';
final filter = Filter.in_('id', const ['test-vote-id']);
final sort = [const SortOption<PollVote>('created_at')];
final sort = [const SortOption<PollVote>.desc('created_at')];
const pagination = PaginationParams(limit: 20);

final votes = List.generate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void main() {
const channelType = 'test-channel-type';

final filter = Filter.in_('cid', const ['test-cid']);
const sort = [SortOption<ChannelState>('test-field')];
const sort = [SortOption<ChannelState>.desc('test-field')];
const memberLimit = 33;
const messageLimit = 33;

Expand Down
10 changes: 5 additions & 5 deletions packages/stream_chat/test/src/core/api/general_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void main() {
'should throw if `pagination.offset` and `sort` both are provided',
() async {
final filter = Filter.in_('cid', const ['test-cid-1', 'test-cid-2']);
const sort = [SortOption('test-field')];
const sort = [SortOption.desc('test-field')];
const pagination = PaginationParams(offset: 10);
try {
await generalApi.searchMessages(
Expand All @@ -103,7 +103,7 @@ void main() {
test('should run successfully with `query`', () async {
final filter = Filter.in_('cid', const ['test-cid-1', 'test-cid-2']);
const query = 'test-query';
const sort = [SortOption('test-field')];
const sort = [SortOption.desc('test-field')];
const pagination = PaginationParams();

const path = '/search';
Expand Down Expand Up @@ -142,7 +142,7 @@ void main() {

test('should run successfully with `messageFilter`', () async {
final filter = Filter.in_('cid', const ['test-cid-1', 'test-cid-2']);
const sort = [SortOption('test-field')];
const sort = [SortOption.desc('test-field')];
final messageFilter = Filter.query('key', 'text');
const pagination = PaginationParams();

Expand Down Expand Up @@ -187,7 +187,7 @@ void main() {
const channelId = 'test-channel-id';
final filter = Filter.in_('cid', const ['test-cid-1', 'test-cid-2']);
const pagination = PaginationParams();
const sort = [SortOption<Member>('test-field')];
const sort = [SortOption<Member>.desc('test-field')];

const path = '/members';

Expand Down Expand Up @@ -234,7 +234,7 @@ void main() {
const channelType = 'test-channel-type';
final filter = Filter.in_('cid', const ['test-cid-1', 'test-cid-2']);
const pagination = PaginationParams();
const sort = [SortOption<Member>('test-field')];
const sort = [SortOption<Member>.desc('test-field')];

const path = '/members';

Expand Down
4 changes: 2 additions & 2 deletions packages/stream_chat/test/src/core/api/polls_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void main() {
test('queryPolls', () async {
const path = '/polls/query';
final filter = Filter.in_('cid', const ['test-cid-1', 'test-cid-2']);
const sort = [SortOption<Poll>('test-field')];
const sort = [SortOption<Poll>.desc('test-field')];
const pagination = PaginationParams(limit: 20);

final payload = jsonEncode({
Expand Down Expand Up @@ -381,7 +381,7 @@ void main() {
test('queryPollVotes', () async {
const pollId = 'test-poll-id';
final filter = Filter.in_('cid', const ['test-cid-1', 'test-cid-2']);
const sort = [SortOption<PollVote>('test-field')];
const sort = [SortOption<PollVote>.desc('test-field')];
const pagination = PaginationParams(limit: 20);

const path = '/polls/$pollId/votes';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void main() {
test('should query reminders with filter, sort, and pagination', () async {
const path = '/reminders/query';
final filter = Filter.equal('userId', 'test-user-id');
const sort = [SortOption<MessageReminder>('remindAt')];
const sort = [SortOption<MessageReminder>.desc('remindAt')];
const pagination = PaginationParams(limit: 10, offset: 5);

final expectedPayload = jsonEncode({
Expand Down
6 changes: 0 additions & 6 deletions packages/stream_chat/test/src/core/api/sort_order_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ void main() {
expect(j, {'field': 'name', 'direction': -1});
});

test('should create a SortOption with default DESC direction', () {
const option = SortOption<TestModel>('name');
expect(option.field, 'name');
expect(option.direction, SortOption.DESC);
});

test('should create a SortOption with ASC direction', () {
const option = SortOption<TestModel>.asc('age');
expect(option.field, 'age');
Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat/test/src/core/api/user_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
test('queryUsers', () async {
const presence = true;
final filter = Filter.in_('cid', const ['test-cid-1', 'test-cid-2']);
const sort = [SortOption<User>('test-field')];
const sort = [SortOption<User>.desc('test-field')];
const pagination = PaginationParams();

const path = '/users';
Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
'members',
[StreamChat.of(context).currentUser!.id],
),
channelStateSort: const [SortOption('last_message_at')],
channelStateSort: const [SortOption.desc('last_message_at')],
limit: 20,
);

Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat_flutter/example/lib/split_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
'members',
[StreamChat.of(context).currentUser!.id],
),
channelStateSort: const [SortOption('last_message_at')],
channelStateSort: const [SortOption.desc('last_message_at')],
limit: 20,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
'members',
[StreamChat.of(context).currentUser!.id],
),
channelStateSort: const [SortOption('last_message_at')],
channelStateSort: const [SortOption.desc('last_message_at')],
);

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
'members',
[StreamChat.of(context).currentUser!.id],
),
channelStateSort: const [SortOption('last_message_at')],
channelStateSort: const [SortOption.desc('last_message_at')],
limit: 20,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
'members',
[StreamChat.of(context).currentUser!.id],
),
channelStateSort: const [SortOption('last_message_at')],
channelStateSort: const [SortOption.desc('last_message_at')],
limit: 20,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
'members',
[StreamChat.of(context).currentUser!.id],
),
channelStateSort: const [SortOption('last_message_at')],
channelStateSort: const [SortOption.desc('last_message_at')],
limit: 20,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
'members',
[StreamChat.of(context).currentUser!.id],
),
channelStateSort: const [SortOption('last_message_at')],
channelStateSort: const [SortOption.desc('last_message_at')],
limit: 20,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
Filter.autoComplete('id', query),
Filter.autoComplete('name', query),
]),
sort: [const SortOption('id', direction: SortOption.ASC)],
sort: [const SortOption.asc('id')],

Check warning on line 163 in packages/stream_chat_flutter/lib/src/autocomplete/stream_mention_autocomplete_options.dart

View check run for this annotation

Codecov / codecov/patch

packages/stream_chat_flutter/lib/src/autocomplete/stream_mention_autocomplete_options.dart#L163

Added line #L163 was not covered by tests
);
return response.users;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const defaultChannelPagedLimit = 10;

/// The default sort used for the channel list.
const defaultChannelListSort = [
SortOption<ChannelState>(ChannelSortKey.lastUpdated),
SortOption<ChannelState>.desc(ChannelSortKey.lastUpdated),
];

const _kDefaultBackendPaginationLimit = 30;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const defaultMemberPagedLimit = 10;

/// The default sort used for the member list.
const defaultMemberListSort = [
SortOption<Member>(
MemberSortKey.createdAt,
direction: SortOption.ASC,
),
SortOption<Member>.asc(MemberSortKey.createdAt),
];

const _kDefaultBackendPaginationLimit = 30;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const defaultPollVotePagedLimit = 10;

/// The default sort used for the poll vote list.
const defaultPollVoteListSort = [
SortOption<PollVote>(
PollVoteSortKey.createdAt,
direction: SortOption.ASC,
),
SortOption<PollVote>.asc(PollVoteSortKey.createdAt),
];

const _kDefaultBackendPaginationLimit = 30;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const defaultUserPagedLimit = 10;

/// The default sort used for the user list.
const defaultUserListSort = [
SortOption<User>(UserSortKey.createdAt),
SortOption<User>.desc(UserSortKey.createdAt),
];

const _kDefaultBackendPaginationLimit = 30;
Expand Down
7 changes: 1 addition & 6 deletions sample_app/lib/pages/new_group_chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {

late final userListController = StreamUserListController(
client: StreamChat.of(context).client,
sort: [
const SortOption(
'name',
direction: 1,
),
],
sort: [const SortOption.asc('name')],
limit: 25,
filter: Filter.and([
Filter.notEqual('id', StreamChat.of(context).currentUser!.id),
Expand Down
7 changes: 1 addition & 6 deletions sample_app/lib/pages/user_mentions_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ class _UserMentionsPageState extends State<UserMentionsPage> {
key: 'mentioned_users.id',
value: StreamChat.of(context).currentUser!.id,
),
sort: [
const SortOption(
'created_at',
direction: SortOption.ASC,
),
],
sort: [const SortOption.asc('created_at')],
limit: 20,
);
@override
Expand Down
8 changes: 4 additions & 4 deletions sample_app/lib/widgets/channel_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class _ChannelList extends State<ChannelList> {
limit: 5,
searchQuery: '',
sort: [
const SortOption(ChannelSortKey.pinnedAt),
const SortOption(ChannelSortKey.createdAt, direction: SortOption.ASC),
const SortOption.desc(ChannelSortKey.pinnedAt),
const SortOption.asc(ChannelSortKey.createdAt),
],
);

Expand Down Expand Up @@ -57,11 +57,11 @@ class _ChannelList extends State<ChannelList> {
client: StreamChat.of(context).client,
filter: Filter.in_('members', [StreamChat.of(context).currentUser!.id]),
channelStateSort: [
const SortOption(
const SortOption.desc(
ChannelSortKey.pinnedAt,
nullOrdering: NullOrdering.nullsLast,
),
const SortOption(ChannelSortKey.lastMessageAt),
const SortOption.desc(ChannelSortKey.lastMessageAt),
],
limit: 30,
);
Expand Down