Skip to content

Commit f318b61

Browse files
authored
Merge branch 'develop' into develop
2 parents 27cb7d2 + 141c130 commit f318b61

File tree

11 files changed

+177
-21
lines changed

11 files changed

+177
-21
lines changed

packages/stream_chat/CHANGELOG.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22

33
✅ Added
44

5-
- You can now pass `score` to `client.sendReaction` and `channel.sendReaction` functions
5+
- You can now pass `score` to `client.sendReaction` and `channel.sendReaction` functions.
6+
- Added new `client.partialUpdateUsers` function in order to partially update users.
67

78
🐞 Fixed
89

9-
- [[#890]](https://github.com/GetStream/stream-chat-flutter/pull/890). Fixed Reactions not updating on thread messages. Thanks [bstolinski](https://github.com/bstolinski).
10+
- [[#890]](https://github.com/GetStream/stream-chat-flutter/pull/890) Fixed Reactions not updating on thread messages.
11+
Thanks [bstolinski](https://github.com/bstolinski).
12+
- [[#897]](https://github.com/GetStream/stream-chat-flutter/issues/897) Fixed error type mis-match in `AuthInterceptor`.
13+
1014
## 3.4.0
1115

1216
🐞 Fixed
1317

1418
- [[#857]](https://github.com/GetStream/stream-chat-flutter/issues/857) Channel now listens for member ban/unban and
1519
updates the channel state with the latest data.
16-
- [[#748]](https://github.com/GetStream/stream-chat-flutter/issues/748) `Message.user` is now also included while saving users in persistence.
20+
- [[#748]](https://github.com/GetStream/stream-chat-flutter/issues/748) `Message.user` is now also included while saving
21+
users in persistence.
1722
- [[#871]](https://github.com/GetStream/stream-chat-flutter/issues/871) Fixed thread message deletion.
18-
- [[#846]](https://github.com/GetStream/stream-chat-flutter/issues/846) Fixed `message.ownReactions` getting truncated when receiving a reaction event.
23+
- [[#846]](https://github.com/GetStream/stream-chat-flutter/issues/846) Fixed `message.ownReactions` getting truncated
24+
when receiving a reaction event.
1925
- Add check for invalid image URLs
2026
- Fix `channelState.pinnedMessagesStream` getting reset to `0` after a channel update.
2127
- Fixed `unreadCount` after removing user from a channel.

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,28 @@ class StreamChatClient {
10731073
Future<UpdateUsersResponse> updateUsers(List<User> users) =>
10741074
_chatApi.user.updateUsers(users);
10751075

1076+
/// Partially update the given user with [id].
1077+
/// Use [set] to define values to be set.
1078+
/// Use [unset] to define values to be unset.
1079+
Future<UpdateUsersResponse> partialUpdateUser(
1080+
String id, {
1081+
Map<String, Object?>? set,
1082+
List<String>? unset,
1083+
}) {
1084+
final user = PartialUpdateUserRequest(
1085+
id: id,
1086+
set: set,
1087+
unset: unset,
1088+
);
1089+
return partialUpdateUsers([user]);
1090+
}
1091+
1092+
/// Batch partial updates the [users].
1093+
Future<UpdateUsersResponse> partialUpdateUsers(
1094+
List<PartialUpdateUserRequest> users,
1095+
) =>
1096+
_chatApi.user.partialUpdateUsers(users);
1097+
10761098
/// Bans a user from all channels
10771099
Future<EmptyResponse> banUser(
10781100
String targetUserId, [

packages/stream_chat/lib/src/core/api/requests.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,29 @@ class PaginationParams extends Equatable {
156156
lessThanOrEqual,
157157
];
158158
}
159+
160+
/// Request model for the [client.partialUpdateUser] api call.
161+
@JsonSerializable(createFactory: false)
162+
class PartialUpdateUserRequest extends Equatable {
163+
/// Creates a new PartialUpdateUserRequest instance.
164+
const PartialUpdateUserRequest({
165+
required this.id,
166+
this.set,
167+
this.unset,
168+
});
169+
170+
/// User ID.
171+
final String id;
172+
173+
/// Fields to set.
174+
final Map<String, Object?>? set;
175+
176+
/// Fields to unset.
177+
final List<String>? unset;
178+
179+
/// Serialize model to json
180+
Map<String, dynamic> toJson() => _$PartialUpdateUserRequestToJson(this);
181+
182+
@override
183+
List<Object?> get props => [id, set, unset];
184+
}

packages/stream_chat/lib/src/core/api/requests.g.dart

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/stream_chat/lib/src/core/api/user_api.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,17 @@ class UserApi {
4646
);
4747
return UpdateUsersResponse.fromJson(response.data);
4848
}
49+
50+
/// Batch partial update of [users].
51+
Future<UpdateUsersResponse> partialUpdateUsers(
52+
List<PartialUpdateUserRequest> users,
53+
) async {
54+
final response = await _client.patch(
55+
'/users',
56+
data: {
57+
'users': users,
58+
},
59+
);
60+
return UpdateUsersResponse.fromJson(response.data);
61+
}
4962
}

packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ class AuthInterceptor extends Interceptor {
4949
DioError err,
5050
ErrorInterceptorHandler handler,
5151
) async {
52-
ErrorResponse? error;
5352
final data = err.response?.data;
54-
if (data != null) error = ErrorResponse.fromJson(data);
55-
if (error?.code == ChatErrorCode.tokenExpired.code) {
53+
if (data == null || data is! Map<String, dynamic>) {
54+
return handler.next(err);
55+
}
56+
57+
final error = ErrorResponse.fromJson(data);
58+
if (error.code == ChatErrorCode.tokenExpired.code) {
5659
if (_tokenManager.isStatic) return handler.next(err);
5760
_client.lock();
5861
await _tokenManager.loadToken(refresh: true);

packages/stream_chat/lib/src/core/models/channel_state.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,46 @@ void main() {
17721772
verifyNoMoreInteractions(api.user);
17731773
});
17741774

1775+
test('`.partialUpdateUser`', () async {
1776+
const userId = 'test-user-id';
1777+
1778+
final set = {'color': 'yellow'};
1779+
final unset = <String>[];
1780+
1781+
final partialUpdateRequest = PartialUpdateUserRequest(
1782+
id: userId,
1783+
set: set,
1784+
unset: unset,
1785+
);
1786+
1787+
final updatedUser = User(
1788+
id: userId,
1789+
extraData: {'color': set['color']},
1790+
);
1791+
1792+
when(() => api.user.partialUpdateUsers([partialUpdateRequest]))
1793+
.thenAnswer(
1794+
(_) async => UpdateUsersResponse()
1795+
..users = {
1796+
updatedUser.id: updatedUser,
1797+
},
1798+
);
1799+
1800+
final res = await client.partialUpdateUser(
1801+
userId,
1802+
set: set,
1803+
unset: unset,
1804+
);
1805+
1806+
expect(res, isNotNull);
1807+
expect(res.users, {updatedUser.id: updatedUser});
1808+
1809+
verify(
1810+
() => api.user.partialUpdateUsers([partialUpdateRequest]),
1811+
).called(1);
1812+
verifyNoMoreInteractions(api.user);
1813+
});
1814+
17751815
test('`.banUser`', () async {
17761816
const userId = 'test-user-id';
17771817

packages/stream_chat/test/src/core/api/user_api_test.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,37 @@ void main() {
8282
verify(() => client.post(path, data: any(named: 'data'))).called(1);
8383
verifyNoMoreInteractions(client);
8484
});
85+
86+
test('partialUpdateUsers', () async {
87+
const user = PartialUpdateUserRequest(
88+
id: 'test-user-id',
89+
set: {'color': 'yellow'},
90+
);
91+
92+
const path = '/users';
93+
94+
final updatedUser = {user.id: User(id: user.id, extraData: user.set!)};
95+
96+
when(() => client.patch(path, data: {
97+
'users': [user],
98+
})).thenAnswer(
99+
(_) async => successResponse(
100+
path,
101+
data: {
102+
'users':
103+
updatedUser.map((key, value) => MapEntry(key, value.toJson()))
104+
},
105+
),
106+
);
107+
108+
final res = await userApi.partialUpdateUsers([user]);
109+
110+
expect(res, isNotNull);
111+
expect(res.users.length, updatedUser.length);
112+
113+
verify(() => client.patch(path, data: {
114+
'users': [user]
115+
})).called(1);
116+
verifyNoMoreInteractions(client);
117+
});
85118
}

packages/stream_chat_flutter/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- [[#888]](https://github.com/GetStream/stream-chat-flutter/issues/888) Fix `unban` command not working in `MessageInput`.
66
- [[#805]](https://github.com/GetStream/stream-chat-flutter/issues/805) Updated chewie dependency version to 1.3.0
7+
- Fix `showScrollToBottom` in `MessageListView` not respecting false value.
78

89
## 3.4.0
910
- Updated `stream_chat_flutter_core` dependency to [`3.4.0`](https://pub.dev/packages/stream_chat_flutter_core/changelog).

0 commit comments

Comments
 (0)