From ac87693be33dcb8f6535b58f2d54ad5d0197a41b Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Tue, 22 Oct 2024 16:47:57 +0200 Subject: [PATCH] feat(llc): added user blocking (#2033) Co-authored-by: Sahil Kumar --- packages/stream_chat/CHANGELOG.md | 5 + .../stream_chat/lib/src/client/client.dart | 12 + .../lib/src/core/api/requests.g.dart | 6 +- .../lib/src/core/api/responses.dart | 32 + .../lib/src/core/api/responses.g.dart | 32 +- .../lib/src/core/api/user_api.dart | 28 + .../lib/src/core/models/attachment.g.dart | 4 +- .../core/models/attachment_file.freezed.dart | 201 +++--- .../src/core/models/attachment_file.g.dart | 27 +- .../lib/src/core/models/channel_config.g.dart | 2 +- .../lib/src/core/models/channel_model.g.dart | 4 +- .../lib/src/core/models/channel_state.g.dart | 2 +- .../lib/src/core/models/event.g.dart | 8 +- .../lib/src/core/models/message.g.dart | 6 +- .../core/models/message_state.freezed.dart | 652 ++++++++++-------- .../lib/src/core/models/message_state.g.dart | 82 ++- .../lib/src/core/models/own_user.g.dart | 4 +- .../lib/src/core/models/reaction.g.dart | 2 +- .../lib/src/core/models/read.g.dart | 2 +- .../lib/src/core/models/user_block.dart | 65 ++ .../lib/src/core/models/user_block.g.dart | 27 + .../stream_chat/test/fixtures/user_block.json | 26 + .../test/src/client/client_test.dart | 60 ++ .../test/src/core/api/responses_test.dart | 52 ++ .../test/src/core/api/user_api_test.dart | 67 ++ .../models/attachment_giphy_info_test.dart | 63 ++ .../test/src/core/models/user_block_test.dart | 42 ++ 27 files changed, 1087 insertions(+), 426 deletions(-) create mode 100644 packages/stream_chat/lib/src/core/models/user_block.dart create mode 100644 packages/stream_chat/lib/src/core/models/user_block.g.dart create mode 100644 packages/stream_chat/test/fixtures/user_block.json create mode 100644 packages/stream_chat/test/src/core/models/attachment_giphy_info_test.dart create mode 100644 packages/stream_chat/test/src/core/models/user_block_test.dart diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index 09678fe2f..6161a90a9 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -1,3 +1,8 @@ +## Upcoming + +✅ Added +- Added user blocking to the client. + ## 8.1.0 ✅ Added diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 4a2427d3f..b713cf260 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -1277,6 +1277,18 @@ class StreamChatClient { Future unmuteUser(String userId) => _chatApi.moderation.unmuteUser(userId); + /// Blocks a user + Future blockUser(String userId) => + _chatApi.user.blockUser(userId); + + /// Unblocks a user + Future unblockUser(String userId) => + _chatApi.user.unblockUser(userId); + + /// Requests users with a given query. + Future queryBlockedUsers() => + _chatApi.user.queryBlockedUsers(); + /// Flag a message Future flagMessage(String messageId) => _chatApi.moderation.flagMessage(messageId); diff --git a/packages/stream_chat/lib/src/core/api/requests.g.dart b/packages/stream_chat/lib/src/core/api/requests.g.dart index b70b87676..271713e82 100644 --- a/packages/stream_chat/lib/src/core/api/requests.g.dart +++ b/packages/stream_chat/lib/src/core/api/requests.g.dart @@ -9,7 +9,7 @@ part of 'requests.dart'; SortOption _$SortOptionFromJson(Map json) => SortOption( json['field'] as String, - direction: json['direction'] as int? ?? SortOption.DESC, + direction: (json['direction'] as num?)?.toInt() ?? SortOption.DESC, ); Map _$SortOptionToJson(SortOption instance) => @@ -20,8 +20,8 @@ Map _$SortOptionToJson(SortOption instance) => PaginationParams _$PaginationParamsFromJson(Map json) => PaginationParams( - limit: json['limit'] as int? ?? 10, - offset: json['offset'] as int?, + limit: (json['limit'] as num?)?.toInt() ?? 10, + offset: (json['offset'] as num?)?.toInt(), next: json['next'] as String?, idAround: json['id_around'] as String?, greaterThan: json['id_gt'] as String?, diff --git a/packages/stream_chat/lib/src/core/api/responses.dart b/packages/stream_chat/lib/src/core/api/responses.dart index 53576dfe0..d475b72a7 100644 --- a/packages/stream_chat/lib/src/core/api/responses.dart +++ b/packages/stream_chat/lib/src/core/api/responses.dart @@ -13,6 +13,7 @@ import 'package:stream_chat/src/core/models/message.dart'; import 'package:stream_chat/src/core/models/reaction.dart'; import 'package:stream_chat/src/core/models/read.dart'; import 'package:stream_chat/src/core/models/user.dart'; +import 'package:stream_chat/src/core/models/user_block.dart'; part 'responses.g.dart'; @@ -530,3 +531,34 @@ class CreateCallPayload extends _BaseResponse { /// The call object. CallPayload? call; } + +/// Contains information about a [User] that was banned from a [Channel] or App. +@JsonSerializable() +class UserBlockResponse extends _BaseResponse { + /// User that banned the [user]. + @JsonKey(defaultValue: '') + late String blockedByUserId; + + /// Reason for the ban. + @JsonKey(defaultValue: '') + late String blockedUserId; + + /// Timestamp when the [user] was banned. + late DateTime createdAt; + + /// Create a new instance from a json + static UserBlockResponse fromJson(Map json) => + _$UserBlockResponseFromJson(json); +} + +/// Model response for [StreamChatClient.queryBlockedUsers] api call +@JsonSerializable(createToJson: false) +class BlockedUsersResponse extends _BaseResponse { + /// Updated users + @JsonKey(defaultValue: []) + late List blocks; + + /// Create a new instance from a json + static BlockedUsersResponse fromJson(Map json) => + _$BlockedUsersResponseFromJson(json); +} diff --git a/packages/stream_chat/lib/src/core/api/responses.g.dart b/packages/stream_chat/lib/src/core/api/responses.g.dart index 624f533bf..7c447a803 100644 --- a/packages/stream_chat/lib/src/core/api/responses.g.dart +++ b/packages/stream_chat/lib/src/core/api/responses.g.dart @@ -9,9 +9,9 @@ part of 'responses.dart'; ErrorResponse _$ErrorResponseFromJson(Map json) => ErrorResponse() ..duration = json['duration'] as String? - ..code = json['code'] as int? + ..code = (json['code'] as num?)?.toInt() ..message = json['message'] as String? - ..statusCode = json['StatusCode'] as int? + ..statusCode = (json['StatusCode'] as num?)?.toInt() ..moreInfo = json['more_info'] as String?; Map _$ErrorResponseToJson(ErrorResponse instance) => @@ -279,7 +279,7 @@ ChannelStateResponse _$ChannelStateResponseFromJson( ?.map((e) => Member.fromJson(e as Map)) .toList() ?? [] - ..watcherCount = json['watcher_count'] as int? ?? 0 + ..watcherCount = (json['watcher_count'] as num?)?.toInt() ?? 0 ..read = (json['read'] as List?) ?.map((e) => Read.fromJson(e as Map)) .toList() ?? @@ -304,7 +304,7 @@ CallTokenPayload _$CallTokenPayloadFromJson(Map json) => CallTokenPayload() ..duration = json['duration'] as String? ..token = json['token'] as String? - ..agoraUid = json['agora_uid'] as int? + ..agoraUid = (json['agora_uid'] as num?)?.toInt() ..agoraAppId = json['agora_app_id'] as String?; CreateCallPayload _$CreateCallPayloadFromJson(Map json) => @@ -313,3 +313,27 @@ CreateCallPayload _$CreateCallPayloadFromJson(Map json) => ..call = json['call'] == null ? null : CallPayload.fromJson(json['call'] as Map); + +UserBlockResponse _$UserBlockResponseFromJson(Map json) => + UserBlockResponse() + ..duration = json['duration'] as String? + ..blockedByUserId = json['blocked_by_user_id'] as String? ?? '' + ..blockedUserId = json['blocked_user_id'] as String? ?? '' + ..createdAt = DateTime.parse(json['created_at'] as String); + +Map _$UserBlockResponseToJson(UserBlockResponse instance) => + { + 'duration': instance.duration, + 'blocked_by_user_id': instance.blockedByUserId, + 'blocked_user_id': instance.blockedUserId, + 'created_at': instance.createdAt.toIso8601String(), + }; + +BlockedUsersResponse _$BlockedUsersResponseFromJson( + Map json) => + BlockedUsersResponse() + ..duration = json['duration'] as String? + ..blocks = (json['blocks'] as List?) + ?.map((e) => UserBlock.fromJson(e as Map)) + .toList() ?? + []; diff --git a/packages/stream_chat/lib/src/core/api/user_api.dart b/packages/stream_chat/lib/src/core/api/user_api.dart index 916976c8c..bc60ceda3 100644 --- a/packages/stream_chat/lib/src/core/api/user_api.dart +++ b/packages/stream_chat/lib/src/core/api/user_api.dart @@ -59,4 +59,32 @@ class UserApi { ); return UpdateUsersResponse.fromJson(response.data); } + + /// Blocks a user + Future blockUser(String userId) async { + final response = await _client.post( + '/users/block', + data: {'blocked_user_id': userId}, + ); + + return UserBlockResponse.fromJson(response.data); + } + + /// Unblocks a user + Future unblockUser(String userId) async { + final response = await _client.post( + '/users/unblock', + data: {'blocked_user_id': userId}, + ); + return EmptyResponse.fromJson(response.data); + } + + /// Requests blocked users. + Future queryBlockedUsers() async { + final response = await _client.get( + '/users/block', + ); + + return BlockedUsersResponse.fromJson(response.data); + } } diff --git a/packages/stream_chat/lib/src/core/models/attachment.g.dart b/packages/stream_chat/lib/src/core/models/attachment.g.dart index 51aae50e3..a9e5fcb01 100644 --- a/packages/stream_chat/lib/src/core/models/attachment.g.dart +++ b/packages/stream_chat/lib/src/core/models/attachment.g.dart @@ -29,8 +29,8 @@ Attachment _$AttachmentFromJson(Map json) => Attachment( ?.map((e) => Action.fromJson(e as Map)) .toList() ?? const [], - originalWidth: json['original_width'] as int?, - originalHeight: json['original_height'] as int?, + originalWidth: (json['original_width'] as num?)?.toInt(), + originalHeight: (json['original_height'] as num?)?.toInt(), extraData: json['extra_data'] as Map? ?? const {}, file: json['file'] == null ? null diff --git a/packages/stream_chat/lib/src/core/models/attachment_file.freezed.dart b/packages/stream_chat/lib/src/core/models/attachment_file.freezed.dart index 9a0f3d1c0..54f797609 100644 --- a/packages/stream_chat/lib/src/core/models/attachment_file.freezed.dart +++ b/packages/stream_chat/lib/src/core/models/attachment_file.freezed.dart @@ -12,7 +12,7 @@ part of 'attachment_file.dart'; T _$identity(T value) => value; final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); UploadState _$UploadStateFromJson(Map json) { switch (json['runtimeType']) { @@ -83,6 +83,8 @@ mixin _$UploadState { required TResult orElse(), }) => throw _privateConstructorUsedError; + + /// Serializes this UploadState to a JSON map. Map toJson() => throw _privateConstructorUsedError; } @@ -102,33 +104,39 @@ class _$UploadStateCopyWithImpl<$Res, $Val extends UploadState> final $Val _value; // ignore: unused_field final $Res Function($Val) _then; + + /// Create a copy of UploadState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc -abstract class _$$PreparingCopyWith<$Res> { - factory _$$PreparingCopyWith( - _$Preparing value, $Res Function(_$Preparing) then) = - __$$PreparingCopyWithImpl<$Res>; +abstract class _$$PreparingImplCopyWith<$Res> { + factory _$$PreparingImplCopyWith( + _$PreparingImpl value, $Res Function(_$PreparingImpl) then) = + __$$PreparingImplCopyWithImpl<$Res>; } /// @nodoc -class __$$PreparingCopyWithImpl<$Res> - extends _$UploadStateCopyWithImpl<$Res, _$Preparing> - implements _$$PreparingCopyWith<$Res> { - __$$PreparingCopyWithImpl( - _$Preparing _value, $Res Function(_$Preparing) _then) +class __$$PreparingImplCopyWithImpl<$Res> + extends _$UploadStateCopyWithImpl<$Res, _$PreparingImpl> + implements _$$PreparingImplCopyWith<$Res> { + __$$PreparingImplCopyWithImpl( + _$PreparingImpl _value, $Res Function(_$PreparingImpl) _then) : super(_value, _then); + + /// Create a copy of UploadState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @JsonSerializable() -class _$Preparing extends Preparing { - const _$Preparing({final String? $type}) +class _$PreparingImpl extends Preparing { + const _$PreparingImpl({final String? $type}) : $type = $type ?? 'preparing', super._(); - factory _$Preparing.fromJson(Map json) => - _$$PreparingFromJson(json); + factory _$PreparingImpl.fromJson(Map json) => + _$$PreparingImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @@ -139,12 +147,12 @@ class _$Preparing extends Preparing { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$Preparing); + (other.runtimeType == runtimeType && other is _$PreparingImpl); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => runtimeType.hashCode; @@ -224,43 +232,46 @@ class _$Preparing extends Preparing { @override Map toJson() { - return _$$PreparingToJson( + return _$$PreparingImplToJson( this, ); } } abstract class Preparing extends UploadState { - const factory Preparing() = _$Preparing; + const factory Preparing() = _$PreparingImpl; const Preparing._() : super._(); - factory Preparing.fromJson(Map json) = _$Preparing.fromJson; + factory Preparing.fromJson(Map json) = + _$PreparingImpl.fromJson; } /// @nodoc -abstract class _$$InProgressCopyWith<$Res> { - factory _$$InProgressCopyWith( - _$InProgress value, $Res Function(_$InProgress) then) = - __$$InProgressCopyWithImpl<$Res>; +abstract class _$$InProgressImplCopyWith<$Res> { + factory _$$InProgressImplCopyWith( + _$InProgressImpl value, $Res Function(_$InProgressImpl) then) = + __$$InProgressImplCopyWithImpl<$Res>; @useResult $Res call({int uploaded, int total}); } /// @nodoc -class __$$InProgressCopyWithImpl<$Res> - extends _$UploadStateCopyWithImpl<$Res, _$InProgress> - implements _$$InProgressCopyWith<$Res> { - __$$InProgressCopyWithImpl( - _$InProgress _value, $Res Function(_$InProgress) _then) +class __$$InProgressImplCopyWithImpl<$Res> + extends _$UploadStateCopyWithImpl<$Res, _$InProgressImpl> + implements _$$InProgressImplCopyWith<$Res> { + __$$InProgressImplCopyWithImpl( + _$InProgressImpl _value, $Res Function(_$InProgressImpl) _then) : super(_value, _then); + /// Create a copy of UploadState + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ Object? uploaded = null, Object? total = null, }) { - return _then(_$InProgress( + return _then(_$InProgressImpl( uploaded: null == uploaded ? _value.uploaded : uploaded // ignore: cast_nullable_to_non_nullable @@ -275,14 +286,14 @@ class __$$InProgressCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$InProgress extends InProgress { - const _$InProgress( +class _$InProgressImpl extends InProgress { + const _$InProgressImpl( {required this.uploaded, required this.total, final String? $type}) : $type = $type ?? 'inProgress', super._(); - factory _$InProgress.fromJson(Map json) => - _$$InProgressFromJson(json); + factory _$InProgressImpl.fromJson(Map json) => + _$$InProgressImplFromJson(json); @override final int uploaded; @@ -298,24 +309,26 @@ class _$InProgress extends InProgress { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$InProgress && + other is _$InProgressImpl && (identical(other.uploaded, uploaded) || other.uploaded == uploaded) && (identical(other.total, total) || other.total == total)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, uploaded, total); - @JsonKey(ignore: true) + /// Create a copy of UploadState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') - _$$InProgressCopyWith<_$InProgress> get copyWith => - __$$InProgressCopyWithImpl<_$InProgress>(this, _$identity); + _$$InProgressImplCopyWith<_$InProgressImpl> get copyWith => + __$$InProgressImplCopyWithImpl<_$InProgressImpl>(this, _$identity); @override @optionalTypeArgs @@ -393,7 +406,7 @@ class _$InProgress extends InProgress { @override Map toJson() { - return _$$InProgressToJson( + return _$$InProgressImplToJson( this, ); } @@ -401,42 +414,51 @@ class _$InProgress extends InProgress { abstract class InProgress extends UploadState { const factory InProgress( - {required final int uploaded, required final int total}) = _$InProgress; + {required final int uploaded, + required final int total}) = _$InProgressImpl; const InProgress._() : super._(); factory InProgress.fromJson(Map json) = - _$InProgress.fromJson; + _$InProgressImpl.fromJson; int get uploaded; int get total; - @JsonKey(ignore: true) - _$$InProgressCopyWith<_$InProgress> get copyWith => + + /// Create a copy of UploadState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$InProgressImplCopyWith<_$InProgressImpl> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$SuccessCopyWith<$Res> { - factory _$$SuccessCopyWith(_$Success value, $Res Function(_$Success) then) = - __$$SuccessCopyWithImpl<$Res>; +abstract class _$$SuccessImplCopyWith<$Res> { + factory _$$SuccessImplCopyWith( + _$SuccessImpl value, $Res Function(_$SuccessImpl) then) = + __$$SuccessImplCopyWithImpl<$Res>; } /// @nodoc -class __$$SuccessCopyWithImpl<$Res> - extends _$UploadStateCopyWithImpl<$Res, _$Success> - implements _$$SuccessCopyWith<$Res> { - __$$SuccessCopyWithImpl(_$Success _value, $Res Function(_$Success) _then) +class __$$SuccessImplCopyWithImpl<$Res> + extends _$UploadStateCopyWithImpl<$Res, _$SuccessImpl> + implements _$$SuccessImplCopyWith<$Res> { + __$$SuccessImplCopyWithImpl( + _$SuccessImpl _value, $Res Function(_$SuccessImpl) _then) : super(_value, _then); + + /// Create a copy of UploadState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @JsonSerializable() -class _$Success extends Success { - const _$Success({final String? $type}) +class _$SuccessImpl extends Success { + const _$SuccessImpl({final String? $type}) : $type = $type ?? 'success', super._(); - factory _$Success.fromJson(Map json) => - _$$SuccessFromJson(json); + factory _$SuccessImpl.fromJson(Map json) => + _$$SuccessImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @@ -447,12 +469,12 @@ class _$Success extends Success { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$Success); + (other.runtimeType == runtimeType && other is _$SuccessImpl); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => runtimeType.hashCode; @@ -532,40 +554,44 @@ class _$Success extends Success { @override Map toJson() { - return _$$SuccessToJson( + return _$$SuccessImplToJson( this, ); } } abstract class Success extends UploadState { - const factory Success() = _$Success; + const factory Success() = _$SuccessImpl; const Success._() : super._(); - factory Success.fromJson(Map json) = _$Success.fromJson; + factory Success.fromJson(Map json) = _$SuccessImpl.fromJson; } /// @nodoc -abstract class _$$FailedCopyWith<$Res> { - factory _$$FailedCopyWith(_$Failed value, $Res Function(_$Failed) then) = - __$$FailedCopyWithImpl<$Res>; +abstract class _$$FailedImplCopyWith<$Res> { + factory _$$FailedImplCopyWith( + _$FailedImpl value, $Res Function(_$FailedImpl) then) = + __$$FailedImplCopyWithImpl<$Res>; @useResult $Res call({String error}); } /// @nodoc -class __$$FailedCopyWithImpl<$Res> - extends _$UploadStateCopyWithImpl<$Res, _$Failed> - implements _$$FailedCopyWith<$Res> { - __$$FailedCopyWithImpl(_$Failed _value, $Res Function(_$Failed) _then) +class __$$FailedImplCopyWithImpl<$Res> + extends _$UploadStateCopyWithImpl<$Res, _$FailedImpl> + implements _$$FailedImplCopyWith<$Res> { + __$$FailedImplCopyWithImpl( + _$FailedImpl _value, $Res Function(_$FailedImpl) _then) : super(_value, _then); + /// Create a copy of UploadState + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ Object? error = null, }) { - return _then(_$Failed( + return _then(_$FailedImpl( error: null == error ? _value.error : error // ignore: cast_nullable_to_non_nullable @@ -576,13 +602,13 @@ class __$$FailedCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$Failed extends Failed { - const _$Failed({required this.error, final String? $type}) +class _$FailedImpl extends Failed { + const _$FailedImpl({required this.error, final String? $type}) : $type = $type ?? 'failed', super._(); - factory _$Failed.fromJson(Map json) => - _$$FailedFromJson(json); + factory _$FailedImpl.fromJson(Map json) => + _$$FailedImplFromJson(json); @override final String error; @@ -596,22 +622,24 @@ class _$Failed extends Failed { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$Failed && + other is _$FailedImpl && (identical(other.error, error) || other.error == error)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, error); - @JsonKey(ignore: true) + /// Create a copy of UploadState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') - _$$FailedCopyWith<_$Failed> get copyWith => - __$$FailedCopyWithImpl<_$Failed>(this, _$identity); + _$$FailedImplCopyWith<_$FailedImpl> get copyWith => + __$$FailedImplCopyWithImpl<_$FailedImpl>(this, _$identity); @override @optionalTypeArgs @@ -689,20 +717,23 @@ class _$Failed extends Failed { @override Map toJson() { - return _$$FailedToJson( + return _$$FailedImplToJson( this, ); } } abstract class Failed extends UploadState { - const factory Failed({required final String error}) = _$Failed; + const factory Failed({required final String error}) = _$FailedImpl; const Failed._() : super._(); - factory Failed.fromJson(Map json) = _$Failed.fromJson; + factory Failed.fromJson(Map json) = _$FailedImpl.fromJson; String get error; - @JsonKey(ignore: true) - _$$FailedCopyWith<_$Failed> get copyWith => + + /// Create a copy of UploadState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$FailedImplCopyWith<_$FailedImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/packages/stream_chat/lib/src/core/models/attachment_file.g.dart b/packages/stream_chat/lib/src/core/models/attachment_file.g.dart index fe02433e4..6b385f2bb 100644 --- a/packages/stream_chat/lib/src/core/models/attachment_file.g.dart +++ b/packages/stream_chat/lib/src/core/models/attachment_file.g.dart @@ -8,7 +8,7 @@ part of 'attachment_file.dart'; AttachmentFile _$AttachmentFileFromJson(Map json) => AttachmentFile( - size: json['size'] as int?, + size: (json['size'] as num?)?.toInt(), path: json['path'] as String?, name: json['name'] as String?, ); @@ -20,42 +20,47 @@ Map _$AttachmentFileToJson(AttachmentFile instance) => 'size': instance.size, }; -_$Preparing _$$PreparingFromJson(Map json) => _$Preparing( +_$PreparingImpl _$$PreparingImplFromJson(Map json) => + _$PreparingImpl( $type: json['runtimeType'] as String?, ); -Map _$$PreparingToJson(_$Preparing instance) => +Map _$$PreparingImplToJson(_$PreparingImpl instance) => { 'runtimeType': instance.$type, }; -_$InProgress _$$InProgressFromJson(Map json) => _$InProgress( - uploaded: json['uploaded'] as int, - total: json['total'] as int, +_$InProgressImpl _$$InProgressImplFromJson(Map json) => + _$InProgressImpl( + uploaded: (json['uploaded'] as num).toInt(), + total: (json['total'] as num).toInt(), $type: json['runtimeType'] as String?, ); -Map _$$InProgressToJson(_$InProgress instance) => +Map _$$InProgressImplToJson(_$InProgressImpl instance) => { 'uploaded': instance.uploaded, 'total': instance.total, 'runtimeType': instance.$type, }; -_$Success _$$SuccessFromJson(Map json) => _$Success( +_$SuccessImpl _$$SuccessImplFromJson(Map json) => + _$SuccessImpl( $type: json['runtimeType'] as String?, ); -Map _$$SuccessToJson(_$Success instance) => { +Map _$$SuccessImplToJson(_$SuccessImpl instance) => + { 'runtimeType': instance.$type, }; -_$Failed _$$FailedFromJson(Map json) => _$Failed( +_$FailedImpl _$$FailedImplFromJson(Map json) => _$FailedImpl( error: json['error'] as String, $type: json['runtimeType'] as String?, ); -Map _$$FailedToJson(_$Failed instance) => { +Map _$$FailedImplToJson(_$FailedImpl instance) => + { 'error': instance.error, 'runtimeType': instance.$type, }; diff --git a/packages/stream_chat/lib/src/core/models/channel_config.g.dart b/packages/stream_chat/lib/src/core/models/channel_config.g.dart index 48b2a739a..c17e3db78 100644 --- a/packages/stream_chat/lib/src/core/models/channel_config.g.dart +++ b/packages/stream_chat/lib/src/core/models/channel_config.g.dart @@ -20,7 +20,7 @@ ChannelConfig _$ChannelConfigFromJson(Map json) => updatedAt: json['updated_at'] == null ? null : DateTime.parse(json['updated_at'] as String), - maxMessageLength: json['max_message_length'] as int? ?? 0, + maxMessageLength: (json['max_message_length'] as num?)?.toInt() ?? 0, messageRetention: json['message_retention'] as String? ?? '', mutes: json['mutes'] as bool? ?? false, reactions: json['reactions'] as bool? ?? false, diff --git a/packages/stream_chat/lib/src/core/models/channel_model.g.dart b/packages/stream_chat/lib/src/core/models/channel_model.g.dart index b1a691e3f..b9f5d03b0 100644 --- a/packages/stream_chat/lib/src/core/models/channel_model.g.dart +++ b/packages/stream_chat/lib/src/core/models/channel_model.g.dart @@ -32,10 +32,10 @@ ChannelModel _$ChannelModelFromJson(Map json) => ChannelModel( deletedAt: json['deleted_at'] == null ? null : DateTime.parse(json['deleted_at'] as String), - memberCount: json['member_count'] as int? ?? 0, + memberCount: (json['member_count'] as num?)?.toInt() ?? 0, extraData: json['extra_data'] as Map? ?? const {}, team: json['team'] as String?, - cooldown: json['cooldown'] as int? ?? 0, + cooldown: (json['cooldown'] as num?)?.toInt() ?? 0, ); Map _$ChannelModelToJson(ChannelModel instance) => diff --git a/packages/stream_chat/lib/src/core/models/channel_state.g.dart b/packages/stream_chat/lib/src/core/models/channel_state.g.dart index 40e11a32d..db2a2b673 100644 --- a/packages/stream_chat/lib/src/core/models/channel_state.g.dart +++ b/packages/stream_chat/lib/src/core/models/channel_state.g.dart @@ -19,7 +19,7 @@ ChannelState _$ChannelStateFromJson(Map json) => ChannelState( pinnedMessages: (json['pinned_messages'] as List?) ?.map((e) => Message.fromJson(e as Map)) .toList(), - watcherCount: json['watcher_count'] as int?, + watcherCount: (json['watcher_count'] as num?)?.toInt(), watchers: (json['watchers'] as List?) ?.map((e) => User.fromJson(e as Map)) .toList(), diff --git a/packages/stream_chat/lib/src/core/models/event.g.dart b/packages/stream_chat/lib/src/core/models/event.g.dart index 524b5bd9b..54dcce873 100644 --- a/packages/stream_chat/lib/src/core/models/event.g.dart +++ b/packages/stream_chat/lib/src/core/models/event.g.dart @@ -22,8 +22,8 @@ Event _$EventFromJson(Map json) => Event( message: json['message'] == null ? null : Message.fromJson(json['message'] as Map), - totalUnreadCount: json['total_unread_count'] as int?, - unreadChannels: json['unread_channels'] as int?, + totalUnreadCount: (json['total_unread_count'] as num?)?.toInt(), + unreadChannels: (json['unread_channels'] as num?)?.toInt(), reaction: json['reaction'] == null ? null : Reaction.fromJson(json['reaction'] as Map), @@ -97,8 +97,8 @@ EventChannel _$EventChannelFromJson(Map json) => EventChannel( deletedAt: json['deleted_at'] == null ? null : DateTime.parse(json['deleted_at'] as String), - memberCount: json['member_count'] as int? ?? 0, + memberCount: (json['member_count'] as num?)?.toInt() ?? 0, extraData: json['extra_data'] as Map?, - cooldown: json['cooldown'] as int? ?? 0, + cooldown: (json['cooldown'] as num?)?.toInt() ?? 0, team: json['team'] as String?, ); diff --git a/packages/stream_chat/lib/src/core/models/message.g.dart b/packages/stream_chat/lib/src/core/models/message.g.dart index 2b089a4d1..dfe672143 100644 --- a/packages/stream_chat/lib/src/core/models/message.g.dart +++ b/packages/stream_chat/lib/src/core/models/message.g.dart @@ -21,10 +21,10 @@ Message _$MessageFromJson(Map json) => Message( silent: json['silent'] as bool? ?? false, shadowed: json['shadowed'] as bool? ?? false, reactionCounts: (json['reaction_counts'] as Map?)?.map( - (k, e) => MapEntry(k, e as int), + (k, e) => MapEntry(k, (e as num).toInt()), ), reactionScores: (json['reaction_scores'] as Map?)?.map( - (k, e) => MapEntry(k, e as int), + (k, e) => MapEntry(k, (e as num).toInt()), ), latestReactions: (json['latest_reactions'] as List?) ?.map((e) => Reaction.fromJson(e as Map)) @@ -37,7 +37,7 @@ Message _$MessageFromJson(Map json) => Message( ? null : Message.fromJson(json['quoted_message'] as Map), quotedMessageId: json['quoted_message_id'] as String?, - replyCount: json['reply_count'] as int? ?? 0, + replyCount: (json['reply_count'] as num?)?.toInt() ?? 0, threadParticipants: (json['thread_participants'] as List?) ?.map((e) => User.fromJson(e as Map)) .toList(), diff --git a/packages/stream_chat/lib/src/core/models/message_state.freezed.dart b/packages/stream_chat/lib/src/core/models/message_state.freezed.dart index 5096839d9..584bc54b4 100644 --- a/packages/stream_chat/lib/src/core/models/message_state.freezed.dart +++ b/packages/stream_chat/lib/src/core/models/message_state.freezed.dart @@ -12,7 +12,7 @@ part of 'message_state.dart'; T _$identity(T value) => value; final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); MessageState _$MessageStateFromJson(Map json) { switch (json['runtimeType']) { @@ -83,6 +83,8 @@ mixin _$MessageState { required TResult orElse(), }) => throw _privateConstructorUsedError; + + /// Serializes this MessageState to a JSON map. Map toJson() => throw _privateConstructorUsedError; } @@ -102,31 +104,38 @@ class _$MessageStateCopyWithImpl<$Res, $Val extends MessageState> final $Val _value; // ignore: unused_field final $Res Function($Val) _then; + + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc -abstract class _$$MessageInitialCopyWith<$Res> { - factory _$$MessageInitialCopyWith( - _$MessageInitial value, $Res Function(_$MessageInitial) then) = - __$$MessageInitialCopyWithImpl<$Res>; +abstract class _$$MessageInitialImplCopyWith<$Res> { + factory _$$MessageInitialImplCopyWith(_$MessageInitialImpl value, + $Res Function(_$MessageInitialImpl) then) = + __$$MessageInitialImplCopyWithImpl<$Res>; } /// @nodoc -class __$$MessageInitialCopyWithImpl<$Res> - extends _$MessageStateCopyWithImpl<$Res, _$MessageInitial> - implements _$$MessageInitialCopyWith<$Res> { - __$$MessageInitialCopyWithImpl( - _$MessageInitial _value, $Res Function(_$MessageInitial) _then) +class __$$MessageInitialImplCopyWithImpl<$Res> + extends _$MessageStateCopyWithImpl<$Res, _$MessageInitialImpl> + implements _$$MessageInitialImplCopyWith<$Res> { + __$$MessageInitialImplCopyWithImpl( + _$MessageInitialImpl _value, $Res Function(_$MessageInitialImpl) _then) : super(_value, _then); + + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @JsonSerializable() -class _$MessageInitial implements MessageInitial { - const _$MessageInitial({final String? $type}) : $type = $type ?? 'initial'; +class _$MessageInitialImpl implements MessageInitial { + const _$MessageInitialImpl({final String? $type}) + : $type = $type ?? 'initial'; - factory _$MessageInitial.fromJson(Map json) => - _$$MessageInitialFromJson(json); + factory _$MessageInitialImpl.fromJson(Map json) => + _$$MessageInitialImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @@ -137,12 +146,12 @@ class _$MessageInitial implements MessageInitial { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$MessageInitial); + (other.runtimeType == runtimeType && other is _$MessageInitialImpl); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => runtimeType.hashCode; @@ -222,24 +231,24 @@ class _$MessageInitial implements MessageInitial { @override Map toJson() { - return _$$MessageInitialToJson( + return _$$MessageInitialImplToJson( this, ); } } abstract class MessageInitial implements MessageState { - const factory MessageInitial() = _$MessageInitial; + const factory MessageInitial() = _$MessageInitialImpl; factory MessageInitial.fromJson(Map json) = - _$MessageInitial.fromJson; + _$MessageInitialImpl.fromJson; } /// @nodoc -abstract class _$$MessageOutgoingCopyWith<$Res> { - factory _$$MessageOutgoingCopyWith( - _$MessageOutgoing value, $Res Function(_$MessageOutgoing) then) = - __$$MessageOutgoingCopyWithImpl<$Res>; +abstract class _$$MessageOutgoingImplCopyWith<$Res> { + factory _$$MessageOutgoingImplCopyWith(_$MessageOutgoingImpl value, + $Res Function(_$MessageOutgoingImpl) then) = + __$$MessageOutgoingImplCopyWithImpl<$Res>; @useResult $Res call({OutgoingState state}); @@ -247,19 +256,21 @@ abstract class _$$MessageOutgoingCopyWith<$Res> { } /// @nodoc -class __$$MessageOutgoingCopyWithImpl<$Res> - extends _$MessageStateCopyWithImpl<$Res, _$MessageOutgoing> - implements _$$MessageOutgoingCopyWith<$Res> { - __$$MessageOutgoingCopyWithImpl( - _$MessageOutgoing _value, $Res Function(_$MessageOutgoing) _then) +class __$$MessageOutgoingImplCopyWithImpl<$Res> + extends _$MessageStateCopyWithImpl<$Res, _$MessageOutgoingImpl> + implements _$$MessageOutgoingImplCopyWith<$Res> { + __$$MessageOutgoingImplCopyWithImpl( + _$MessageOutgoingImpl _value, $Res Function(_$MessageOutgoingImpl) _then) : super(_value, _then); + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ Object? state = null, }) { - return _then(_$MessageOutgoing( + return _then(_$MessageOutgoingImpl( state: null == state ? _value.state : state // ignore: cast_nullable_to_non_nullable @@ -267,6 +278,8 @@ class __$$MessageOutgoingCopyWithImpl<$Res> )); } + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') $OutgoingStateCopyWith<$Res> get state { @@ -278,12 +291,12 @@ class __$$MessageOutgoingCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$MessageOutgoing implements MessageOutgoing { - const _$MessageOutgoing({required this.state, final String? $type}) +class _$MessageOutgoingImpl implements MessageOutgoing { + const _$MessageOutgoingImpl({required this.state, final String? $type}) : $type = $type ?? 'outgoing'; - factory _$MessageOutgoing.fromJson(Map json) => - _$$MessageOutgoingFromJson(json); + factory _$MessageOutgoingImpl.fromJson(Map json) => + _$$MessageOutgoingImplFromJson(json); @override final OutgoingState state; @@ -297,22 +310,25 @@ class _$MessageOutgoing implements MessageOutgoing { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$MessageOutgoing && + other is _$MessageOutgoingImpl && (identical(other.state, state) || other.state == state)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, state); - @JsonKey(ignore: true) + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') - _$$MessageOutgoingCopyWith<_$MessageOutgoing> get copyWith => - __$$MessageOutgoingCopyWithImpl<_$MessageOutgoing>(this, _$identity); + _$$MessageOutgoingImplCopyWith<_$MessageOutgoingImpl> get copyWith => + __$$MessageOutgoingImplCopyWithImpl<_$MessageOutgoingImpl>( + this, _$identity); @override @optionalTypeArgs @@ -390,7 +406,7 @@ class _$MessageOutgoing implements MessageOutgoing { @override Map toJson() { - return _$$MessageOutgoingToJson( + return _$$MessageOutgoingImplToJson( this, ); } @@ -398,22 +414,25 @@ class _$MessageOutgoing implements MessageOutgoing { abstract class MessageOutgoing implements MessageState { const factory MessageOutgoing({required final OutgoingState state}) = - _$MessageOutgoing; + _$MessageOutgoingImpl; factory MessageOutgoing.fromJson(Map json) = - _$MessageOutgoing.fromJson; + _$MessageOutgoingImpl.fromJson; OutgoingState get state; - @JsonKey(ignore: true) - _$$MessageOutgoingCopyWith<_$MessageOutgoing> get copyWith => + + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MessageOutgoingImplCopyWith<_$MessageOutgoingImpl> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$MessageCompletedCopyWith<$Res> { - factory _$$MessageCompletedCopyWith( - _$MessageCompleted value, $Res Function(_$MessageCompleted) then) = - __$$MessageCompletedCopyWithImpl<$Res>; +abstract class _$$MessageCompletedImplCopyWith<$Res> { + factory _$$MessageCompletedImplCopyWith(_$MessageCompletedImpl value, + $Res Function(_$MessageCompletedImpl) then) = + __$$MessageCompletedImplCopyWithImpl<$Res>; @useResult $Res call({CompletedState state}); @@ -421,19 +440,21 @@ abstract class _$$MessageCompletedCopyWith<$Res> { } /// @nodoc -class __$$MessageCompletedCopyWithImpl<$Res> - extends _$MessageStateCopyWithImpl<$Res, _$MessageCompleted> - implements _$$MessageCompletedCopyWith<$Res> { - __$$MessageCompletedCopyWithImpl( - _$MessageCompleted _value, $Res Function(_$MessageCompleted) _then) +class __$$MessageCompletedImplCopyWithImpl<$Res> + extends _$MessageStateCopyWithImpl<$Res, _$MessageCompletedImpl> + implements _$$MessageCompletedImplCopyWith<$Res> { + __$$MessageCompletedImplCopyWithImpl(_$MessageCompletedImpl _value, + $Res Function(_$MessageCompletedImpl) _then) : super(_value, _then); + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ Object? state = null, }) { - return _then(_$MessageCompleted( + return _then(_$MessageCompletedImpl( state: null == state ? _value.state : state // ignore: cast_nullable_to_non_nullable @@ -441,6 +462,8 @@ class __$$MessageCompletedCopyWithImpl<$Res> )); } + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') $CompletedStateCopyWith<$Res> get state { @@ -452,12 +475,12 @@ class __$$MessageCompletedCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$MessageCompleted implements MessageCompleted { - const _$MessageCompleted({required this.state, final String? $type}) +class _$MessageCompletedImpl implements MessageCompleted { + const _$MessageCompletedImpl({required this.state, final String? $type}) : $type = $type ?? 'completed'; - factory _$MessageCompleted.fromJson(Map json) => - _$$MessageCompletedFromJson(json); + factory _$MessageCompletedImpl.fromJson(Map json) => + _$$MessageCompletedImplFromJson(json); @override final CompletedState state; @@ -471,22 +494,25 @@ class _$MessageCompleted implements MessageCompleted { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$MessageCompleted && + other is _$MessageCompletedImpl && (identical(other.state, state) || other.state == state)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, state); - @JsonKey(ignore: true) + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') - _$$MessageCompletedCopyWith<_$MessageCompleted> get copyWith => - __$$MessageCompletedCopyWithImpl<_$MessageCompleted>(this, _$identity); + _$$MessageCompletedImplCopyWith<_$MessageCompletedImpl> get copyWith => + __$$MessageCompletedImplCopyWithImpl<_$MessageCompletedImpl>( + this, _$identity); @override @optionalTypeArgs @@ -564,7 +590,7 @@ class _$MessageCompleted implements MessageCompleted { @override Map toJson() { - return _$$MessageCompletedToJson( + return _$$MessageCompletedImplToJson( this, ); } @@ -572,22 +598,25 @@ class _$MessageCompleted implements MessageCompleted { abstract class MessageCompleted implements MessageState { const factory MessageCompleted({required final CompletedState state}) = - _$MessageCompleted; + _$MessageCompletedImpl; factory MessageCompleted.fromJson(Map json) = - _$MessageCompleted.fromJson; + _$MessageCompletedImpl.fromJson; CompletedState get state; - @JsonKey(ignore: true) - _$$MessageCompletedCopyWith<_$MessageCompleted> get copyWith => + + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MessageCompletedImplCopyWith<_$MessageCompletedImpl> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$MessageFailedCopyWith<$Res> { - factory _$$MessageFailedCopyWith( - _$MessageFailed value, $Res Function(_$MessageFailed) then) = - __$$MessageFailedCopyWithImpl<$Res>; +abstract class _$$MessageFailedImplCopyWith<$Res> { + factory _$$MessageFailedImplCopyWith( + _$MessageFailedImpl value, $Res Function(_$MessageFailedImpl) then) = + __$$MessageFailedImplCopyWithImpl<$Res>; @useResult $Res call({FailedState state, Object? reason}); @@ -595,20 +624,22 @@ abstract class _$$MessageFailedCopyWith<$Res> { } /// @nodoc -class __$$MessageFailedCopyWithImpl<$Res> - extends _$MessageStateCopyWithImpl<$Res, _$MessageFailed> - implements _$$MessageFailedCopyWith<$Res> { - __$$MessageFailedCopyWithImpl( - _$MessageFailed _value, $Res Function(_$MessageFailed) _then) +class __$$MessageFailedImplCopyWithImpl<$Res> + extends _$MessageStateCopyWithImpl<$Res, _$MessageFailedImpl> + implements _$$MessageFailedImplCopyWith<$Res> { + __$$MessageFailedImplCopyWithImpl( + _$MessageFailedImpl _value, $Res Function(_$MessageFailedImpl) _then) : super(_value, _then); + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ Object? state = null, Object? reason = freezed, }) { - return _then(_$MessageFailed( + return _then(_$MessageFailedImpl( state: null == state ? _value.state : state // ignore: cast_nullable_to_non_nullable @@ -617,6 +648,8 @@ class __$$MessageFailedCopyWithImpl<$Res> )); } + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') $FailedStateCopyWith<$Res> get state { @@ -628,12 +661,13 @@ class __$$MessageFailedCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$MessageFailed implements MessageFailed { - const _$MessageFailed({required this.state, this.reason, final String? $type}) +class _$MessageFailedImpl implements MessageFailed { + const _$MessageFailedImpl( + {required this.state, this.reason, final String? $type}) : $type = $type ?? 'failed'; - factory _$MessageFailed.fromJson(Map json) => - _$$MessageFailedFromJson(json); + factory _$MessageFailedImpl.fromJson(Map json) => + _$$MessageFailedImplFromJson(json); @override final FailedState state; @@ -649,24 +683,26 @@ class _$MessageFailed implements MessageFailed { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$MessageFailed && + other is _$MessageFailedImpl && (identical(other.state, state) || other.state == state) && const DeepCollectionEquality().equals(other.reason, reason)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash( runtimeType, state, const DeepCollectionEquality().hash(reason)); - @JsonKey(ignore: true) + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') - _$$MessageFailedCopyWith<_$MessageFailed> get copyWith => - __$$MessageFailedCopyWithImpl<_$MessageFailed>(this, _$identity); + _$$MessageFailedImplCopyWith<_$MessageFailedImpl> get copyWith => + __$$MessageFailedImplCopyWithImpl<_$MessageFailedImpl>(this, _$identity); @override @optionalTypeArgs @@ -744,7 +780,7 @@ class _$MessageFailed implements MessageFailed { @override Map toJson() { - return _$$MessageFailedToJson( + return _$$MessageFailedImplToJson( this, ); } @@ -753,15 +789,18 @@ class _$MessageFailed implements MessageFailed { abstract class MessageFailed implements MessageState { const factory MessageFailed( {required final FailedState state, - final Object? reason}) = _$MessageFailed; + final Object? reason}) = _$MessageFailedImpl; factory MessageFailed.fromJson(Map json) = - _$MessageFailed.fromJson; + _$MessageFailedImpl.fromJson; FailedState get state; Object? get reason; - @JsonKey(ignore: true) - _$$MessageFailedCopyWith<_$MessageFailed> get copyWith => + + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MessageFailedImplCopyWith<_$MessageFailedImpl> get copyWith => throw _privateConstructorUsedError; } @@ -826,6 +865,8 @@ mixin _$OutgoingState { required TResult orElse(), }) => throw _privateConstructorUsedError; + + /// Serializes this OutgoingState to a JSON map. Map toJson() => throw _privateConstructorUsedError; } @@ -845,29 +886,37 @@ class _$OutgoingStateCopyWithImpl<$Res, $Val extends OutgoingState> final $Val _value; // ignore: unused_field final $Res Function($Val) _then; + + /// Create a copy of OutgoingState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc -abstract class _$$SendingCopyWith<$Res> { - factory _$$SendingCopyWith(_$Sending value, $Res Function(_$Sending) then) = - __$$SendingCopyWithImpl<$Res>; +abstract class _$$SendingImplCopyWith<$Res> { + factory _$$SendingImplCopyWith( + _$SendingImpl value, $Res Function(_$SendingImpl) then) = + __$$SendingImplCopyWithImpl<$Res>; } /// @nodoc -class __$$SendingCopyWithImpl<$Res> - extends _$OutgoingStateCopyWithImpl<$Res, _$Sending> - implements _$$SendingCopyWith<$Res> { - __$$SendingCopyWithImpl(_$Sending _value, $Res Function(_$Sending) _then) +class __$$SendingImplCopyWithImpl<$Res> + extends _$OutgoingStateCopyWithImpl<$Res, _$SendingImpl> + implements _$$SendingImplCopyWith<$Res> { + __$$SendingImplCopyWithImpl( + _$SendingImpl _value, $Res Function(_$SendingImpl) _then) : super(_value, _then); + + /// Create a copy of OutgoingState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @JsonSerializable() -class _$Sending implements Sending { - const _$Sending({final String? $type}) : $type = $type ?? 'sending'; +class _$SendingImpl implements Sending { + const _$SendingImpl({final String? $type}) : $type = $type ?? 'sending'; - factory _$Sending.fromJson(Map json) => - _$$SendingFromJson(json); + factory _$SendingImpl.fromJson(Map json) => + _$$SendingImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @@ -878,12 +927,12 @@ class _$Sending implements Sending { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$Sending); + (other.runtimeType == runtimeType && other is _$SendingImpl); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => runtimeType.hashCode; @@ -957,40 +1006,44 @@ class _$Sending implements Sending { @override Map toJson() { - return _$$SendingToJson( + return _$$SendingImplToJson( this, ); } } abstract class Sending implements OutgoingState { - const factory Sending() = _$Sending; + const factory Sending() = _$SendingImpl; - factory Sending.fromJson(Map json) = _$Sending.fromJson; + factory Sending.fromJson(Map json) = _$SendingImpl.fromJson; } /// @nodoc -abstract class _$$UpdatingCopyWith<$Res> { - factory _$$UpdatingCopyWith( - _$Updating value, $Res Function(_$Updating) then) = - __$$UpdatingCopyWithImpl<$Res>; +abstract class _$$UpdatingImplCopyWith<$Res> { + factory _$$UpdatingImplCopyWith( + _$UpdatingImpl value, $Res Function(_$UpdatingImpl) then) = + __$$UpdatingImplCopyWithImpl<$Res>; } /// @nodoc -class __$$UpdatingCopyWithImpl<$Res> - extends _$OutgoingStateCopyWithImpl<$Res, _$Updating> - implements _$$UpdatingCopyWith<$Res> { - __$$UpdatingCopyWithImpl(_$Updating _value, $Res Function(_$Updating) _then) +class __$$UpdatingImplCopyWithImpl<$Res> + extends _$OutgoingStateCopyWithImpl<$Res, _$UpdatingImpl> + implements _$$UpdatingImplCopyWith<$Res> { + __$$UpdatingImplCopyWithImpl( + _$UpdatingImpl _value, $Res Function(_$UpdatingImpl) _then) : super(_value, _then); + + /// Create a copy of OutgoingState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @JsonSerializable() -class _$Updating implements Updating { - const _$Updating({final String? $type}) : $type = $type ?? 'updating'; +class _$UpdatingImpl implements Updating { + const _$UpdatingImpl({final String? $type}) : $type = $type ?? 'updating'; - factory _$Updating.fromJson(Map json) => - _$$UpdatingFromJson(json); + factory _$UpdatingImpl.fromJson(Map json) => + _$$UpdatingImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @@ -1001,12 +1054,12 @@ class _$Updating implements Updating { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$Updating); + (other.runtimeType == runtimeType && other is _$UpdatingImpl); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => runtimeType.hashCode; @@ -1080,40 +1133,44 @@ class _$Updating implements Updating { @override Map toJson() { - return _$$UpdatingToJson( + return _$$UpdatingImplToJson( this, ); } } abstract class Updating implements OutgoingState { - const factory Updating() = _$Updating; + const factory Updating() = _$UpdatingImpl; - factory Updating.fromJson(Map json) = _$Updating.fromJson; + factory Updating.fromJson(Map json) = + _$UpdatingImpl.fromJson; } /// @nodoc -abstract class _$$DeletingCopyWith<$Res> { - factory _$$DeletingCopyWith( - _$Deleting value, $Res Function(_$Deleting) then) = - __$$DeletingCopyWithImpl<$Res>; +abstract class _$$DeletingImplCopyWith<$Res> { + factory _$$DeletingImplCopyWith( + _$DeletingImpl value, $Res Function(_$DeletingImpl) then) = + __$$DeletingImplCopyWithImpl<$Res>; @useResult $Res call({bool hard}); } /// @nodoc -class __$$DeletingCopyWithImpl<$Res> - extends _$OutgoingStateCopyWithImpl<$Res, _$Deleting> - implements _$$DeletingCopyWith<$Res> { - __$$DeletingCopyWithImpl(_$Deleting _value, $Res Function(_$Deleting) _then) +class __$$DeletingImplCopyWithImpl<$Res> + extends _$OutgoingStateCopyWithImpl<$Res, _$DeletingImpl> + implements _$$DeletingImplCopyWith<$Res> { + __$$DeletingImplCopyWithImpl( + _$DeletingImpl _value, $Res Function(_$DeletingImpl) _then) : super(_value, _then); + /// Create a copy of OutgoingState + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ Object? hard = null, }) { - return _then(_$Deleting( + return _then(_$DeletingImpl( hard: null == hard ? _value.hard : hard // ignore: cast_nullable_to_non_nullable @@ -1124,12 +1181,12 @@ class __$$DeletingCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$Deleting implements Deleting { - const _$Deleting({this.hard = false, final String? $type}) +class _$DeletingImpl implements Deleting { + const _$DeletingImpl({this.hard = false, final String? $type}) : $type = $type ?? 'deleting'; - factory _$Deleting.fromJson(Map json) => - _$$DeletingFromJson(json); + factory _$DeletingImpl.fromJson(Map json) => + _$$DeletingImplFromJson(json); @override @JsonKey() @@ -1144,22 +1201,24 @@ class _$Deleting implements Deleting { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$Deleting && + other is _$DeletingImpl && (identical(other.hard, hard) || other.hard == hard)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, hard); - @JsonKey(ignore: true) + /// Create a copy of OutgoingState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') - _$$DeletingCopyWith<_$Deleting> get copyWith => - __$$DeletingCopyWithImpl<_$Deleting>(this, _$identity); + _$$DeletingImplCopyWith<_$DeletingImpl> get copyWith => + __$$DeletingImplCopyWithImpl<_$DeletingImpl>(this, _$identity); @override @optionalTypeArgs @@ -1231,20 +1290,24 @@ class _$Deleting implements Deleting { @override Map toJson() { - return _$$DeletingToJson( + return _$$DeletingImplToJson( this, ); } } abstract class Deleting implements OutgoingState { - const factory Deleting({final bool hard}) = _$Deleting; + const factory Deleting({final bool hard}) = _$DeletingImpl; - factory Deleting.fromJson(Map json) = _$Deleting.fromJson; + factory Deleting.fromJson(Map json) = + _$DeletingImpl.fromJson; bool get hard; - @JsonKey(ignore: true) - _$$DeletingCopyWith<_$Deleting> get copyWith => + + /// Create a copy of OutgoingState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$DeletingImplCopyWith<_$DeletingImpl> get copyWith => throw _privateConstructorUsedError; } @@ -1309,6 +1372,8 @@ mixin _$CompletedState { required TResult orElse(), }) => throw _privateConstructorUsedError; + + /// Serializes this CompletedState to a JSON map. Map toJson() => throw _privateConstructorUsedError; } @@ -1328,28 +1393,36 @@ class _$CompletedStateCopyWithImpl<$Res, $Val extends CompletedState> final $Val _value; // ignore: unused_field final $Res Function($Val) _then; + + /// Create a copy of CompletedState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc -abstract class _$$SentCopyWith<$Res> { - factory _$$SentCopyWith(_$Sent value, $Res Function(_$Sent) then) = - __$$SentCopyWithImpl<$Res>; +abstract class _$$SentImplCopyWith<$Res> { + factory _$$SentImplCopyWith( + _$SentImpl value, $Res Function(_$SentImpl) then) = + __$$SentImplCopyWithImpl<$Res>; } /// @nodoc -class __$$SentCopyWithImpl<$Res> - extends _$CompletedStateCopyWithImpl<$Res, _$Sent> - implements _$$SentCopyWith<$Res> { - __$$SentCopyWithImpl(_$Sent _value, $Res Function(_$Sent) _then) +class __$$SentImplCopyWithImpl<$Res> + extends _$CompletedStateCopyWithImpl<$Res, _$SentImpl> + implements _$$SentImplCopyWith<$Res> { + __$$SentImplCopyWithImpl(_$SentImpl _value, $Res Function(_$SentImpl) _then) : super(_value, _then); + + /// Create a copy of CompletedState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @JsonSerializable() -class _$Sent implements Sent { - const _$Sent({final String? $type}) : $type = $type ?? 'sent'; +class _$SentImpl implements Sent { + const _$SentImpl({final String? $type}) : $type = $type ?? 'sent'; - factory _$Sent.fromJson(Map json) => _$$SentFromJson(json); + factory _$SentImpl.fromJson(Map json) => + _$$SentImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @@ -1360,12 +1433,12 @@ class _$Sent implements Sent { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$Sent); + (other.runtimeType == runtimeType && other is _$SentImpl); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => runtimeType.hashCode; @@ -1439,39 +1512,44 @@ class _$Sent implements Sent { @override Map toJson() { - return _$$SentToJson( + return _$$SentImplToJson( this, ); } } abstract class Sent implements CompletedState { - const factory Sent() = _$Sent; + const factory Sent() = _$SentImpl; - factory Sent.fromJson(Map json) = _$Sent.fromJson; + factory Sent.fromJson(Map json) = _$SentImpl.fromJson; } /// @nodoc -abstract class _$$UpdatedCopyWith<$Res> { - factory _$$UpdatedCopyWith(_$Updated value, $Res Function(_$Updated) then) = - __$$UpdatedCopyWithImpl<$Res>; +abstract class _$$UpdatedImplCopyWith<$Res> { + factory _$$UpdatedImplCopyWith( + _$UpdatedImpl value, $Res Function(_$UpdatedImpl) then) = + __$$UpdatedImplCopyWithImpl<$Res>; } /// @nodoc -class __$$UpdatedCopyWithImpl<$Res> - extends _$CompletedStateCopyWithImpl<$Res, _$Updated> - implements _$$UpdatedCopyWith<$Res> { - __$$UpdatedCopyWithImpl(_$Updated _value, $Res Function(_$Updated) _then) +class __$$UpdatedImplCopyWithImpl<$Res> + extends _$CompletedStateCopyWithImpl<$Res, _$UpdatedImpl> + implements _$$UpdatedImplCopyWith<$Res> { + __$$UpdatedImplCopyWithImpl( + _$UpdatedImpl _value, $Res Function(_$UpdatedImpl) _then) : super(_value, _then); + + /// Create a copy of CompletedState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @JsonSerializable() -class _$Updated implements Updated { - const _$Updated({final String? $type}) : $type = $type ?? 'updated'; +class _$UpdatedImpl implements Updated { + const _$UpdatedImpl({final String? $type}) : $type = $type ?? 'updated'; - factory _$Updated.fromJson(Map json) => - _$$UpdatedFromJson(json); + factory _$UpdatedImpl.fromJson(Map json) => + _$$UpdatedImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @@ -1482,12 +1560,12 @@ class _$Updated implements Updated { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$Updated); + (other.runtimeType == runtimeType && other is _$UpdatedImpl); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => runtimeType.hashCode; @@ -1561,39 +1639,43 @@ class _$Updated implements Updated { @override Map toJson() { - return _$$UpdatedToJson( + return _$$UpdatedImplToJson( this, ); } } abstract class Updated implements CompletedState { - const factory Updated() = _$Updated; + const factory Updated() = _$UpdatedImpl; - factory Updated.fromJson(Map json) = _$Updated.fromJson; + factory Updated.fromJson(Map json) = _$UpdatedImpl.fromJson; } /// @nodoc -abstract class _$$DeletedCopyWith<$Res> { - factory _$$DeletedCopyWith(_$Deleted value, $Res Function(_$Deleted) then) = - __$$DeletedCopyWithImpl<$Res>; +abstract class _$$DeletedImplCopyWith<$Res> { + factory _$$DeletedImplCopyWith( + _$DeletedImpl value, $Res Function(_$DeletedImpl) then) = + __$$DeletedImplCopyWithImpl<$Res>; @useResult $Res call({bool hard}); } /// @nodoc -class __$$DeletedCopyWithImpl<$Res> - extends _$CompletedStateCopyWithImpl<$Res, _$Deleted> - implements _$$DeletedCopyWith<$Res> { - __$$DeletedCopyWithImpl(_$Deleted _value, $Res Function(_$Deleted) _then) +class __$$DeletedImplCopyWithImpl<$Res> + extends _$CompletedStateCopyWithImpl<$Res, _$DeletedImpl> + implements _$$DeletedImplCopyWith<$Res> { + __$$DeletedImplCopyWithImpl( + _$DeletedImpl _value, $Res Function(_$DeletedImpl) _then) : super(_value, _then); + /// Create a copy of CompletedState + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ Object? hard = null, }) { - return _then(_$Deleted( + return _then(_$DeletedImpl( hard: null == hard ? _value.hard : hard // ignore: cast_nullable_to_non_nullable @@ -1604,12 +1686,12 @@ class __$$DeletedCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$Deleted implements Deleted { - const _$Deleted({this.hard = false, final String? $type}) +class _$DeletedImpl implements Deleted { + const _$DeletedImpl({this.hard = false, final String? $type}) : $type = $type ?? 'deleted'; - factory _$Deleted.fromJson(Map json) => - _$$DeletedFromJson(json); + factory _$DeletedImpl.fromJson(Map json) => + _$$DeletedImplFromJson(json); @override @JsonKey() @@ -1624,22 +1706,24 @@ class _$Deleted implements Deleted { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$Deleted && + other is _$DeletedImpl && (identical(other.hard, hard) || other.hard == hard)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, hard); - @JsonKey(ignore: true) + /// Create a copy of CompletedState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') - _$$DeletedCopyWith<_$Deleted> get copyWith => - __$$DeletedCopyWithImpl<_$Deleted>(this, _$identity); + _$$DeletedImplCopyWith<_$DeletedImpl> get copyWith => + __$$DeletedImplCopyWithImpl<_$DeletedImpl>(this, _$identity); @override @optionalTypeArgs @@ -1711,20 +1795,23 @@ class _$Deleted implements Deleted { @override Map toJson() { - return _$$DeletedToJson( + return _$$DeletedImplToJson( this, ); } } abstract class Deleted implements CompletedState { - const factory Deleted({final bool hard}) = _$Deleted; + const factory Deleted({final bool hard}) = _$DeletedImpl; - factory Deleted.fromJson(Map json) = _$Deleted.fromJson; + factory Deleted.fromJson(Map json) = _$DeletedImpl.fromJson; bool get hard; - @JsonKey(ignore: true) - _$$DeletedCopyWith<_$Deleted> get copyWith => + + /// Create a copy of CompletedState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$DeletedImplCopyWith<_$DeletedImpl> get copyWith => throw _privateConstructorUsedError; } @@ -1789,6 +1876,8 @@ mixin _$FailedState { required TResult orElse(), }) => throw _privateConstructorUsedError; + + /// Serializes this FailedState to a JSON map. Map toJson() => throw _privateConstructorUsedError; } @@ -1808,32 +1897,38 @@ class _$FailedStateCopyWithImpl<$Res, $Val extends FailedState> final $Val _value; // ignore: unused_field final $Res Function($Val) _then; + + /// Create a copy of FailedState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc -abstract class _$$SendingFailedCopyWith<$Res> { - factory _$$SendingFailedCopyWith( - _$SendingFailed value, $Res Function(_$SendingFailed) then) = - __$$SendingFailedCopyWithImpl<$Res>; +abstract class _$$SendingFailedImplCopyWith<$Res> { + factory _$$SendingFailedImplCopyWith( + _$SendingFailedImpl value, $Res Function(_$SendingFailedImpl) then) = + __$$SendingFailedImplCopyWithImpl<$Res>; } /// @nodoc -class __$$SendingFailedCopyWithImpl<$Res> - extends _$FailedStateCopyWithImpl<$Res, _$SendingFailed> - implements _$$SendingFailedCopyWith<$Res> { - __$$SendingFailedCopyWithImpl( - _$SendingFailed _value, $Res Function(_$SendingFailed) _then) +class __$$SendingFailedImplCopyWithImpl<$Res> + extends _$FailedStateCopyWithImpl<$Res, _$SendingFailedImpl> + implements _$$SendingFailedImplCopyWith<$Res> { + __$$SendingFailedImplCopyWithImpl( + _$SendingFailedImpl _value, $Res Function(_$SendingFailedImpl) _then) : super(_value, _then); + + /// Create a copy of FailedState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @JsonSerializable() -class _$SendingFailed implements SendingFailed { - const _$SendingFailed({final String? $type}) +class _$SendingFailedImpl implements SendingFailed { + const _$SendingFailedImpl({final String? $type}) : $type = $type ?? 'sendingFailed'; - factory _$SendingFailed.fromJson(Map json) => - _$$SendingFailedFromJson(json); + factory _$SendingFailedImpl.fromJson(Map json) => + _$$SendingFailedImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @@ -1844,12 +1939,12 @@ class _$SendingFailed implements SendingFailed { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$SendingFailed); + (other.runtimeType == runtimeType && other is _$SendingFailedImpl); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => runtimeType.hashCode; @@ -1923,43 +2018,46 @@ class _$SendingFailed implements SendingFailed { @override Map toJson() { - return _$$SendingFailedToJson( + return _$$SendingFailedImplToJson( this, ); } } abstract class SendingFailed implements FailedState { - const factory SendingFailed() = _$SendingFailed; + const factory SendingFailed() = _$SendingFailedImpl; factory SendingFailed.fromJson(Map json) = - _$SendingFailed.fromJson; + _$SendingFailedImpl.fromJson; } /// @nodoc -abstract class _$$UpdatingFailedCopyWith<$Res> { - factory _$$UpdatingFailedCopyWith( - _$UpdatingFailed value, $Res Function(_$UpdatingFailed) then) = - __$$UpdatingFailedCopyWithImpl<$Res>; +abstract class _$$UpdatingFailedImplCopyWith<$Res> { + factory _$$UpdatingFailedImplCopyWith(_$UpdatingFailedImpl value, + $Res Function(_$UpdatingFailedImpl) then) = + __$$UpdatingFailedImplCopyWithImpl<$Res>; } /// @nodoc -class __$$UpdatingFailedCopyWithImpl<$Res> - extends _$FailedStateCopyWithImpl<$Res, _$UpdatingFailed> - implements _$$UpdatingFailedCopyWith<$Res> { - __$$UpdatingFailedCopyWithImpl( - _$UpdatingFailed _value, $Res Function(_$UpdatingFailed) _then) +class __$$UpdatingFailedImplCopyWithImpl<$Res> + extends _$FailedStateCopyWithImpl<$Res, _$UpdatingFailedImpl> + implements _$$UpdatingFailedImplCopyWith<$Res> { + __$$UpdatingFailedImplCopyWithImpl( + _$UpdatingFailedImpl _value, $Res Function(_$UpdatingFailedImpl) _then) : super(_value, _then); + + /// Create a copy of FailedState + /// with the given fields replaced by the non-null parameter values. } /// @nodoc @JsonSerializable() -class _$UpdatingFailed implements UpdatingFailed { - const _$UpdatingFailed({final String? $type}) +class _$UpdatingFailedImpl implements UpdatingFailed { + const _$UpdatingFailedImpl({final String? $type}) : $type = $type ?? 'updatingFailed'; - factory _$UpdatingFailed.fromJson(Map json) => - _$$UpdatingFailedFromJson(json); + factory _$UpdatingFailedImpl.fromJson(Map json) => + _$$UpdatingFailedImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @@ -1970,12 +2068,12 @@ class _$UpdatingFailed implements UpdatingFailed { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$UpdatingFailed); + (other.runtimeType == runtimeType && other is _$UpdatingFailedImpl); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => runtimeType.hashCode; @@ -2049,42 +2147,44 @@ class _$UpdatingFailed implements UpdatingFailed { @override Map toJson() { - return _$$UpdatingFailedToJson( + return _$$UpdatingFailedImplToJson( this, ); } } abstract class UpdatingFailed implements FailedState { - const factory UpdatingFailed() = _$UpdatingFailed; + const factory UpdatingFailed() = _$UpdatingFailedImpl; factory UpdatingFailed.fromJson(Map json) = - _$UpdatingFailed.fromJson; + _$UpdatingFailedImpl.fromJson; } /// @nodoc -abstract class _$$DeletingFailedCopyWith<$Res> { - factory _$$DeletingFailedCopyWith( - _$DeletingFailed value, $Res Function(_$DeletingFailed) then) = - __$$DeletingFailedCopyWithImpl<$Res>; +abstract class _$$DeletingFailedImplCopyWith<$Res> { + factory _$$DeletingFailedImplCopyWith(_$DeletingFailedImpl value, + $Res Function(_$DeletingFailedImpl) then) = + __$$DeletingFailedImplCopyWithImpl<$Res>; @useResult $Res call({bool hard}); } /// @nodoc -class __$$DeletingFailedCopyWithImpl<$Res> - extends _$FailedStateCopyWithImpl<$Res, _$DeletingFailed> - implements _$$DeletingFailedCopyWith<$Res> { - __$$DeletingFailedCopyWithImpl( - _$DeletingFailed _value, $Res Function(_$DeletingFailed) _then) +class __$$DeletingFailedImplCopyWithImpl<$Res> + extends _$FailedStateCopyWithImpl<$Res, _$DeletingFailedImpl> + implements _$$DeletingFailedImplCopyWith<$Res> { + __$$DeletingFailedImplCopyWithImpl( + _$DeletingFailedImpl _value, $Res Function(_$DeletingFailedImpl) _then) : super(_value, _then); + /// Create a copy of FailedState + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({ Object? hard = null, }) { - return _then(_$DeletingFailed( + return _then(_$DeletingFailedImpl( hard: null == hard ? _value.hard : hard // ignore: cast_nullable_to_non_nullable @@ -2095,12 +2195,12 @@ class __$$DeletingFailedCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$DeletingFailed implements DeletingFailed { - const _$DeletingFailed({this.hard = false, final String? $type}) +class _$DeletingFailedImpl implements DeletingFailed { + const _$DeletingFailedImpl({this.hard = false, final String? $type}) : $type = $type ?? 'deletingFailed'; - factory _$DeletingFailed.fromJson(Map json) => - _$$DeletingFailedFromJson(json); + factory _$DeletingFailedImpl.fromJson(Map json) => + _$$DeletingFailedImplFromJson(json); @override @JsonKey() @@ -2115,22 +2215,25 @@ class _$DeletingFailed implements DeletingFailed { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$DeletingFailed && + other is _$DeletingFailedImpl && (identical(other.hard, hard) || other.hard == hard)); } - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, hard); - @JsonKey(ignore: true) + /// Create a copy of FailedState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override @pragma('vm:prefer-inline') - _$$DeletingFailedCopyWith<_$DeletingFailed> get copyWith => - __$$DeletingFailedCopyWithImpl<_$DeletingFailed>(this, _$identity); + _$$DeletingFailedImplCopyWith<_$DeletingFailedImpl> get copyWith => + __$$DeletingFailedImplCopyWithImpl<_$DeletingFailedImpl>( + this, _$identity); @override @optionalTypeArgs @@ -2202,20 +2305,23 @@ class _$DeletingFailed implements DeletingFailed { @override Map toJson() { - return _$$DeletingFailedToJson( + return _$$DeletingFailedImplToJson( this, ); } } abstract class DeletingFailed implements FailedState { - const factory DeletingFailed({final bool hard}) = _$DeletingFailed; + const factory DeletingFailed({final bool hard}) = _$DeletingFailedImpl; factory DeletingFailed.fromJson(Map json) = - _$DeletingFailed.fromJson; + _$DeletingFailedImpl.fromJson; bool get hard; - @JsonKey(ignore: true) - _$$DeletingFailedCopyWith<_$DeletingFailed> get copyWith => + + /// Create a copy of FailedState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$DeletingFailedImplCopyWith<_$DeletingFailedImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/packages/stream_chat/lib/src/core/models/message_state.g.dart b/packages/stream_chat/lib/src/core/models/message_state.g.dart index 708222bf5..7cf2531c8 100644 --- a/packages/stream_chat/lib/src/core/models/message_state.g.dart +++ b/packages/stream_chat/lib/src/core/models/message_state.g.dart @@ -6,135 +6,151 @@ part of 'message_state.dart'; // JsonSerializableGenerator // ************************************************************************** -_$MessageInitial _$$MessageInitialFromJson(Map json) => - _$MessageInitial( +_$MessageInitialImpl _$$MessageInitialImplFromJson(Map json) => + _$MessageInitialImpl( $type: json['runtimeType'] as String?, ); -Map _$$MessageInitialToJson(_$MessageInitial instance) => +Map _$$MessageInitialImplToJson( + _$MessageInitialImpl instance) => { 'runtimeType': instance.$type, }; -_$MessageOutgoing _$$MessageOutgoingFromJson(Map json) => - _$MessageOutgoing( +_$MessageOutgoingImpl _$$MessageOutgoingImplFromJson( + Map json) => + _$MessageOutgoingImpl( state: OutgoingState.fromJson(json['state'] as Map), $type: json['runtimeType'] as String?, ); -Map _$$MessageOutgoingToJson(_$MessageOutgoing instance) => +Map _$$MessageOutgoingImplToJson( + _$MessageOutgoingImpl instance) => { 'state': instance.state.toJson(), 'runtimeType': instance.$type, }; -_$MessageCompleted _$$MessageCompletedFromJson(Map json) => - _$MessageCompleted( +_$MessageCompletedImpl _$$MessageCompletedImplFromJson( + Map json) => + _$MessageCompletedImpl( state: CompletedState.fromJson(json['state'] as Map), $type: json['runtimeType'] as String?, ); -Map _$$MessageCompletedToJson(_$MessageCompleted instance) => +Map _$$MessageCompletedImplToJson( + _$MessageCompletedImpl instance) => { 'state': instance.state.toJson(), 'runtimeType': instance.$type, }; -_$MessageFailed _$$MessageFailedFromJson(Map json) => - _$MessageFailed( +_$MessageFailedImpl _$$MessageFailedImplFromJson(Map json) => + _$MessageFailedImpl( state: FailedState.fromJson(json['state'] as Map), reason: json['reason'], $type: json['runtimeType'] as String?, ); -Map _$$MessageFailedToJson(_$MessageFailed instance) => +Map _$$MessageFailedImplToJson(_$MessageFailedImpl instance) => { 'state': instance.state.toJson(), 'reason': instance.reason, 'runtimeType': instance.$type, }; -_$Sending _$$SendingFromJson(Map json) => _$Sending( +_$SendingImpl _$$SendingImplFromJson(Map json) => + _$SendingImpl( $type: json['runtimeType'] as String?, ); -Map _$$SendingToJson(_$Sending instance) => { +Map _$$SendingImplToJson(_$SendingImpl instance) => + { 'runtimeType': instance.$type, }; -_$Updating _$$UpdatingFromJson(Map json) => _$Updating( +_$UpdatingImpl _$$UpdatingImplFromJson(Map json) => + _$UpdatingImpl( $type: json['runtimeType'] as String?, ); -Map _$$UpdatingToJson(_$Updating instance) => +Map _$$UpdatingImplToJson(_$UpdatingImpl instance) => { 'runtimeType': instance.$type, }; -_$Deleting _$$DeletingFromJson(Map json) => _$Deleting( +_$DeletingImpl _$$DeletingImplFromJson(Map json) => + _$DeletingImpl( hard: json['hard'] as bool? ?? false, $type: json['runtimeType'] as String?, ); -Map _$$DeletingToJson(_$Deleting instance) => +Map _$$DeletingImplToJson(_$DeletingImpl instance) => { 'hard': instance.hard, 'runtimeType': instance.$type, }; -_$Sent _$$SentFromJson(Map json) => _$Sent( +_$SentImpl _$$SentImplFromJson(Map json) => _$SentImpl( $type: json['runtimeType'] as String?, ); -Map _$$SentToJson(_$Sent instance) => { +Map _$$SentImplToJson(_$SentImpl instance) => + { 'runtimeType': instance.$type, }; -_$Updated _$$UpdatedFromJson(Map json) => _$Updated( +_$UpdatedImpl _$$UpdatedImplFromJson(Map json) => + _$UpdatedImpl( $type: json['runtimeType'] as String?, ); -Map _$$UpdatedToJson(_$Updated instance) => { +Map _$$UpdatedImplToJson(_$UpdatedImpl instance) => + { 'runtimeType': instance.$type, }; -_$Deleted _$$DeletedFromJson(Map json) => _$Deleted( +_$DeletedImpl _$$DeletedImplFromJson(Map json) => + _$DeletedImpl( hard: json['hard'] as bool? ?? false, $type: json['runtimeType'] as String?, ); -Map _$$DeletedToJson(_$Deleted instance) => { +Map _$$DeletedImplToJson(_$DeletedImpl instance) => + { 'hard': instance.hard, 'runtimeType': instance.$type, }; -_$SendingFailed _$$SendingFailedFromJson(Map json) => - _$SendingFailed( +_$SendingFailedImpl _$$SendingFailedImplFromJson(Map json) => + _$SendingFailedImpl( $type: json['runtimeType'] as String?, ); -Map _$$SendingFailedToJson(_$SendingFailed instance) => +Map _$$SendingFailedImplToJson(_$SendingFailedImpl instance) => { 'runtimeType': instance.$type, }; -_$UpdatingFailed _$$UpdatingFailedFromJson(Map json) => - _$UpdatingFailed( +_$UpdatingFailedImpl _$$UpdatingFailedImplFromJson(Map json) => + _$UpdatingFailedImpl( $type: json['runtimeType'] as String?, ); -Map _$$UpdatingFailedToJson(_$UpdatingFailed instance) => +Map _$$UpdatingFailedImplToJson( + _$UpdatingFailedImpl instance) => { 'runtimeType': instance.$type, }; -_$DeletingFailed _$$DeletingFailedFromJson(Map json) => - _$DeletingFailed( +_$DeletingFailedImpl _$$DeletingFailedImplFromJson(Map json) => + _$DeletingFailedImpl( hard: json['hard'] as bool? ?? false, $type: json['runtimeType'] as String?, ); -Map _$$DeletingFailedToJson(_$DeletingFailed instance) => +Map _$$DeletingFailedImplToJson( + _$DeletingFailedImpl instance) => { 'hard': instance.hard, 'runtimeType': instance.$type, diff --git a/packages/stream_chat/lib/src/core/models/own_user.g.dart b/packages/stream_chat/lib/src/core/models/own_user.g.dart index 6cae18eec..29aecb8c1 100644 --- a/packages/stream_chat/lib/src/core/models/own_user.g.dart +++ b/packages/stream_chat/lib/src/core/models/own_user.g.dart @@ -15,8 +15,8 @@ OwnUser _$OwnUserFromJson(Map json) => OwnUser( ?.map((e) => Mute.fromJson(e as Map)) .toList() ?? const [], - totalUnreadCount: json['total_unread_count'] as int? ?? 0, - unreadChannels: json['unread_channels'] as int? ?? 0, + totalUnreadCount: (json['total_unread_count'] as num?)?.toInt() ?? 0, + unreadChannels: (json['unread_channels'] as num?)?.toInt() ?? 0, channelMutes: (json['channel_mutes'] as List?) ?.map((e) => ChannelMute.fromJson(e as Map)) .toList() ?? diff --git a/packages/stream_chat/lib/src/core/models/reaction.g.dart b/packages/stream_chat/lib/src/core/models/reaction.g.dart index 6dcac5e19..3be01abc3 100644 --- a/packages/stream_chat/lib/src/core/models/reaction.g.dart +++ b/packages/stream_chat/lib/src/core/models/reaction.g.dart @@ -16,7 +16,7 @@ Reaction _$ReactionFromJson(Map json) => Reaction( ? null : User.fromJson(json['user'] as Map), userId: json['user_id'] as String?, - score: json['score'] as int? ?? 0, + score: (json['score'] as num?)?.toInt() ?? 0, extraData: json['extra_data'] as Map? ?? const {}, ); diff --git a/packages/stream_chat/lib/src/core/models/read.g.dart b/packages/stream_chat/lib/src/core/models/read.g.dart index 231b12e59..113eb4197 100644 --- a/packages/stream_chat/lib/src/core/models/read.g.dart +++ b/packages/stream_chat/lib/src/core/models/read.g.dart @@ -10,7 +10,7 @@ Read _$ReadFromJson(Map json) => Read( lastRead: DateTime.parse(json['last_read'] as String), user: User.fromJson(json['user'] as Map), lastReadMessageId: json['last_read_message_id'] as String?, - unreadMessages: json['unread_messages'] as int? ?? 0, + unreadMessages: (json['unread_messages'] as num?)?.toInt() ?? 0, ); Map _$ReadToJson(Read instance) => { diff --git a/packages/stream_chat/lib/src/core/models/user_block.dart b/packages/stream_chat/lib/src/core/models/user_block.dart new file mode 100644 index 000000000..247de32bb --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/user_block.dart @@ -0,0 +1,65 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:stream_chat/src/core/models/user.dart'; + +part 'user_block.g.dart'; + +/// Contains information about a [User] blocked from a [Channel] or App. +@JsonSerializable() +class UserBlock extends Equatable { + /// Creates a new instance of [UserBlock] + const UserBlock({ + required this.user, + this.blockedUser, + this.userId, + this.blockedUserId, + this.createdAt, + }); + + /// Create a new instance from a json + factory UserBlock.fromJson(Map json) => + _$UserBlockFromJson(json); + + /// User that blocked the [blockedUser]. + final User user; + + /// User that was blocked by the [user]. + final User? blockedUser; + + /// ID of the [user]. + final String? userId; + + /// ID of the [blockedUser]. + final String? blockedUserId; + + /// Timestamp when the [user] was blocked. + final DateTime? createdAt; + + /// Serialize to json + Map toJson() => _$UserBlockToJson(this); + + /// Returns a copy of this object with the given fields updated. + UserBlock copyWith({ + User? user, + User? blockedUser, + String? userId, + String? blockedUserId, + DateTime? createdAt, + }) => + UserBlock( + user: user ?? this.user, + blockedUser: blockedUser ?? this.blockedUser, + userId: userId ?? this.userId, + blockedUserId: blockedUserId ?? this.blockedUserId, + createdAt: createdAt ?? this.createdAt, + ); + + @override + List get props => [ + user, + blockedUser, + userId, + blockedUserId, + createdAt, + ]; +} diff --git a/packages/stream_chat/lib/src/core/models/user_block.g.dart b/packages/stream_chat/lib/src/core/models/user_block.g.dart new file mode 100644 index 000000000..00e138211 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/user_block.g.dart @@ -0,0 +1,27 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'user_block.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UserBlock _$UserBlockFromJson(Map json) => UserBlock( + user: User.fromJson(json['user'] as Map), + blockedUser: json['blocked_user'] == null + ? null + : User.fromJson(json['blocked_user'] as Map), + userId: json['user_id'] as String?, + blockedUserId: json['blocked_user_id'] as String?, + createdAt: json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + ); + +Map _$UserBlockToJson(UserBlock instance) => { + 'user': instance.user.toJson(), + 'blocked_user': instance.blockedUser?.toJson(), + 'user_id': instance.userId, + 'blocked_user_id': instance.blockedUserId, + 'created_at': instance.createdAt?.toIso8601String(), + }; diff --git a/packages/stream_chat/test/fixtures/user_block.json b/packages/stream_chat/test/fixtures/user_block.json new file mode 100644 index 000000000..124781307 --- /dev/null +++ b/packages/stream_chat/test/fixtures/user_block.json @@ -0,0 +1,26 @@ +{ + "user": { + "id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e", + "role": "test-role", + "name": "John", + "image": "https://getstream.io/random_png/?id=cool-shadow-7&name=Cool+shadow", + "banned": true, + "online": true, + "created_at": "2021-08-03 12:39:21.817646", + "updated_at": "2021-08-04 12:39:21.817646", + "last_active": "2021-08-05 12:39:21.817646" + }, + "blocked_user": { + "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", + "role": "user", + "created_at": "2020-01-28T22:17:30.83015Z", + "updated_at": "2020-01-28T22:17:31.19435Z", + "banned": false, + "online": false, + "image": "https://randomuser.me/api/portraits/women/2.jpg", + "name": "Mia Denys" + }, + "user_id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e", + "blocked_user_id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", + "created_at": "2020-01-28T22:17:30.83015Z" +} \ No newline at end of file diff --git a/packages/stream_chat/test/src/client/client_test.dart b/packages/stream_chat/test/src/client/client_test.dart index 19450f664..acbda8da5 100644 --- a/packages/stream_chat/test/src/client/client_test.dart +++ b/packages/stream_chat/test/src/client/client_test.dart @@ -1,6 +1,7 @@ import 'package:mocktail/mocktail.dart'; import 'package:stream_chat/src/core/http/token.dart'; import 'package:stream_chat/src/core/models/banned_user.dart'; +import 'package:stream_chat/src/core/models/user_block.dart'; import 'package:stream_chat/stream_chat.dart'; import 'package:test/test.dart'; @@ -1882,6 +1883,65 @@ void main() { verifyNoMoreInteractions(api.moderation); }); + test('`.blockUser`', () async { + const userId = 'test-user-id'; + + when(() => api.user.blockUser(userId)).thenAnswer( + (_) async => UserBlockResponse.fromJson({ + 'blocked_by_user_id': 'deven', + 'blocked_user_id': 'jaap', + 'created_at': '2024-10-01 12:45:23.456', + }), + ); + + final res = await client.blockUser(userId); + + expect(res, isNotNull); + + verify( + () => api.user.blockUser(userId), + ).called(1); + verifyNoMoreInteractions(api.user); + }); + + test('`.unblockUser`', () async { + const userId = 'test-user-id'; + + when(() => api.user.unblockUser(userId)) + .thenAnswer((_) async => EmptyResponse()); + + final res = await client.unblockUser(userId); + + expect(res, isNotNull); + + verify( + () => api.user.unblockUser(userId), + ).called(1); + verifyNoMoreInteractions(api.user); + }); + + test('`.queryBlockedUsers`', () async { + final users = List.generate( + 3, + (index) => User(id: 'test-user-id-$index'), + ); + + when(() => api.user.queryBlockedUsers()).thenAnswer( + (_) async => BlockedUsersResponse() + ..blocks = [ + UserBlock(user: users[0], blockedUser: users[1]), + UserBlock(user: users[0], blockedUser: users[2]), + ], + ); + + final res = await client.queryBlockedUsers(); + expect(res, isNotNull); + expect(res.blocks.length, 2); + + verify(() => api.user.queryBlockedUsers()).called(1); + verifyNoMoreInteractions(api.user); + }); + test('`.shadowBan`', () async { const userId = 'test-user-id'; diff --git a/packages/stream_chat/test/src/core/api/responses_test.dart b/packages/stream_chat/test/src/core/api/responses_test.dart index b322fbe19..65731d2d7 100644 --- a/packages/stream_chat/test/src/core/api/responses_test.dart +++ b/packages/stream_chat/test/src/core/api/responses_test.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:stream_chat/src/core/models/call_payload.dart'; +import 'package:stream_chat/src/core/models/user_block.dart'; import 'package:stream_chat/stream_chat.dart'; import 'package:test/test.dart'; @@ -4389,5 +4390,56 @@ void main() { final response = CreateCallPayload.fromJson(json.decode(jsonExample)); expect(response.call, isA()); }); + + test('UserBlockResponse', () { + const jsonExample = ''' + { + "blocked_user_id":"c1c9b454-2bcc-402d-8bb0-2f3706ce1680", + "blocked_by_user_id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e", + "created_at": "2020-01-28T22:17:30.83015Z" + } + '''; + final response = UserBlockResponse.fromJson(json.decode(jsonExample)); + expect(response.blockedUserId, isA()); + expect(response.blockedByUserId, isA()); + expect(response.createdAt, isA()); + }); + + test('BlockedUsersResponse', () { + const jsonExample = ''' + { + "blocks": [ + { + "user": { + "id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e", + "role": "test-role", + "name": "John", + "image": "https://getstream.io/random_png/?id=cool-shadow-7&name=Cool+shadow", + "banned": true, + "online": true, + "created_at": "2021-08-03 12:39:21.817646", + "updated_at": "2021-08-04 12:39:21.817646", + "last_active": "2021-08-05 12:39:21.817646" + }, + "blocked_user": { + "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", + "role": "user", + "created_at": "2020-01-28T22:17:30.83015Z", + "updated_at": "2020-01-28T22:17:31.19435Z", + "banned": false, + "online": false, + "image": "https://randomuser.me/api/portraits/women/2.jpg", + "name": "Mia Denys" + }, + "user_id": "bbb19d9a-ee50-45bc-84e5-0584e79d0c9e", + "blocked_user_id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", + "created_at": "2020-01-28T22:17:30.83015Z" + } + ] + } + '''; + final response = BlockedUsersResponse.fromJson(json.decode(jsonExample)); + expect(response.blocks, isA>()); + }); }); } diff --git a/packages/stream_chat/test/src/core/api/user_api_test.dart b/packages/stream_chat/test/src/core/api/user_api_test.dart index 764386f86..9feb68e71 100644 --- a/packages/stream_chat/test/src/core/api/user_api_test.dart +++ b/packages/stream_chat/test/src/core/api/user_api_test.dart @@ -115,4 +115,71 @@ void main() { })).called(1); verifyNoMoreInteractions(client); }); + + test('blockUser', () async { + const targetUserId = 'test-target-user-id'; + + const path = '/users/block'; + + when(() => client.post(path, data: { + 'blocked_user_id': targetUserId, + })).thenAnswer( + (_) async => successResponse( + path, + data: { + 'blocked_by_user_id': 'deven', + 'blocked_user_id': 'jaap', + 'created_at': '2024-10-01 12:45:23.456', + }, + ), + ); + + final res = await userApi.blockUser(targetUserId); + + expect(res, isNotNull); + + verify(() => client.post(path, data: { + 'blocked_user_id': targetUserId, + })).called(1); + verifyNoMoreInteractions(client); + }); + + test('unblockUser', () async { + const targetUserId = 'test-target-user-id'; + + const path = '/users/unblock'; + + when(() => client.post(path, data: { + 'blocked_user_id': targetUserId, + })).thenAnswer( + (_) async => successResponse( + path, + data: {}, + ), + ); + + final res = await userApi.unblockUser(targetUserId); + + expect(res, isNotNull); + + verify(() => client.post(path, data: { + 'blocked_user_id': targetUserId, + })).called(1); + verifyNoMoreInteractions(client); + }); + + test('queryBlockedUsers', () async { + const path = '/users/block'; + + when(() => client.get(path)).thenAnswer( + (_) async => successResponse(path, data: {}), + ); + + final res = await userApi.queryBlockedUsers(); + + expect(res, isNotNull); + + verify(() => client.get(path)).called(1); + verifyNoMoreInteractions(client); + }); } diff --git a/packages/stream_chat/test/src/core/models/attachment_giphy_info_test.dart b/packages/stream_chat/test/src/core/models/attachment_giphy_info_test.dart new file mode 100644 index 000000000..d135c217d --- /dev/null +++ b/packages/stream_chat/test/src/core/models/attachment_giphy_info_test.dart @@ -0,0 +1,63 @@ +import 'package:stream_chat/src/core/models/attachment.dart'; +import 'package:stream_chat/src/core/models/attachment_giphy_info.dart'; +import 'package:test/test.dart'; + +void main() { + group('GiphyInfoType', () { + test('enum values should have correct string representation', () { + expect(GiphyInfoType.original.value, 'original'); + expect(GiphyInfoType.fixedHeight.value, 'fixed_height'); + expect(GiphyInfoType.fixedHeightStill.value, 'fixed_height_still'); + expect( + GiphyInfoType.fixedHeightDownsampled.value, + 'fixed_height_downsampled', + ); + }); + }); + + group('GiphyInfoX', () { + test('giphyInfo returns valid GiphyInfo object when data is valid', () { + final attachment = Attachment(extraData: const { + 'giphy': { + 'original': { + 'url': 'https://example.com/original.gif', + 'width': '200', + 'height': '150', + } + } + }); + + final giphyInfo = attachment.giphyInfo(GiphyInfoType.original); + + expect(giphyInfo, isNotNull); + expect(giphyInfo!.url, 'https://example.com/original.gif'); + expect(giphyInfo.width, 200); + expect(giphyInfo.height, 150); + }); + + test('giphyInfo returns null when giphy data is missing', () { + final attachment = Attachment(); + + final giphyInfo = attachment.giphyInfo(GiphyInfoType.original); + + expect(giphyInfo, isNull); + }); + + test('giphyInfo returns null when the specific GiphyInfoType is missing', + () { + final attachment = Attachment(extraData: const { + 'giphy': { + 'fixed_height': { + 'url': 'https://example.com/fixed_height.gif', + 'width': '100', + 'height': '100', + } + } + }); + + final giphyInfo = attachment.giphyInfo(GiphyInfoType.original); + + expect(giphyInfo, isNull); + }); + }); +} diff --git a/packages/stream_chat/test/src/core/models/user_block_test.dart b/packages/stream_chat/test/src/core/models/user_block_test.dart new file mode 100644 index 000000000..8531d4024 --- /dev/null +++ b/packages/stream_chat/test/src/core/models/user_block_test.dart @@ -0,0 +1,42 @@ +import 'package:stream_chat/src/core/models/user.dart'; +import 'package:stream_chat/src/core/models/user_block.dart'; +import 'package:test/test.dart'; + +import '../../utils.dart'; + +void main() { + group('src/models/user_block', () { + test('should parse json correctly', () { + final userBlock = UserBlock.fromJson(jsonFixture('user_block.json')); + expect(userBlock.userId, 'bbb19d9a-ee50-45bc-84e5-0584e79d0c9e'); + expect(userBlock.blockedUserId, 'c1c9b454-2bcc-402d-8bb0-2f3706ce1680'); + expect( + userBlock.createdAt, + DateTime.parse('2020-01-28T22:17:30.83015Z'), + ); + expect(userBlock.user, isNotNull); + expect(userBlock.blockedUser, isNotNull); + }); + + test('should serialize to json correctly', () { + final userBlock = UserBlock( + user: User(id: 'user-1'), + blockedUser: User(id: 'user-2'), + userId: 'user-1', + blockedUserId: 'user-2', + createdAt: DateTime.parse('2020-01-28T22:17:30.830150Z'), + ); + + expect( + userBlock.toJson(), + { + 'user': {'id': 'user-1'}, + 'blocked_user': {'id': 'user-2'}, + 'user_id': 'user-1', + 'blocked_user_id': 'user-2', + 'created_at': '2020-01-28T22:17:30.830150Z' + }, + ); + }); + }); +}