refactor (core <-> ui <-> persistence) with the new filter changes.

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-04-27 15:41:00 +05:30
parent f683961581
commit 8c666caa52
24 changed files with 180 additions and 195 deletions
@@ -18,7 +18,7 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
/// Creates a new channel query dao instance
ChannelQueryDao(MoorChatDatabase db) : super(db);
String _computeHash(Map<String, dynamic>? filter) {
String _computeHash(Filter? filter) {
if (filter == null) {
return 'allchannels';
}
@@ -30,7 +30,7 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
/// If [clearQueryCache] is true before the insert
/// the list of matching rows will be deleted
Future<void> updateChannelQueries(
Map<String, dynamic> filter,
Filter? filter,
List<String> cids, {
bool clearQueryCache = false,
}) async =>
@@ -58,7 +58,7 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
});
///
Future<List<String>> getCachedChannelCids(Map<String, dynamic>? filter) {
Future<List<String>> getCachedChannelCids(Filter? filter) {
final hash = _computeHash(filter);
return (select(channelQueries)..where((c) => c.queryHash.equals(hash)))
.map((c) => c.channelCid)
@@ -67,7 +67,7 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
/// Get list of channels by filter, sort and paginationParams
Future<List<ChannelModel>> getChannels({
Map<String, dynamic>? filter,
Filter? filter,
List<SortOption<ChannelModel>>? sort,
PaginationParams? paginationParams,
}) async {
@@ -253,7 +253,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
@override
Future<List<ChannelState>> getChannelStates({
Map<String, dynamic>? filter,
Filter? filter,
List<SortOption<ChannelModel>>? sort,
PaginationParams? paginationParams,
}) {
@@ -273,7 +273,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
@override
Future<void> updateChannelQueries(
Map<String, dynamic> filter,
Filter? filter,
List<String> cids, {
bool clearQueryCache = false,
}) {
@@ -17,11 +17,7 @@ void main() {
});
test('updateChannelQueries', () async {
const filter = {
'members': {
r'$in': ['testUserId'],
},
};
final filter = Filter.in_('members', const ['testUserId']);
const cids = ['testCid1', 'testCid2', 'testCid3'];
@@ -36,11 +32,7 @@ void main() {
});
test('clear queryCache before updateChannelQueries', () async {
const filter = {
'members': {
r'$in': ['testUserId'],
},
};
final filter = Filter.in_('members', const ['testUserId']);
const cids = ['testCid1', 'testCid2', 'testCid3'];
@@ -59,11 +51,7 @@ void main() {
});
test('getCachedChannelCids', () async {
const filter = {
'members': {
r'$in': ['testUserId'],
},
};
final filter = Filter.in_('members', const ['testUserId']);
const cids = ['testCid1', 'testCid2', 'testCid3'];
@@ -78,7 +66,7 @@ void main() {
});
Future<List<ChannelModel>> _insertTestDataForGetChannel(
Map<String, Object> filter, {
Filter filter, {
int count = 3,
}) async {
final now = DateTime.now();
@@ -110,11 +98,7 @@ void main() {
}
group('getChannels', () {
const filter = {
'members': {
r'$in': ['testUserId'],
},
};
final filter = Filter.in_('members', const ['testUserId']);
test('should return empty list of channels', () async {
final channels = await channelQueryDao.getChannels(filter: filter);
@@ -292,7 +292,7 @@ void main() {
});
test('updateChannelQueries', () async {
const filter = <String, dynamic>{};
final filter = Filter.in_('members', const ['testUserId']);
const cids = <String>[];
when(() =>
mockDatabase.channelQueryDao.updateChannelQueries(filter, cids))