Skip to content

Commit ac416c0

Browse files
authored
Merge pull request #1712 from GetStream/release/v6.9.0
2 parents aec4c07 + 8ba2f57 commit ac416c0

File tree

64 files changed

+918
-559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+918
-559
lines changed

.github/workflows/legacy_version_analyze.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: legacy_version_analyze
33
env:
44
# Note: The versions below should be manually updated after a new stable
55
# version comes out.
6-
flutter_version: "3.7.12"
6+
flutter_version: "3.10.6"
77

88
on:
99
push:

.github/workflows/stream_flutter_workflow.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: stream_flutter_workflow
22

33
env:
44
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
5-
flutter_version: "3.10.4"
5+
flutter_channel: "stable"
66

77
on:
88
pull_request:
@@ -37,7 +37,7 @@ jobs:
3737
uses: subosito/flutter-action@v2
3838
with:
3939
cache: true
40-
flutter-version: ${{ env.flutter_version }}
40+
channel: ${{ env.flutter_channel }}
4141
- name: "Install Tools"
4242
run: |
4343
flutter pub global activate melos

packages/stream_chat/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 6.8.0
2+
3+
🐞 Fixed
4+
5+
- Fixed `Channel.query` not initializing `ChannelState`.
6+
7+
✅ Added
8+
9+
- Added support for `channel.countUnreadMentions()` to get the count of unread messages mentioning the current user on a
10+
channel. [#1692](https://github.com/GetStream/stream-chat-flutter/issues/1692)
11+
12+
🔄 Changed
13+
14+
- Updated minimum supported `SDK` version to Dart 3.0
15+
116
## 6.7.0
217

318
✅ Added

packages/stream_chat/example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ publish_to: "none"
55
version: 1.0.0+1
66

77
environment:
8-
sdk: '>=2.19.0 <4.0.0'
9-
flutter: ">=3.7.0"
8+
sdk: ">=3.0.0 <4.0.0"
9+
flutter: ">=3.10.0"
1010

1111
dependencies:
1212
cupertino_icons: ^1.0.5

packages/stream_chat/lib/src/client/channel.dart

Lines changed: 83 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,26 +1339,6 @@ class Channel {
13391339
return _client.markChannelRead(id!, type, messageId: messageId);
13401340
}
13411341

1342-
/// Loads the initial channel state and watches for changes.
1343-
Future<ChannelState> watch({bool presence = false}) async {
1344-
ChannelState response;
1345-
1346-
try {
1347-
response = await query(watch: true, presence: presence);
1348-
} catch (error, stackTrace) {
1349-
if (!_initializedCompleter.isCompleted) {
1350-
_initializedCompleter.completeError(error, stackTrace);
1351-
}
1352-
rethrow;
1353-
}
1354-
1355-
if (state == null) {
1356-
_initState(response);
1357-
}
1358-
1359-
return response;
1360-
}
1361-
13621342
void _initState(ChannelState channelState) {
13631343
state = ChannelClientState(this, channelState);
13641344

@@ -1370,6 +1350,22 @@ class Channel {
13701350
}
13711351
}
13721352

1353+
/// Loads the initial channel state and watches for changes.
1354+
Future<ChannelState> watch({
1355+
bool presence = false,
1356+
PaginationParams? messagesPagination,
1357+
PaginationParams? membersPagination,
1358+
PaginationParams? watchersPagination,
1359+
}) {
1360+
return query(
1361+
watch: true,
1362+
presence: presence,
1363+
messagesPagination: messagesPagination,
1364+
membersPagination: membersPagination,
1365+
watchersPagination: watchersPagination,
1366+
);
1367+
}
1368+
13731369
/// Stop watching the channel.
13741370
Future<EmptyResponse> stopWatching() async {
13751371
_checkInitialized();
@@ -1435,7 +1431,7 @@ class Channel {
14351431
);
14361432

14371433
/// Creates a new channel.
1438-
Future<ChannelState> create() async => query(state: false);
1434+
Future<ChannelState> create() => query(state: false);
14391435

14401436
/// Query the API, get messages, members or other channel fields.
14411437
///
@@ -1450,23 +1446,28 @@ class Channel {
14501446
PaginationParams? watchersPagination,
14511447
bool preferOffline = false,
14521448
}) async {
1453-
if (preferOffline && cid != null) {
1454-
final updatedState = await _client.chatPersistenceClient
1455-
?.getChannelStateByCid(cid!, messagePagination: messagesPagination);
1456-
if (updatedState != null &&
1457-
updatedState.messages != null &&
1458-
updatedState.messages!.isNotEmpty) {
1459-
if (this.state == null) {
1460-
_initState(updatedState);
1461-
} else {
1462-
this.state?.updateChannelState(updatedState);
1449+
ChannelState? channelState;
1450+
1451+
try {
1452+
// If we prefer offline, we first try to get the channel state from the
1453+
// offline storage.
1454+
if (preferOffline && !watch && cid != null) {
1455+
final persistenceClient = _client.chatPersistenceClient;
1456+
if (persistenceClient != null) {
1457+
final cachedState = await persistenceClient.getChannelStateByCid(
1458+
cid!,
1459+
messagePagination: messagesPagination,
1460+
);
1461+
1462+
// If the cached state contains messages, we can use it.
1463+
if (cachedState.messages?.isNotEmpty == true) {
1464+
channelState = cachedState;
1465+
}
14631466
}
1464-
return updatedState;
14651467
}
1466-
}
14671468

1468-
try {
1469-
final updatedState = await _client.queryChannel(
1469+
// If we still don't have the channelState, we try to get it from the API.
1470+
channelState ??= await _client.queryChannel(
14701471
type,
14711472
channelId: id,
14721473
channelData: _extraData,
@@ -1479,18 +1480,35 @@ class Channel {
14791480
);
14801481

14811482
if (_id == null) {
1482-
_id = updatedState.channel!.id;
1483-
_cid = updatedState.channel!.cid;
1483+
_id = channelState.channel!.id;
1484+
_cid = channelState.channel!.cid;
14841485
}
14851486

1486-
this.state?.updateChannelState(updatedState);
1487-
return updatedState;
1488-
} catch (e) {
1489-
if (_client.persistenceEnabled) {
1490-
return _client.chatPersistenceClient!.getChannelStateByCid(
1491-
cid!,
1492-
messagePagination: messagesPagination,
1493-
);
1487+
// Initialize the channel state if it's not initialized yet.
1488+
if (this.state == null) {
1489+
_initState(channelState);
1490+
} else {
1491+
// Otherwise, update the channel state.
1492+
this.state?.updateChannelState(channelState);
1493+
}
1494+
1495+
return channelState;
1496+
} catch (e, stk) {
1497+
// If we failed to get the channel state from the API and we were not
1498+
// supposed to watch the channel, we will try to get the channel state
1499+
// from the offline storage.
1500+
if (watch == false) {
1501+
if (_client.persistenceEnabled) {
1502+
return _client.chatPersistenceClient!.getChannelStateByCid(
1503+
cid!,
1504+
messagePagination: messagesPagination,
1505+
);
1506+
}
1507+
}
1508+
1509+
// Otherwise, we will just rethrow the error.
1510+
if (!_initializedCompleter.isCompleted) {
1511+
_initializedCompleter.completeError(e, stk);
14941512
}
14951513

14961514
rethrow;
@@ -2334,6 +2352,26 @@ class ChannelClientState {
23342352
!isThreadMessage;
23352353
}
23362354

2355+
/// Counts the number of unread messages mentioning the current user.
2356+
///
2357+
/// **NOTE**: The method relies on the [Channel.messages] list and doesn't do
2358+
/// any API call. Therefore, the count might be not reliable as it relies on
2359+
/// the local data.
2360+
int countUnreadMentions() {
2361+
final lastRead = currentUserRead?.lastRead;
2362+
final userId = _channel.client.state.currentUser?.id;
2363+
2364+
var count = 0;
2365+
for (final message in messages) {
2366+
if (_countMessageAsUnread(message) &&
2367+
(lastRead == null || message.createdAt.isAfter(lastRead)) &&
2368+
message.mentionedUsers.any((user) => user.id == userId) == true) {
2369+
count++;
2370+
}
2371+
}
2372+
return count;
2373+
}
2374+
23372375
/// Update threads with updated information about messages.
23382376
void updateThreadInfo(String parentId, List<Message> messages) {
23392377
final newThreads = Map<String, List<Message>>.from(threads);

packages/stream_chat/lib/src/client/client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ class ClientState {
16961696
void updateUsers(List<User?> userList) {
16971697
final newUsers = {
16981698
...users,
1699-
for (var user in userList)
1699+
for (final user in userList)
17001700
if (user != null) user.id: user,
17011701
};
17021702
_usersController.add(newUsers);

packages/stream_chat/lib/src/ws/timer_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dart:async';
22
import 'package:uuid/uuid.dart';
33

44
///
5-
class TimerHelper {
5+
mixin class TimerHelper {
66
final _uuid = const Uuid();
77
late final _timers = <String, Timer>{};
88

packages/stream_chat/lib/version.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import 'package:stream_chat/src/client/client.dart';
33
/// Current package version
44
/// Used in [StreamChatClient] to build the `x-stream-client` header
55
// ignore: constant_identifier_names
6-
const PACKAGE_VERSION = '6.7.0';
6+
const PACKAGE_VERSION = '6.8.0';

packages/stream_chat/pubspec.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
name: stream_chat
22
homepage: https://getstream.io/
33
description: The official Dart client for Stream Chat, a service for building chat applications.
4-
version: 6.7.0
4+
version: 6.8.0
55
repository: https://github.com/GetStream/stream-chat-flutter
66
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues
77

88
environment:
9-
sdk: '>=2.19.0 <4.0.0'
9+
sdk: '>=3.0.0 <4.0.0'
1010

1111
dependencies:
12-
async: ^2.10.0
13-
collection: ^1.17.0
14-
dio: ^5.2.1+1
12+
async: ^2.11.0
13+
collection: ^1.17.1
14+
dio: ^5.3.2
1515
equatable: ^2.0.5
16-
freezed_annotation: ^2.2.0
16+
freezed_annotation: ^2.4.1
1717
http_parser: ^4.0.2
18-
jose: ^0.3.3
18+
jose: ^0.3.4
1919
json_annotation: ^4.8.1
2020
logging: ^1.2.0
21-
meta: ^1.8.0
21+
meta: ^1.9.1
2222
mime: ^1.0.4
2323
rate_limiter: ^1.0.0
2424
rxdart: ^0.27.7
@@ -27,8 +27,8 @@ dependencies:
2727
web_socket_channel: ^2.4.0
2828

2929
dev_dependencies:
30-
build_runner: ^2.3.3
31-
freezed: ^2.4.0
32-
json_serializable: ^6.6.2
33-
mocktail: ^0.3.0
34-
test: ^1.24.3
30+
build_runner: ^2.4.6
31+
freezed: ^2.4.2
32+
json_serializable: ^6.7.1
33+
mocktail: ^1.0.0
34+
test: ^1.24.6

packages/stream_chat/test/src/client/client_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ void main() {
975975
// skipping initial seed event -> {} users
976976
client.state.usersStream.skip(1),
977977
emitsInOrder([
978-
{for (var user in users) user.id: user},
978+
{for (final user in users) user.id: user},
979979
]),
980980
);
981981

packages/stream_chat/test/src/core/http/interceptor/additional_headers_interceptor_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: invalid_use_of_protected_member
2+
13
import 'package:dio/dio.dart';
24
import 'package:stream_chat/src/core/http/interceptor/additional_headers_interceptor.dart';
35
import 'package:stream_chat/stream_chat.dart';

packages/stream_chat/test/src/core/http/interceptor/auth_interceptor_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: invalid_use_of_protected_member
2+
13
import 'package:dio/dio.dart';
24
import 'package:mocktail/mocktail.dart';
35
import 'package:stream_chat/src/core/http/interceptor/auth_interceptor.dart';

packages/stream_chat/test/src/core/http/interceptor/connection_id_interceptor_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: invalid_use_of_protected_member
2+
13
import 'package:dio/dio.dart';
24
import 'package:mocktail/mocktail.dart';
35
import 'package:stream_chat/src/core/http/connection_id_manager.dart';

0 commit comments

Comments
 (0)