Skip to content

Commit 8dd2e61

Browse files
Merge pull request #96 from sendbird/v4.2.3
Add 4.2.3.
2 parents 4d44a44 + d968041 commit 8dd2e61

23 files changed

+342
-177
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v4.2.3 (Mar 4, 2024)
2+
3+
### Improvements
4+
- Fixed the bug where `query` in `GroupChannelCollection` does not work when reconnected
5+
16
## v4.2.2 (Fed 15, 2024)
27

38
### Improvements

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Before installing Sendbird Chat SDK, you need to create a Sendbird application o
4848

4949
```yaml
5050
dependencies:
51-
sendbird_chat_sdk: ^4.2.2
51+
sendbird_chat_sdk: ^4.2.3
5252
```
5353
5454
- Run `flutter pub get` command in your project directory.

lib/src/internal/db/db.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ class DB {
247247
return await CGroupChannel.getChannels(_chat, _isar, query, offset);
248248
}
249249

250+
Future<bool> canAddChannel(
251+
GroupChannelListQuery query, String channelUrl) async {
252+
return await CGroupChannel.canAddChannel(_chat, _isar, query, channelUrl);
253+
}
254+
250255
Future<void> deleteGroupChannel(String channelUrl) async {
251256
await CGroupChannel.delete(_chat, _isar, channelUrl);
252257
}

lib/src/internal/db/schema/channel/c_group_channel.dart

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,61 @@ class CGroupChannel extends CBaseChannel {
211211
return await cGroupChannel?.toGroupChannel(chat, isar);
212212
}
213213

214+
static Future<bool> canAddChannel(
215+
Chat chat,
216+
Isar isar,
217+
GroupChannelListQuery query,
218+
String channelUrl,
219+
) async {
220+
final groupChannels = await _getChannels(
221+
chat: chat,
222+
isar: isar,
223+
query: query,
224+
channelUrl: channelUrl,
225+
);
226+
return groupChannels.isNotEmpty;
227+
}
228+
214229
static Future<List<GroupChannel>> getChannels(
215230
Chat chat,
216231
Isar isar,
217232
GroupChannelListQuery query,
218233
int? offset,
219234
) async {
235+
return _getChannels(
236+
chat: chat,
237+
isar: isar,
238+
query: query,
239+
offset: offset,
240+
);
241+
}
242+
243+
static Future<List<GroupChannel>> _getChannels({
244+
required Chat chat,
245+
required Isar isar,
246+
required GroupChannelListQuery query,
247+
int? offset,
248+
String? channelUrl,
249+
}) async {
220250
// [includeMetaData]
221251
// When calling API, this value have to be `true` to make chunk.
222252
// But we must always call API for GroupChannel, because we must always get `hasNext` value from API.
223253
// So we do not need the chunk for GroupChannel.
224254

225-
final cGroupChannels = await isar.cGroupChannels
226-
.where()
227-
.channelTypeEqualToAnyChannelUrl(ChannelType.group) // Check
228-
.filter()
255+
QueryBuilder<CGroupChannel, CGroupChannel, QFilterCondition> queryBuilder;
256+
if (channelUrl != null && channelUrl.isNotEmpty) {
257+
queryBuilder = isar.cGroupChannels
258+
.where()
259+
.channelTypeChannelUrlEqualTo(ChannelType.group, channelUrl)
260+
.filter();
261+
} else {
262+
queryBuilder = isar.cGroupChannels
263+
.where()
264+
.channelTypeEqualToAnyChannelUrl(ChannelType.group) // Check
265+
.filter();
266+
}
229267

268+
final cGroupChannels = await queryBuilder
230269
// channelUrlsFilter
231270
.optional(query.channelUrlsFilter.isNotEmpty, (q) {
232271
return q.group((groupQ) {

lib/src/internal/main/chat/chat.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ part 'chat_notifications.dart';
6060
part 'chat_push.dart';
6161
part 'chat_user.dart';
6262

63-
const sdkVersion = '4.2.2';
63+
const sdkVersion = '4.2.3';
6464

6565
// Internal implementation for main class. Do not directly access this class.
6666
class Chat with WidgetsBindingObserver {

lib/src/internal/main/chat_manager/collection_manager/group_channel_collection_manager.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ extension GroupChannelCollectionManager on CollectionManager {
179179
}
180180

181181
if (!isChannelExists) {
182-
if (channelCollection.canAddChannel(eventSource, addedChannel)) {
182+
if (await channelCollection.canAddChannel(eventSource, addedChannel)) {
183183
addedChannelsForEvent.add(addedChannel);
184184
}
185185
}
@@ -202,7 +202,7 @@ extension GroupChannelCollectionManager on CollectionManager {
202202
// Need to compare channel properties with updatedChannel
203203
// when eventSource is CollectionEventSource.channelChangeLogs (?)
204204

205-
if (channelCollection.canAddChannel(eventSource, updatedChannel,
205+
if (await channelCollection.canAddChannel(eventSource, updatedChannel,
206206
checkToUpdateChannel: true)) {
207207
channelCollection.channelList[index] = updatedChannel;
208208
updatedChannelsForEvent.add(updatedChannel);
@@ -218,7 +218,7 @@ extension GroupChannelCollectionManager on CollectionManager {
218218

219219
if (eventSource == CollectionEventSource.channelChangeLogs &&
220220
!isUpdatedChannelInChannelList) {
221-
if (channelCollection.canAddChannel(eventSource, updatedChannel)) {
221+
if (await channelCollection.canAddChannel(eventSource, updatedChannel)) {
222222
addedChannelsForEvent.add(updatedChannel);
223223
}
224224
}

lib/src/internal/main/chat_manager/db_manager.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ class DBManager {
256256
return [];
257257
}
258258

259+
Future<bool> canAddChannel({
260+
required GroupChannelListQuery query,
261+
required String channelUrl,
262+
}) async {
263+
if (isEnabled()) {
264+
return await _db.canAddChannel(query, channelUrl);
265+
}
266+
return true;
267+
}
268+
259269
Future<GroupChannel?> getGroupChannel(String channelUrl) async {
260270
if (isEnabled()) {
261271
return await _db.getGroupChannel(channelUrl);

lib/src/public/main/collection/group_channel_collection/group_channel_collection.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@ class GroupChannelCollection {
234234
}
235235
}
236236

237-
bool canAddChannel(
237+
Future<bool> canAddChannel(
238238
CollectionEventSource eventSource,
239239
GroupChannel addedChannel, {
240240
bool checkToUpdateChannel = false,
241-
}) {
241+
}) async {
242242
if (eventSource == CollectionEventSource.channelCacheLoadMore ||
243243
eventSource == CollectionEventSource.channelLoadMore) {
244244
return true;
@@ -297,6 +297,14 @@ class GroupChannelCollection {
297297
}
298298
}
299299

300+
if (eventSource == CollectionEventSource.channelChangeLogs) {
301+
if (await _chat.dbManager.canAddChannel(
302+
query: _query, channelUrl: addedChannel.channelUrl) ==
303+
false) {
304+
return false;
305+
}
306+
}
307+
300308
return true;
301309
}
302310
}

lib/src/public/main/query/channel/open_channel_list_query.dart

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,31 @@ class OpenChannelListQuery extends BaseQuery {
4747
if (includeMetaData) ChannelListQueryIncludeOption.includeMetadata
4848
];
4949

50-
final res =
51-
await chat.apiClient.send<ChannelListQueryResponse<OpenChannel>>(
52-
OpenChannelListRequest(
53-
chat,
54-
limit: limit,
55-
nameKeyword: nameKeyword,
56-
urlKeyword: urlKeyword,
57-
customType: customTypeFilter,
58-
token: token,
59-
options: options,
60-
),
61-
);
50+
ChannelListQueryResponse<OpenChannel> res;
51+
try {
52+
res = await chat.apiClient.send<ChannelListQueryResponse<OpenChannel>>(
53+
OpenChannelListRequest(
54+
chat,
55+
limit: limit,
56+
nameKeyword: nameKeyword,
57+
urlKeyword: urlKeyword,
58+
customType: customTypeFilter,
59+
token: token,
60+
options: options,
61+
),
62+
);
6263

63-
for (final element in res.channels) {
64-
element.set(chat);
64+
token = res.next;
65+
hasNext = res.next != '';
66+
for (final element in res.channels) {
67+
element.set(chat);
68+
}
69+
} catch (_) {
70+
isLoading = false;
71+
rethrow;
6572
}
6673

6774
isLoading = false;
68-
token = res.next;
69-
hasNext = res.next != '';
7075
return res.channels;
7176
}
7277
}

lib/src/public/main/query/channel/public_group_channel_list_query.dart

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,31 @@ class PublicGroupChannelListQuery extends BaseQuery {
130130
..createdBefore = GroupChannelFilter.toSec(createdBefore)
131131
..createdAfter = GroupChannelFilter.toSec(createdAfter);
132132

133-
final res =
134-
await chat.apiClient.send<ChannelListQueryResponse<GroupChannel>>(
135-
PublicGroupChannelListRequest(
136-
chat,
137-
limit: limit,
138-
order: order,
139-
token: token,
140-
channelUrls: channelUrlsFilter,
141-
options: options,
142-
filter: filter,
143-
),
144-
);
145-
146-
for (final element in res.channels) {
147-
element.set(chat);
133+
ChannelListQueryResponse<GroupChannel> res;
134+
try {
135+
res = await chat.apiClient.send<ChannelListQueryResponse<GroupChannel>>(
136+
PublicGroupChannelListRequest(
137+
chat,
138+
limit: limit,
139+
order: order,
140+
token: token,
141+
channelUrls: channelUrlsFilter,
142+
options: options,
143+
filter: filter,
144+
),
145+
);
146+
147+
token = res.next;
148+
hasNext = res.next != '';
149+
for (final element in res.channels) {
150+
element.set(chat);
151+
}
152+
} catch (_) {
153+
isLoading = false;
154+
rethrow;
148155
}
149156

150157
isLoading = false;
151-
token = res.next;
152-
hasNext = res.next != '';
153158
return res.channels;
154159
}
155160
}

0 commit comments

Comments
 (0)