feat(llc): add support for partialUserUpdate endpoint.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -1073,6 +1073,28 @@ class StreamChatClient {
|
||||
Future<UpdateUsersResponse> updateUsers(List<User> users) =>
|
||||
_chatApi.user.updateUsers(users);
|
||||
|
||||
/// Partially update the given user with [id].
|
||||
/// Use [set] to define values to be set.
|
||||
/// Use [unset] to define values to be unset.
|
||||
Future<UpdateUsersResponse> partialUpdateUser(
|
||||
String id, {
|
||||
Map<String, Object?>? set,
|
||||
List<String>? unset,
|
||||
}) {
|
||||
final user = PartialUpdateUserRequest(
|
||||
id: id,
|
||||
set: set,
|
||||
unset: unset,
|
||||
);
|
||||
return partialUpdateUsers([user]);
|
||||
}
|
||||
|
||||
/// Batch partial updates the [users].
|
||||
Future<UpdateUsersResponse> partialUpdateUsers(
|
||||
List<PartialUpdateUserRequest> users,
|
||||
) =>
|
||||
_chatApi.user.partialUpdateUsers(users);
|
||||
|
||||
/// Bans a user from all channels
|
||||
Future<EmptyResponse> banUser(
|
||||
String targetUserId, [
|
||||
|
||||
@@ -156,3 +156,29 @@ class PaginationParams extends Equatable {
|
||||
lessThanOrEqual,
|
||||
];
|
||||
}
|
||||
|
||||
/// Request model for the [client.partialUpdateUser] api call.
|
||||
@JsonSerializable(createFactory: false)
|
||||
class PartialUpdateUserRequest extends Equatable {
|
||||
/// Creates a new PartialUpdateUserRequest instance.
|
||||
const PartialUpdateUserRequest({
|
||||
required this.id,
|
||||
this.set,
|
||||
this.unset,
|
||||
});
|
||||
|
||||
/// User ID.
|
||||
final String id;
|
||||
|
||||
/// Fields to set.
|
||||
final Map<String, Object?>? set;
|
||||
|
||||
/// Fields to unset.
|
||||
final List<String>? unset;
|
||||
|
||||
/// Serialize model to json
|
||||
Map<String, dynamic> toJson() => _$PartialUpdateUserRequestToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, set, unset];
|
||||
}
|
||||
|
||||
@@ -54,3 +54,14 @@ Map<String, dynamic> _$PaginationParamsToJson(PaginationParams instance) {
|
||||
writeNotNull('id_lte', instance.lessThanOrEqual);
|
||||
return val;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$PartialUpdateUserRequestToJson(
|
||||
PartialUpdateUserRequest instance) =>
|
||||
<String, dynamic>{
|
||||
'stringify': instance.stringify,
|
||||
'hash_code': instance.hashCode,
|
||||
'id': instance.id,
|
||||
'set': instance.set,
|
||||
'unset': instance.unset,
|
||||
'props': instance.props,
|
||||
};
|
||||
|
||||
@@ -46,4 +46,17 @@ class UserApi {
|
||||
);
|
||||
return UpdateUsersResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
/// Batch partial update of [users].
|
||||
Future<UpdateUsersResponse> partialUpdateUsers(
|
||||
List<PartialUpdateUserRequest> users,
|
||||
) async {
|
||||
final response = await _client.patch(
|
||||
'/users',
|
||||
data: {
|
||||
'users': users,
|
||||
},
|
||||
);
|
||||
return UpdateUsersResponse.fromJson(response.data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ ChannelState _$ChannelStateFromJson(Map<String, dynamic> json) => ChannelState(
|
||||
pinnedMessages: (json['pinned_messages'] as List<dynamic>?)
|
||||
?.map((e) => Message.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
const [],
|
||||
_emptyPinnedMessages,
|
||||
watcherCount: json['watcher_count'] as int?,
|
||||
watchers: (json['watchers'] as List<dynamic>?)
|
||||
?.map((e) => User.fromJson(e as Map<String, dynamic>))
|
||||
|
||||
@@ -1772,6 +1772,46 @@ void main() {
|
||||
verifyNoMoreInteractions(api.user);
|
||||
});
|
||||
|
||||
test('`.partialUpdateUser`', () async {
|
||||
const userId = 'test-user-id';
|
||||
|
||||
final set = {'color': 'yellow'};
|
||||
final unset = <String>[];
|
||||
|
||||
final partialUpdateRequest = PartialUpdateUserRequest(
|
||||
id: userId,
|
||||
set: set,
|
||||
unset: unset,
|
||||
);
|
||||
|
||||
final updatedUser = User(
|
||||
id: userId,
|
||||
extraData: {'color': set['color']},
|
||||
);
|
||||
|
||||
when(() => api.user.partialUpdateUsers([partialUpdateRequest]))
|
||||
.thenAnswer(
|
||||
(_) async => UpdateUsersResponse()
|
||||
..users = {
|
||||
updatedUser.id: updatedUser,
|
||||
},
|
||||
);
|
||||
|
||||
final res = await client.partialUpdateUser(
|
||||
userId,
|
||||
set: set,
|
||||
unset: unset,
|
||||
);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.users, {updatedUser.id: updatedUser});
|
||||
|
||||
verify(
|
||||
() => api.user.partialUpdateUsers([partialUpdateRequest]),
|
||||
).called(1);
|
||||
verifyNoMoreInteractions(api.user);
|
||||
});
|
||||
|
||||
test('`.banUser`', () async {
|
||||
const userId = 'test-user-id';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user