Merge remote-tracking branch 'origin/v7.0.0'

This commit is contained in:
Efthymis Sarmpanis
2023-12-04 12:16:34 +02:00
188 changed files with 4662 additions and 4119 deletions
@@ -1,3 +1,8 @@
## 7.0.0
- Updated minimum supported `SDK` version to Flutter 3.13/Dart 3.1
- 🛑 **BREAKING** Removed deprecated `getChannelStates.sort` parameter. Use `getChannelStates.channelStateSort` instead.
## 6.10.0
- Updated `stream_chat` dependency to [`6.10.0`](https://pub.dev/packages/stream_chat/changelog).
@@ -15,6 +20,7 @@
- [[#1683]](https://github.com/GetStream/stream-chat-flutter/issues/1683) Fixed SqliteException no such
column `messages.state`.
- Updated `stream_chat` dependency to [`6.7.0`](https://pub.dev/packages/stream_chat/changelog).
## 6.6.0
@@ -4,8 +4,8 @@ publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.10.0"
sdk: ">=3.1.0 <4.0.0"
flutter: ">=3.13.0"
dependencies:
cupertino_icons: ^1.0.3
@@ -251,38 +251,35 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
@override
Future<List<ChannelState>> getChannelStates({
Filter? filter,
@Deprecated('Use channelStateSort instead.')
List<SortOption<ChannelModel>>? sort,
List<SortOption<ChannelState>>? channelStateSort,
PaginationParams? paginationParams,
}) async {
assert(_debugIsConnected, '');
assert(
sort == null || channelStateSort == null,
'sort and channelStateSort cannot be used together',
);
assert(() {
if (channelStateSort?.any((it) => it.comparator == null) ?? false) {
throw ArgumentError(
'SortOption requires a comparator in order to sort',
);
}
return true;
}(), '');
_logger.info('getChannelStates');
final channels = await db!.channelQueryDao.getChannels(
filter: filter,
sort: sort,
);
final channels = await db!.channelQueryDao.getChannels(filter: filter);
final channelStates = await Future.wait(
channels.map((e) => getChannelStateByCid(e.cid)),
);
// Only sort the channel states if the channels are not already sorted.
if (sort == null) {
var comparator = _defaultChannelStateComparator;
if (channelStateSort != null && channelStateSort.isNotEmpty) {
comparator = _combineComparators(
channelStateSort.map((it) => it.comparator).withNullifyer,
);
}
channelStates.sort(comparator);
// Sort the channel states
var comparator = _defaultChannelStateComparator;
if (channelStateSort != null && channelStateSort.isNotEmpty) {
comparator = _combineComparators(
channelStateSort.map((it) => it.comparator).withNullifyer,
);
}
channelStates.sort(comparator);
final offset = paginationParams?.offset;
if (offset != null && offset > 0 && channelStates.isNotEmpty) {
@@ -1,13 +1,13 @@
name: stream_chat_persistence
homepage: https://github.com/GetStream/stream-chat-flutter
description: Official Stream Chat Persistence library. Build your own chat experience using Dart and Flutter.
version: 6.10.0
version: 7.0.0
repository: https://github.com/GetStream/stream-chat-flutter
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues
environment:
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.10.0"
sdk: ">=3.1.0 <4.0.0"
flutter: ">=3.13.0"
dependencies:
drift: ^2.11.0
@@ -18,7 +18,7 @@ dependencies:
path: ^1.8.3
path_provider: ^2.1.0
sqlite3_flutter_libs: ^0.5.15
stream_chat: ^6.10.0
stream_chat: ^7.0.0
dev_dependencies:
build_runner: ^2.4.6
@@ -148,7 +148,6 @@ void main() {
// Should match with the inserted channels
final updatedChannels = await channelQueryDao.getChannels(
filter: filter,
// ignore: deprecated_member_use_from_same_package
sort: [
SortOption(
'member_count',
@@ -196,7 +195,6 @@ void main() {
// Should match with the inserted channels
final updatedChannels = await channelQueryDao.getChannels(
filter: filter,
// ignore: deprecated_member_use_from_same_package
sort: [SortOption('test_custom_field', comparator: sortComparator)],
);
@@ -245,64 +245,81 @@ void main() {
.called(1);
});
test('getChannelStates', () async {
const cid = 'testType:testId';
final channels = List.generate(3, (index) => ChannelModel(cid: cid));
final messages = List.generate(3, (index) => Message());
final members = List.generate(3, (index) => Member());
final reads = List.generate(
3,
(index) => Read(
user: User(id: 'testUserId$index'),
lastRead: DateTime.now(),
),
);
final channel = ChannelModel(cid: cid);
final channelStates = channels
.map(
(channel) => ChannelState(
channel: channel,
messages: messages,
pinnedMessages: messages,
members: members,
read: reads,
),
)
.toList(growable: false);
group('getChannelState', () {
test('should throw if sort is provided without comparator', () async {
final sort = [
const SortOption<ChannelState>(
'testField',
direction: SortOption.ASC,
),
];
when(() => mockDatabase.channelQueryDao.getChannels())
.thenAnswer((_) async => channels);
when(() => mockDatabase.memberDao.getMembersByCid(cid))
.thenAnswer((_) async => members);
when(() => mockDatabase.readDao.getReadsByCid(cid))
.thenAnswer((_) async => reads);
when(() => mockDatabase.channelDao.getChannelByCid(cid))
.thenAnswer((_) async => channel);
when(() => mockDatabase.messageDao.getMessagesByCid(cid))
.thenAnswer((_) async => messages);
when(() => mockDatabase.pinnedMessageDao.getMessagesByCid(cid))
.thenAnswer((_) async => messages);
expect(
() => client.getChannelStates(channelStateSort: sort),
throwsA(isA<ArgumentError>()),
);
});
final fetchedChannelStates = await client.getChannelStates();
expect(fetchedChannelStates.length, channelStates.length);
test('should work fine', () async {
const cid = 'testType:testId';
final channels = List.generate(3, (index) => ChannelModel(cid: cid));
final messages = List.generate(3, (index) => Message());
final members = List.generate(3, (index) => Member());
final reads = List.generate(
3,
(index) => Read(
user: User(id: 'testUserId$index'),
lastRead: DateTime.now(),
),
);
final channel = ChannelModel(cid: cid);
final channelStates = channels
.map(
(channel) => ChannelState(
channel: channel,
messages: messages,
pinnedMessages: messages,
members: members,
read: reads,
),
)
.toList(growable: false);
for (var i = 0; i < fetchedChannelStates.length; i++) {
final original = channelStates[i];
final fetched = fetchedChannelStates[i];
expect(fetched.members?.length, original.members?.length);
expect(fetched.messages?.length, original.messages?.length);
expect(fetched.pinnedMessages?.length, original.pinnedMessages?.length);
expect(fetched.read?.length, original.read?.length);
expect(fetched.channel!.cid, original.channel!.cid);
}
when(() => mockDatabase.channelQueryDao.getChannels())
.thenAnswer((_) async => channels);
when(() => mockDatabase.memberDao.getMembersByCid(cid))
.thenAnswer((_) async => members);
when(() => mockDatabase.readDao.getReadsByCid(cid))
.thenAnswer((_) async => reads);
when(() => mockDatabase.channelDao.getChannelByCid(cid))
.thenAnswer((_) async => channel);
when(() => mockDatabase.messageDao.getMessagesByCid(cid))
.thenAnswer((_) async => messages);
when(() => mockDatabase.pinnedMessageDao.getMessagesByCid(cid))
.thenAnswer((_) async => messages);
verify(() => mockDatabase.channelQueryDao.getChannels()).called(1);
verify(() => mockDatabase.memberDao.getMembersByCid(cid)).called(3);
verify(() => mockDatabase.readDao.getReadsByCid(cid)).called(3);
verify(() => mockDatabase.channelDao.getChannelByCid(cid)).called(3);
verify(() => mockDatabase.messageDao.getMessagesByCid(cid)).called(3);
verify(() => mockDatabase.pinnedMessageDao.getMessagesByCid(cid))
.called(3);
final fetchedChannelStates = await client.getChannelStates();
expect(fetchedChannelStates.length, channelStates.length);
for (var i = 0; i < fetchedChannelStates.length; i++) {
final original = channelStates[i];
final fetched = fetchedChannelStates[i];
expect(fetched.members?.length, original.members?.length);
expect(fetched.messages?.length, original.messages?.length);
expect(
fetched.pinnedMessages?.length, original.pinnedMessages?.length);
expect(fetched.read?.length, original.read?.length);
expect(fetched.channel!.cid, original.channel!.cid);
}
verify(() => mockDatabase.channelQueryDao.getChannels()).called(1);
verify(() => mockDatabase.memberDao.getMembersByCid(cid)).called(3);
verify(() => mockDatabase.readDao.getReadsByCid(cid)).called(3);
verify(() => mockDatabase.channelDao.getChannelByCid(cid)).called(3);
verify(() => mockDatabase.messageDao.getMessagesByCid(cid)).called(3);
verify(() => mockDatabase.pinnedMessageDao.getMessagesByCid(cid))
.called(3);
});
});
test('updateChannelQueries', () async {