diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index 3b133e9687..ea5c0d8929 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -1,3 +1,16 @@ +## Upcoming + +✅ Added + +- Added `reactionGroups` to the `Message` model. This field is a map of reaction types to their + respective counts and scores and additional metadata such as the first and last reaction + timestamps. + +🔄 Changed + +- Deprecated `message.reactionCounts`, `message.reactionScores` in favor of + `message.reactionGroups`. + ## 9.10.0 🐞 Fixed diff --git a/packages/stream_chat/lib/src/client/channel.dart b/packages/stream_chat/lib/src/client/channel.dart index 8eb81b5ffe..e42cc5c777 100644 --- a/packages/stream_chat/lib/src/client/channel.dart +++ b/packages/stream_chat/lib/src/client/channel.dart @@ -1,7 +1,7 @@ // ignore_for_file: avoid_redundant_argument_values import 'dart:async'; -import 'dart:math'; +import 'dart:math' as math; import 'package:collection/collection.dart'; import 'package:rxdart/rxdart.dart'; @@ -303,7 +303,7 @@ class Channel { final currentTime = DateTime.timestamp(); final elapsedTime = currentTime.difference(userLastMessageAt).inSeconds; - return max(0, cooldownDuration - elapsedTime); + return math.max(0, cooldownDuration - elapsedTime); } /// Stores time at which cooldown was started @@ -1303,59 +1303,37 @@ class Channel { bool enforceUnique = false, }) async { _checkInitialized(); - final messageId = message.id; - final now = DateTime.now(); - final user = _client.state.currentUser; - - var latestReactions = [...message.latestReactions ?? []]; - if (enforceUnique) { - latestReactions.removeWhere((it) => it.userId == user!.id); + final currentUser = _client.state.currentUser; + if (currentUser == null) { + throw StateError( + 'Cannot send reaction: current user is not available. ' + 'Ensure the client is connected and a user is set.', + ); } - final newReaction = Reaction( - messageId: messageId, - createdAt: now, + final messageId = message.id; + final reaction = Reaction( type: type, - user: user, + messageId: messageId, + user: currentUser, score: score, + createdAt: DateTime.timestamp(), extraData: extraData, ); - latestReactions = (latestReactions - // Inserting at the 0th index as it's the latest reaction - ..insert(0, newReaction)) - .take(10) - .toList(); - final ownReactions = enforceUnique - ? [newReaction] - : [ - ...message.ownReactions ?? [], - newReaction, - ]; - - final newMessage = message.copyWith( - reactionCounts: {...message.reactionCounts ?? {}} - ..update(type, (value) { - if (enforceUnique) return value; - return value + 1; - }, ifAbsent: () => 1), // ignore: prefer-trailing-comma - reactionScores: {...message.reactionScores ?? {}} - ..update(type, (value) { - if (enforceUnique) return value; - return value + 1; - }, ifAbsent: () => 1), // ignore: prefer-trailing-comma - latestReactions: latestReactions, - ownReactions: ownReactions, + final updatedMessage = message.addMyReaction( + reaction, + enforceUnique: enforceUnique, ); - state?.updateMessage(newMessage); + state?.updateMessage(updatedMessage); try { final reactionResp = await _client.sendReaction( messageId, - type, - score: score, - extraData: extraData, + reaction.type, + score: reaction.score, + extraData: reaction.extraData, enforceUnique: enforceUnique, ); return reactionResp; @@ -1371,35 +1349,11 @@ class Channel { Message message, Reaction reaction, ) async { - final type = reaction.type; - - final reactionCounts = {...?message.reactionCounts}; - if (reactionCounts.containsKey(type)) { - reactionCounts.update(type, (value) => value - 1); - } - final reactionScores = {...?message.reactionScores}; - if (reactionScores.containsKey(type)) { - reactionScores.update(type, (value) => value - 1); - } - - final latestReactions = [...?message.latestReactions]..removeWhere((r) => - r.userId == reaction.userId && - r.type == reaction.type && - r.messageId == reaction.messageId); - - final ownReactions = [...?message.ownReactions]..removeWhere((r) => - r.userId == reaction.userId && - r.type == reaction.type && - r.messageId == reaction.messageId); - - final newMessage = message.copyWith( - reactionCounts: reactionCounts..removeWhere((_, value) => value == 0), - reactionScores: reactionScores..removeWhere((_, value) => value == 0), - latestReactions: latestReactions, - ownReactions: ownReactions, + final updatedMessage = message.deleteMyReaction( + reactionType: reaction.type, ); - state?.updateMessage(newMessage); + state?.updateMessage(updatedMessage); try { final deleteResponse = await _client.deleteReaction( 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 20401e945d..54f7976091 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 @@ -1,4 +1,3 @@ -// dart format width=80 // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint @@ -10,8 +9,11 @@ part of 'attachment_file.dart'; // FreezedGenerator // ************************************************************************** -// dart format off 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#adding-getters-and-methods-to-our-models'); + UploadState _$UploadStateFromJson(Map json) { switch (json['runtimeType']) { case 'preparing': @@ -31,53 +33,123 @@ UploadState _$UploadStateFromJson(Map json) { /// @nodoc mixin _$UploadState { + @optionalTypeArgs + TResult when({ + required TResult Function() preparing, + required TResult Function(int uploaded, int total) inProgress, + required TResult Function() success, + required TResult Function(String error) failed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? preparing, + TResult? Function(int uploaded, int total)? inProgress, + TResult? Function()? success, + TResult? Function(String error)? failed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? preparing, + TResult Function(int uploaded, int total)? inProgress, + TResult Function()? success, + TResult Function(String error)? failed, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Preparing value) preparing, + required TResult Function(InProgress value) inProgress, + required TResult Function(Success value) success, + required TResult Function(Failed value) failed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Preparing value)? preparing, + TResult? Function(InProgress value)? inProgress, + TResult? Function(Success value)? success, + TResult? Function(Failed value)? failed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Preparing value)? preparing, + TResult Function(InProgress value)? inProgress, + TResult Function(Success value)? success, + TResult Function(Failed value)? failed, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + /// Serializes this UploadState to a JSON map. - Map toJson(); + Map toJson() => throw _privateConstructorUsedError; +} - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is UploadState); - } +/// @nodoc +abstract class $UploadStateCopyWith<$Res> { + factory $UploadStateCopyWith( + UploadState value, $Res Function(UploadState) then) = + _$UploadStateCopyWithImpl<$Res, UploadState>; +} - @JsonKey(includeFromJson: false, includeToJson: false) - @override - int get hashCode => runtimeType.hashCode; +/// @nodoc +class _$UploadStateCopyWithImpl<$Res, $Val extends UploadState> + implements $UploadStateCopyWith<$Res> { + _$UploadStateCopyWithImpl(this._value, this._then); - @override - String toString() { - return 'UploadState()'; - } + // ignore: unused_field + 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 -class $UploadStateCopyWith<$Res> { - $UploadStateCopyWith(UploadState _, $Res Function(UploadState) __); +abstract class _$$PreparingImplCopyWith<$Res> { + factory _$$PreparingImplCopyWith( + _$PreparingImpl value, $Res Function(_$PreparingImpl) then) = + __$$PreparingImplCopyWithImpl<$Res>; +} + +/// @nodoc +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 UploadState { - 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; @override - Map toJson() { - return _$PreparingToJson( - this, - ); + String toString() { + return 'UploadState.preparing()'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is Preparing); + (other.runtimeType == runtimeType && other is _$PreparingImpl); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -85,92 +157,127 @@ class Preparing extends UploadState { int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'UploadState.preparing()'; + @optionalTypeArgs + TResult when({ + required TResult Function() preparing, + required TResult Function(int uploaded, int total) inProgress, + required TResult Function() success, + required TResult Function(String error) failed, + }) { + return preparing(); } -} - -/// @nodoc -@JsonSerializable() -class InProgress extends UploadState { - const InProgress( - {required this.uploaded, required this.total, final String? $type}) - : $type = $type ?? 'inProgress', - super._(); - factory InProgress.fromJson(Map json) => - _$InProgressFromJson(json); - - final int uploaded; - final int total; - @JsonKey(name: 'runtimeType') - final String $type; + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? preparing, + TResult? Function(int uploaded, int total)? inProgress, + TResult? Function()? success, + TResult? Function(String error)? failed, + }) { + return preparing?.call(); + } - /// Create a copy of UploadState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $InProgressCopyWith get copyWith => - _$InProgressCopyWithImpl(this, _$identity); + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? preparing, + TResult Function(int uploaded, int total)? inProgress, + TResult Function()? success, + TResult Function(String error)? failed, + required TResult orElse(), + }) { + if (preparing != null) { + return preparing(); + } + return orElse(); + } @override - Map toJson() { - return _$InProgressToJson( - this, - ); + @optionalTypeArgs + TResult map({ + required TResult Function(Preparing value) preparing, + required TResult Function(InProgress value) inProgress, + required TResult Function(Success value) success, + required TResult Function(Failed value) failed, + }) { + return preparing(this); } @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is InProgress && - (identical(other.uploaded, uploaded) || - other.uploaded == uploaded) && - (identical(other.total, total) || other.total == total)); + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Preparing value)? preparing, + TResult? Function(InProgress value)? inProgress, + TResult? Function(Success value)? success, + TResult? Function(Failed value)? failed, + }) { + return preparing?.call(this); } - @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, uploaded, total); + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Preparing value)? preparing, + TResult Function(InProgress value)? inProgress, + TResult Function(Success value)? success, + TResult Function(Failed value)? failed, + required TResult orElse(), + }) { + if (preparing != null) { + return preparing(this); + } + return orElse(); + } @override - String toString() { - return 'UploadState.inProgress(uploaded: $uploaded, total: $total)'; + Map toJson() { + return _$$PreparingImplToJson( + this, + ); } } +abstract class Preparing extends UploadState { + const factory Preparing() = _$PreparingImpl; + const Preparing._() : super._(); + + factory Preparing.fromJson(Map json) = + _$PreparingImpl.fromJson; +} + /// @nodoc -abstract mixin class $InProgressCopyWith<$Res> - implements $UploadStateCopyWith<$Res> { - factory $InProgressCopyWith( - InProgress value, $Res Function(InProgress) _then) = - _$InProgressCopyWithImpl; +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> implements $InProgressCopyWith<$Res> { - _$InProgressCopyWithImpl(this._self, this._then); - - final InProgress _self; - final $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 - ? _self.uploaded + ? _value.uploaded : uploaded // ignore: cast_nullable_to_non_nullable as int, total: null == total - ? _self.total + ? _value.total : total // ignore: cast_nullable_to_non_nullable as int, )); @@ -179,113 +286,454 @@ class _$InProgressCopyWithImpl<$Res> implements $InProgressCopyWith<$Res> { /// @nodoc @JsonSerializable() -class Success extends UploadState { - const Success({final String? $type}) - : $type = $type ?? 'success', +class _$InProgressImpl extends InProgress { + const _$InProgressImpl( + {required this.uploaded, required this.total, final String? $type}) + : $type = $type ?? 'inProgress', super._(); - factory Success.fromJson(Map json) => - _$SuccessFromJson(json); + + factory _$InProgressImpl.fromJson(Map json) => + _$$InProgressImplFromJson(json); + + @override + final int uploaded; + @override + final int total; @JsonKey(name: 'runtimeType') final String $type; @override - Map toJson() { - return _$SuccessToJson( - this, - ); + String toString() { + return 'UploadState.inProgress(uploaded: $uploaded, total: $total)'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is Success); + (other.runtimeType == runtimeType && + other is _$InProgressImpl && + (identical(other.uploaded, uploaded) || + other.uploaded == uploaded) && + (identical(other.total, total) || other.total == total)); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => runtimeType.hashCode; + int get hashCode => Object.hash(runtimeType, uploaded, total); + + /// 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') + _$$InProgressImplCopyWith<_$InProgressImpl> get copyWith => + __$$InProgressImplCopyWithImpl<_$InProgressImpl>(this, _$identity); @override - String toString() { - return 'UploadState.success()'; + @optionalTypeArgs + TResult when({ + required TResult Function() preparing, + required TResult Function(int uploaded, int total) inProgress, + required TResult Function() success, + required TResult Function(String error) failed, + }) { + return inProgress(uploaded, total); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? preparing, + TResult? Function(int uploaded, int total)? inProgress, + TResult? Function()? success, + TResult? Function(String error)? failed, + }) { + return inProgress?.call(uploaded, total); } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? preparing, + TResult Function(int uploaded, int total)? inProgress, + TResult Function()? success, + TResult Function(String error)? failed, + required TResult orElse(), + }) { + if (inProgress != null) { + return inProgress(uploaded, total); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Preparing value) preparing, + required TResult Function(InProgress value) inProgress, + required TResult Function(Success value) success, + required TResult Function(Failed value) failed, + }) { + return inProgress(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Preparing value)? preparing, + TResult? Function(InProgress value)? inProgress, + TResult? Function(Success value)? success, + TResult? Function(Failed value)? failed, + }) { + return inProgress?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Preparing value)? preparing, + TResult Function(InProgress value)? inProgress, + TResult Function(Success value)? success, + TResult Function(Failed value)? failed, + required TResult orElse(), + }) { + if (inProgress != null) { + return inProgress(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$InProgressImplToJson( + this, + ); + } +} + +abstract class InProgress extends UploadState { + const factory InProgress( + {required final int uploaded, + required final int total}) = _$InProgressImpl; + const InProgress._() : super._(); + + factory InProgress.fromJson(Map json) = + _$InProgressImpl.fromJson; + + int get uploaded; + int get total; + + /// 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 _$$SuccessImplCopyWith<$Res> { + factory _$$SuccessImplCopyWith( + _$SuccessImpl value, $Res Function(_$SuccessImpl) then) = + __$$SuccessImplCopyWithImpl<$Res>; +} + +/// @nodoc +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 Failed extends UploadState { - const Failed({required this.error, final String? $type}) - : $type = $type ?? 'failed', +class _$SuccessImpl extends Success { + const _$SuccessImpl({final String? $type}) + : $type = $type ?? 'success', super._(); - factory Failed.fromJson(Map json) => _$FailedFromJson(json); - final String error; + factory _$SuccessImpl.fromJson(Map json) => + _$$SuccessImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; - /// Create a copy of UploadState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $FailedCopyWith get copyWith => - _$FailedCopyWithImpl(this, _$identity); - @override - Map toJson() { - return _$FailedToJson( - this, - ); + String toString() { + return 'UploadState.success()'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && - other is Failed && - (identical(other.error, error) || other.error == error)); + (other.runtimeType == runtimeType && other is _$SuccessImpl); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, error); + int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'UploadState.failed(error: $error)'; + @optionalTypeArgs + TResult when({ + required TResult Function() preparing, + required TResult Function(int uploaded, int total) inProgress, + required TResult Function() success, + required TResult Function(String error) failed, + }) { + return success(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? preparing, + TResult? Function(int uploaded, int total)? inProgress, + TResult? Function()? success, + TResult? Function(String error)? failed, + }) { + return success?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? preparing, + TResult Function(int uploaded, int total)? inProgress, + TResult Function()? success, + TResult Function(String error)? failed, + required TResult orElse(), + }) { + if (success != null) { + return success(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Preparing value) preparing, + required TResult Function(InProgress value) inProgress, + required TResult Function(Success value) success, + required TResult Function(Failed value) failed, + }) { + return success(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Preparing value)? preparing, + TResult? Function(InProgress value)? inProgress, + TResult? Function(Success value)? success, + TResult? Function(Failed value)? failed, + }) { + return success?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Preparing value)? preparing, + TResult Function(InProgress value)? inProgress, + TResult Function(Success value)? success, + TResult Function(Failed value)? failed, + required TResult orElse(), + }) { + if (success != null) { + return success(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$SuccessImplToJson( + this, + ); } } +abstract class Success extends UploadState { + const factory Success() = _$SuccessImpl; + const Success._() : super._(); + + factory Success.fromJson(Map json) = _$SuccessImpl.fromJson; +} + /// @nodoc -abstract mixin class $FailedCopyWith<$Res> - implements $UploadStateCopyWith<$Res> { - factory $FailedCopyWith(Failed value, $Res Function(Failed) _then) = - _$FailedCopyWithImpl; +abstract class _$$FailedImplCopyWith<$Res> { + factory _$$FailedImplCopyWith( + _$FailedImpl value, $Res Function(_$FailedImpl) then) = + __$$FailedImplCopyWithImpl<$Res>; @useResult $Res call({String error}); } /// @nodoc -class _$FailedCopyWithImpl<$Res> implements $FailedCopyWith<$Res> { - _$FailedCopyWithImpl(this._self, this._then); - - final Failed _self; - final $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 - ? _self.error + ? _value.error : error // ignore: cast_nullable_to_non_nullable as String, )); } } -// dart format on +/// @nodoc +@JsonSerializable() +class _$FailedImpl extends Failed { + const _$FailedImpl({required this.error, final String? $type}) + : $type = $type ?? 'failed', + super._(); + + factory _$FailedImpl.fromJson(Map json) => + _$$FailedImplFromJson(json); + + @override + final String error; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'UploadState.failed(error: $error)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$FailedImpl && + (identical(other.error, error) || other.error == error)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, error); + + /// 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') + _$$FailedImplCopyWith<_$FailedImpl> get copyWith => + __$$FailedImplCopyWithImpl<_$FailedImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() preparing, + required TResult Function(int uploaded, int total) inProgress, + required TResult Function() success, + required TResult Function(String error) failed, + }) { + return failed(error); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? preparing, + TResult? Function(int uploaded, int total)? inProgress, + TResult? Function()? success, + TResult? Function(String error)? failed, + }) { + return failed?.call(error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? preparing, + TResult Function(int uploaded, int total)? inProgress, + TResult Function()? success, + TResult Function(String error)? failed, + required TResult orElse(), + }) { + if (failed != null) { + return failed(error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Preparing value) preparing, + required TResult Function(InProgress value) inProgress, + required TResult Function(Success value) success, + required TResult Function(Failed value) failed, + }) { + return failed(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Preparing value)? preparing, + TResult? Function(InProgress value)? inProgress, + TResult? Function(Success value)? success, + TResult? Function(Failed value)? failed, + }) { + return failed?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Preparing value)? preparing, + TResult Function(InProgress value)? inProgress, + TResult Function(Success value)? success, + TResult Function(Failed value)? failed, + required TResult orElse(), + }) { + if (failed != null) { + return failed(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$FailedImplToJson( + this, + ); + } +} + +abstract class Failed extends UploadState { + const factory Failed({required final String error}) = _$FailedImpl; + const Failed._() : super._(); + + factory Failed.fromJson(Map json) = _$FailedImpl.fromJson; + + String get error; + + /// 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 256713cae0..6b385f2bbb 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 @@ -20,41 +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( +_$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/message.dart b/packages/stream_chat/lib/src/core/models/message.dart index 81389e4bd3..ce89e4edfb 100644 --- a/packages/stream_chat/lib/src/core/models/message.dart +++ b/packages/stream_chat/lib/src/core/models/message.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:stream_chat/src/core/models/attachment.dart'; @@ -7,6 +8,7 @@ import 'package:stream_chat/src/core/models/message_state.dart'; import 'package:stream_chat/src/core/models/moderation.dart'; import 'package:stream_chat/src/core/models/poll.dart'; import 'package:stream_chat/src/core/models/reaction.dart'; +import 'package:stream_chat/src/core/models/reaction_group.dart'; import 'package:stream_chat/src/core/models/user.dart'; import 'package:stream_chat/src/core/util/serializer.dart'; import 'package:uuid/uuid.dart'; @@ -31,8 +33,11 @@ class Message extends Equatable implements ComparableFieldProvider { this.mentionedUsers = const [], this.silent = false, this.shadowed = false, - this.reactionCounts, - this.reactionScores, + @Deprecated("Use 'reactionGroups' instead") + Map? reactionCounts, + @Deprecated("Use 'reactionGroups' instead") + Map? reactionScores, + Map? reactionGroups, this.latestReactions, this.ownReactions, this.parentId, @@ -68,6 +73,11 @@ class Message extends Equatable implements ComparableFieldProvider { remoteCreatedAt = createdAt, remoteUpdatedAt = updatedAt, remoteDeletedAt = deletedAt, + reactionGroups = _maybeGetReactionGroups( + reactionGroups: reactionGroups, + reactionCounts: reactionCounts, + reactionScores: reactionScores, + ), _quotedMessageId = quotedMessageId, _pollId = pollId; @@ -117,11 +127,44 @@ class Message extends Equatable implements ComparableFieldProvider { /// A map describing the count of number of every reaction. @JsonKey(includeToJson: false) - final Map? reactionCounts; + @Deprecated("Use 'reactionGroups' instead") + Map? get reactionCounts { + return reactionGroups?.map((type, it) => MapEntry(type, it.count)); + } /// A map describing the count of score of every reaction. @JsonKey(includeToJson: false) - final Map? reactionScores; + @Deprecated("Use 'reactionGroups' instead") + Map? get reactionScores { + return reactionGroups?.map((type, it) => MapEntry(type, it.sumScores)); + } + + static Map? _maybeGetReactionGroups({ + Map? reactionGroups, + Map? reactionCounts, + Map? reactionScores, + }) { + if (reactionGroups != null) return reactionGroups; + if (reactionCounts == null && reactionScores == null) return null; + + final reactionTypes = {...?reactionCounts?.keys, ...?reactionScores?.keys}; + if (reactionTypes.isEmpty) return null; + + final groups = {}; + for (final type in reactionTypes) { + final count = reactionCounts?[type] ?? 0; + final sumScores = reactionScores?[type] ?? 0; + + if (count == 0 || sumScores == 0) continue; + groups[type] = ReactionGroup(count: count, sumScores: sumScores); + } + + return groups; + } + + /// A map of reaction types and their corresponding reaction groups. + @JsonKey(includeToJson: false) + final Map? reactionGroups; /// The latest reactions to the message created by any user. @JsonKey(includeToJson: false) @@ -286,6 +329,7 @@ class Message extends Equatable implements ComparableFieldProvider { 'mentioned_users', 'reaction_counts', 'reaction_scores', + 'reaction_groups', 'silent', 'parent_id', 'quoted_message', @@ -337,8 +381,11 @@ class Message extends Equatable implements ComparableFieldProvider { List? mentionedUsers, bool? silent, bool? shadowed, + @Deprecated("Use 'reactionGroups' instead") Map? reactionCounts, + @Deprecated("Use 'reactionGroups' instead") Map? reactionScores, + Map? reactionGroups, List? latestReactions, List? ownReactions, String? parentId, @@ -408,8 +455,12 @@ class Message extends Equatable implements ComparableFieldProvider { mentionedUsers: mentionedUsers ?? this.mentionedUsers, silent: silent ?? this.silent, shadowed: shadowed ?? this.shadowed, - reactionCounts: reactionCounts ?? this.reactionCounts, - reactionScores: reactionScores ?? this.reactionScores, + reactionGroups: _maybeGetReactionGroups( + reactionGroups: reactionGroups, + reactionCounts: reactionCounts, + reactionScores: reactionScores, + ) ?? + this.reactionGroups, latestReactions: latestReactions ?? this.latestReactions, ownReactions: ownReactions ?? this.ownReactions, parentId: parentId ?? this.parentId, @@ -458,8 +509,7 @@ class Message extends Equatable implements ComparableFieldProvider { mentionedUsers: other.mentionedUsers, silent: other.silent, shadowed: other.shadowed, - reactionCounts: other.reactionCounts, - reactionScores: other.reactionScores, + reactionGroups: other.reactionGroups, latestReactions: other.latestReactions, ownReactions: other.ownReactions, parentId: other.parentId, @@ -521,8 +571,7 @@ class Message extends Equatable implements ComparableFieldProvider { type, attachments, mentionedUsers, - reactionCounts, - reactionScores, + reactionGroups, latestReactions, ownReactions, parentId, @@ -747,3 +796,107 @@ extension on Message { return copyWith(mentionedUsers: updatedMentionedUsers); } } + +/// Extension that adds reaction manipulation functionality to Message objects. +/// +/// This extension provides methods to add and delete reactions to/from messages, +/// with proper handling of reaction counts, scores, and timestamps. +extension MessageReactionHelper on Message { + /// Adds a new reaction to the message. + /// + /// If [enforceUnique] is set to true, it will remove the existing current + /// user's reaction before adding the new one. + Message addMyReaction( + Reaction reaction, { + bool enforceUnique = false, + }) { + var updatedMessage = this; + + // If we are enforcing unique reactions, we need to delete the existing + // reaction before adding the new one. + if (enforceUnique) updatedMessage = updatedMessage.deleteMyReaction(); + + final ownReactions = [...?updatedMessage.ownReactions]; + final latestReactions = [...?updatedMessage.latestReactions]; + final reactionGroups = { + ...?updatedMessage.reactionGroups, + }; + + // Add the new reaction to the own reactions and latest reactions. + ownReactions.insert(0, reaction); + latestReactions.insert(0, reaction); + + // Update the reaction groups. + reactionGroups.update( + reaction.type, + (it) => it.copyWith( + count: it.count + 1, + sumScores: it.sumScores + reaction.score, + firstReactionAt: [it.firstReactionAt, reaction.createdAt].minOrNull, + lastReactionAt: [it.lastReactionAt, reaction.createdAt].maxOrNull, + ), + ifAbsent: () => ReactionGroup( + count: 1, + sumScores: reaction.score, + firstReactionAt: reaction.createdAt, + lastReactionAt: reaction.createdAt, + ), + ); + + return updatedMessage.copyWith( + ownReactions: ownReactions, + latestReactions: latestReactions, + reactionGroups: reactionGroups, + ); + } + + /// Deletes all the current user's reactions from the message. + /// + /// Optionally, you can specify a [reactionType] to delete only that specific + /// current user's reaction. + Message deleteMyReaction({ + String? reactionType, + }) { + final reactionsToDelete = this.ownReactions?.where((it) { + if (reactionType != null) return it.type == reactionType; + return true; + }); + + // If there are no reactions to delete, we can return the message as is. + if (reactionsToDelete == null || reactionsToDelete.isEmpty) return this; + + final ownReactions = [...?this.ownReactions]; + final latestReactions = [...?this.latestReactions]; + final reactionGroups = {...?this.reactionGroups}; + + for (final reaction in reactionsToDelete) { + final type = reaction.type; + + bool match(Reaction r) => r.type == type && r.userId == reaction.userId; + + // Remove from own reactions and latest reactions. + ownReactions.removeWhere(match); + latestReactions.removeWhere(match); + + final group = reactionGroups.remove(type); + if (group == null) continue; + + // Update the reaction group. + final updatedCount = group.count - 1; + final updatedSumScores = group.sumScores - reaction.score; + + if (updatedCount > 0 && updatedSumScores > 0) { + reactionGroups[type] = group.copyWith( + count: updatedCount, + sumScores: updatedSumScores, + ); + } + } + + return copyWith( + ownReactions: ownReactions, + latestReactions: latestReactions, + reactionGroups: reactionGroups, + ); + } +} 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 0b4da5a648..84340182b0 100644 --- a/packages/stream_chat/lib/src/core/models/message.g.dart +++ b/packages/stream_chat/lib/src/core/models/message.g.dart @@ -28,6 +28,10 @@ Message _$MessageFromJson(Map json) => Message( reactionScores: (json['reaction_scores'] as Map?)?.map( (k, e) => MapEntry(k, (e as num).toInt()), ), + reactionGroups: (json['reaction_groups'] as Map?)?.map( + (k, e) => + MapEntry(k, ReactionGroup.fromJson(e as Map)), + ), latestReactions: (json['latest_reactions'] as List?) ?.map((e) => Reaction.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 079d8b3696..584bc54b4c 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 @@ -1,4 +1,3 @@ -// dart format width=80 // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint @@ -10,8 +9,11 @@ part of 'message_state.dart'; // FreezedGenerator // ************************************************************************** -// dart format off 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#adding-getters-and-methods-to-our-models'); + MessageState _$MessageStateFromJson(Map json) { switch (json['runtimeType']) { case 'initial': @@ -31,51 +33,122 @@ MessageState _$MessageStateFromJson(Map json) { /// @nodoc mixin _$MessageState { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(OutgoingState state) outgoing, + required TResult Function(CompletedState state) completed, + required TResult Function(FailedState state, Object? reason) failed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function(OutgoingState state)? outgoing, + TResult? Function(CompletedState state)? completed, + TResult? Function(FailedState state, Object? reason)? failed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(OutgoingState state)? outgoing, + TResult Function(CompletedState state)? completed, + TResult Function(FailedState state, Object? reason)? failed, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(MessageInitial value) initial, + required TResult Function(MessageOutgoing value) outgoing, + required TResult Function(MessageCompleted value) completed, + required TResult Function(MessageFailed value) failed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(MessageInitial value)? initial, + TResult? Function(MessageOutgoing value)? outgoing, + TResult? Function(MessageCompleted value)? completed, + TResult? Function(MessageFailed value)? failed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(MessageInitial value)? initial, + TResult Function(MessageOutgoing value)? outgoing, + TResult Function(MessageCompleted value)? completed, + TResult Function(MessageFailed value)? failed, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + /// Serializes this MessageState to a JSON map. - Map toJson(); + Map toJson() => throw _privateConstructorUsedError; +} - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is MessageState); - } +/// @nodoc +abstract class $MessageStateCopyWith<$Res> { + factory $MessageStateCopyWith( + MessageState value, $Res Function(MessageState) then) = + _$MessageStateCopyWithImpl<$Res, MessageState>; +} - @JsonKey(includeFromJson: false, includeToJson: false) - @override - int get hashCode => runtimeType.hashCode; +/// @nodoc +class _$MessageStateCopyWithImpl<$Res, $Val extends MessageState> + implements $MessageStateCopyWith<$Res> { + _$MessageStateCopyWithImpl(this._value, this._then); - @override - String toString() { - return 'MessageState()'; - } + // ignore: unused_field + 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 _$$MessageInitialImplCopyWith<$Res> { + factory _$$MessageInitialImplCopyWith(_$MessageInitialImpl value, + $Res Function(_$MessageInitialImpl) then) = + __$$MessageInitialImplCopyWithImpl<$Res>; } /// @nodoc -class $MessageStateCopyWith<$Res> { - $MessageStateCopyWith(MessageState _, $Res Function(MessageState) __); +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 MessageState { - const MessageInitial({final String? $type}) : $type = $type ?? 'initial'; - factory MessageInitial.fromJson(Map json) => - _$MessageInitialFromJson(json); +class _$MessageInitialImpl implements MessageInitial { + const _$MessageInitialImpl({final String? $type}) + : $type = $type ?? 'initial'; + + factory _$MessageInitialImpl.fromJson(Map json) => + _$$MessageInitialImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @override - Map toJson() { - return _$MessageInitialToJson( - this, - ); + String toString() { + return 'MessageState.initial()'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is MessageInitial); + (other.runtimeType == runtimeType && other is _$MessageInitialImpl); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -83,62 +156,99 @@ class MessageInitial implements MessageState { int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'MessageState.initial()'; + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(OutgoingState state) outgoing, + required TResult Function(CompletedState state) completed, + required TResult Function(FailedState state, Object? reason) failed, + }) { + return initial(); } -} - -/// @nodoc -@JsonSerializable() -class MessageOutgoing implements MessageState { - const MessageOutgoing({required this.state, final String? $type}) - : $type = $type ?? 'outgoing'; - factory MessageOutgoing.fromJson(Map json) => - _$MessageOutgoingFromJson(json); - - final OutgoingState state; - @JsonKey(name: 'runtimeType') - final String $type; + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function(OutgoingState state)? outgoing, + TResult? Function(CompletedState state)? completed, + TResult? Function(FailedState state, Object? reason)? failed, + }) { + return initial?.call(); + } - /// Create a copy of MessageState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $MessageOutgoingCopyWith get copyWith => - _$MessageOutgoingCopyWithImpl(this, _$identity); + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(OutgoingState state)? outgoing, + TResult Function(CompletedState state)? completed, + TResult Function(FailedState state, Object? reason)? failed, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } @override - Map toJson() { - return _$MessageOutgoingToJson( - this, - ); + @optionalTypeArgs + TResult map({ + required TResult Function(MessageInitial value) initial, + required TResult Function(MessageOutgoing value) outgoing, + required TResult Function(MessageCompleted value) completed, + required TResult Function(MessageFailed value) failed, + }) { + return initial(this); } @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is MessageOutgoing && - (identical(other.state, state) || other.state == state)); + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(MessageInitial value)? initial, + TResult? Function(MessageOutgoing value)? outgoing, + TResult? Function(MessageCompleted value)? completed, + TResult? Function(MessageFailed value)? failed, + }) { + return initial?.call(this); } - @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, state); + @optionalTypeArgs + TResult maybeMap({ + TResult Function(MessageInitial value)? initial, + TResult Function(MessageOutgoing value)? outgoing, + TResult Function(MessageCompleted value)? completed, + TResult Function(MessageFailed value)? failed, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } @override - String toString() { - return 'MessageState.outgoing(state: $state)'; + Map toJson() { + return _$$MessageInitialImplToJson( + this, + ); } } +abstract class MessageInitial implements MessageState { + const factory MessageInitial() = _$MessageInitialImpl; + + factory MessageInitial.fromJson(Map json) = + _$MessageInitialImpl.fromJson; +} + /// @nodoc -abstract mixin class $MessageOutgoingCopyWith<$Res> - implements $MessageStateCopyWith<$Res> { - factory $MessageOutgoingCopyWith( - MessageOutgoing value, $Res Function(MessageOutgoing) _then) = - _$MessageOutgoingCopyWithImpl; +abstract class _$$MessageOutgoingImplCopyWith<$Res> { + factory _$$MessageOutgoingImplCopyWith(_$MessageOutgoingImpl value, + $Res Function(_$MessageOutgoingImpl) then) = + __$$MessageOutgoingImplCopyWithImpl<$Res>; @useResult $Res call({OutgoingState state}); @@ -146,22 +256,23 @@ abstract mixin class $MessageOutgoingCopyWith<$Res> } /// @nodoc -class _$MessageOutgoingCopyWithImpl<$Res> - implements $MessageOutgoingCopyWith<$Res> { - _$MessageOutgoingCopyWithImpl(this._self, this._then); - - final MessageOutgoing _self; - final $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 - ? _self.state + ? _value.state : state // ignore: cast_nullable_to_non_nullable as OutgoingState, )); @@ -172,44 +283,37 @@ class _$MessageOutgoingCopyWithImpl<$Res> @override @pragma('vm:prefer-inline') $OutgoingStateCopyWith<$Res> get state { - return $OutgoingStateCopyWith<$Res>(_self.state, (value) { - return _then(_self.copyWith(state: value)); + return $OutgoingStateCopyWith<$Res>(_value.state, (value) { + return _then(_value.copyWith(state: value)); }); } } /// @nodoc @JsonSerializable() -class MessageCompleted implements MessageState { - const MessageCompleted({required this.state, final String? $type}) - : $type = $type ?? 'completed'; - factory MessageCompleted.fromJson(Map json) => - _$MessageCompletedFromJson(json); +class _$MessageOutgoingImpl implements MessageOutgoing { + const _$MessageOutgoingImpl({required this.state, final String? $type}) + : $type = $type ?? 'outgoing'; - final CompletedState state; + factory _$MessageOutgoingImpl.fromJson(Map json) => + _$$MessageOutgoingImplFromJson(json); + + @override + final OutgoingState state; @JsonKey(name: 'runtimeType') final String $type; - /// Create a copy of MessageState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $MessageCompletedCopyWith get copyWith => - _$MessageCompletedCopyWithImpl(this, _$identity); - @override - Map toJson() { - return _$MessageCompletedToJson( - this, - ); + String toString() { + return 'MessageState.outgoing(state: $state)'; } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is MessageCompleted && + other is _$MessageOutgoingImpl && (identical(other.state, state) || other.state == state)); } @@ -217,18 +321,118 @@ class MessageCompleted implements MessageState { @override int get hashCode => Object.hash(runtimeType, state); + /// 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') + _$$MessageOutgoingImplCopyWith<_$MessageOutgoingImpl> get copyWith => + __$$MessageOutgoingImplCopyWithImpl<_$MessageOutgoingImpl>( + this, _$identity); + @override - String toString() { - return 'MessageState.completed(state: $state)'; + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(OutgoingState state) outgoing, + required TResult Function(CompletedState state) completed, + required TResult Function(FailedState state, Object? reason) failed, + }) { + return outgoing(state); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function(OutgoingState state)? outgoing, + TResult? Function(CompletedState state)? completed, + TResult? Function(FailedState state, Object? reason)? failed, + }) { + return outgoing?.call(state); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(OutgoingState state)? outgoing, + TResult Function(CompletedState state)? completed, + TResult Function(FailedState state, Object? reason)? failed, + required TResult orElse(), + }) { + if (outgoing != null) { + return outgoing(state); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(MessageInitial value) initial, + required TResult Function(MessageOutgoing value) outgoing, + required TResult Function(MessageCompleted value) completed, + required TResult Function(MessageFailed value) failed, + }) { + return outgoing(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(MessageInitial value)? initial, + TResult? Function(MessageOutgoing value)? outgoing, + TResult? Function(MessageCompleted value)? completed, + TResult? Function(MessageFailed value)? failed, + }) { + return outgoing?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(MessageInitial value)? initial, + TResult Function(MessageOutgoing value)? outgoing, + TResult Function(MessageCompleted value)? completed, + TResult Function(MessageFailed value)? failed, + required TResult orElse(), + }) { + if (outgoing != null) { + return outgoing(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$MessageOutgoingImplToJson( + this, + ); } } +abstract class MessageOutgoing implements MessageState { + const factory MessageOutgoing({required final OutgoingState state}) = + _$MessageOutgoingImpl; + + factory MessageOutgoing.fromJson(Map json) = + _$MessageOutgoingImpl.fromJson; + + OutgoingState get state; + + /// 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 mixin class $MessageCompletedCopyWith<$Res> - implements $MessageStateCopyWith<$Res> { - factory $MessageCompletedCopyWith( - MessageCompleted value, $Res Function(MessageCompleted) _then) = - _$MessageCompletedCopyWithImpl; +abstract class _$$MessageCompletedImplCopyWith<$Res> { + factory _$$MessageCompletedImplCopyWith(_$MessageCompletedImpl value, + $Res Function(_$MessageCompletedImpl) then) = + __$$MessageCompletedImplCopyWithImpl<$Res>; @useResult $Res call({CompletedState state}); @@ -236,22 +440,23 @@ abstract mixin class $MessageCompletedCopyWith<$Res> } /// @nodoc -class _$MessageCompletedCopyWithImpl<$Res> - implements $MessageCompletedCopyWith<$Res> { - _$MessageCompletedCopyWithImpl(this._self, this._then); - - final MessageCompleted _self; - final $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 - ? _self.state + ? _value.state : state // ignore: cast_nullable_to_non_nullable as CompletedState, )); @@ -262,66 +467,156 @@ class _$MessageCompletedCopyWithImpl<$Res> @override @pragma('vm:prefer-inline') $CompletedStateCopyWith<$Res> get state { - return $CompletedStateCopyWith<$Res>(_self.state, (value) { - return _then(_self.copyWith(state: value)); + return $CompletedStateCopyWith<$Res>(_value.state, (value) { + return _then(_value.copyWith(state: value)); }); } } /// @nodoc @JsonSerializable() -class MessageFailed implements MessageState { - const MessageFailed({required this.state, this.reason, final String? $type}) - : $type = $type ?? 'failed'; - factory MessageFailed.fromJson(Map json) => - _$MessageFailedFromJson(json); +class _$MessageCompletedImpl implements MessageCompleted { + const _$MessageCompletedImpl({required this.state, final String? $type}) + : $type = $type ?? 'completed'; - final FailedState state; - final Object? reason; + factory _$MessageCompletedImpl.fromJson(Map json) => + _$$MessageCompletedImplFromJson(json); + + @override + final CompletedState state; @JsonKey(name: 'runtimeType') final String $type; + @override + String toString() { + return 'MessageState.completed(state: $state)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MessageCompletedImpl && + (identical(other.state, state) || other.state == state)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, state); + /// 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 get copyWith => - _$MessageFailedCopyWithImpl(this, _$identity); + _$$MessageCompletedImplCopyWith<_$MessageCompletedImpl> get copyWith => + __$$MessageCompletedImplCopyWithImpl<_$MessageCompletedImpl>( + this, _$identity); @override - Map toJson() { - return _$MessageFailedToJson( - this, - ); + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(OutgoingState state) outgoing, + required TResult Function(CompletedState state) completed, + required TResult Function(FailedState state, Object? reason) failed, + }) { + return completed(state); } @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is MessageFailed && - (identical(other.state, state) || other.state == state) && - const DeepCollectionEquality().equals(other.reason, reason)); + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function(OutgoingState state)? outgoing, + TResult? Function(CompletedState state)? completed, + TResult? Function(FailedState state, Object? reason)? failed, + }) { + return completed?.call(state); } - @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash( - runtimeType, state, const DeepCollectionEquality().hash(reason)); + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(OutgoingState state)? outgoing, + TResult Function(CompletedState state)? completed, + TResult Function(FailedState state, Object? reason)? failed, + required TResult orElse(), + }) { + if (completed != null) { + return completed(state); + } + return orElse(); + } @override - String toString() { - return 'MessageState.failed(state: $state, reason: $reason)'; + @optionalTypeArgs + TResult map({ + required TResult Function(MessageInitial value) initial, + required TResult Function(MessageOutgoing value) outgoing, + required TResult Function(MessageCompleted value) completed, + required TResult Function(MessageFailed value) failed, + }) { + return completed(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(MessageInitial value)? initial, + TResult? Function(MessageOutgoing value)? outgoing, + TResult? Function(MessageCompleted value)? completed, + TResult? Function(MessageFailed value)? failed, + }) { + return completed?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(MessageInitial value)? initial, + TResult Function(MessageOutgoing value)? outgoing, + TResult Function(MessageCompleted value)? completed, + TResult Function(MessageFailed value)? failed, + required TResult orElse(), + }) { + if (completed != null) { + return completed(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$MessageCompletedImplToJson( + this, + ); } } +abstract class MessageCompleted implements MessageState { + const factory MessageCompleted({required final CompletedState state}) = + _$MessageCompletedImpl; + + factory MessageCompleted.fromJson(Map json) = + _$MessageCompletedImpl.fromJson; + + CompletedState get state; + + /// 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 mixin class $MessageFailedCopyWith<$Res> - implements $MessageStateCopyWith<$Res> { - factory $MessageFailedCopyWith( - MessageFailed value, $Res Function(MessageFailed) _then) = - _$MessageFailedCopyWithImpl; +abstract class _$$MessageFailedImplCopyWith<$Res> { + factory _$$MessageFailedImplCopyWith( + _$MessageFailedImpl value, $Res Function(_$MessageFailedImpl) then) = + __$$MessageFailedImplCopyWithImpl<$Res>; @useResult $Res call({FailedState state, Object? reason}); @@ -329,26 +624,27 @@ abstract mixin class $MessageFailedCopyWith<$Res> } /// @nodoc -class _$MessageFailedCopyWithImpl<$Res> - implements $MessageFailedCopyWith<$Res> { - _$MessageFailedCopyWithImpl(this._self, this._then); - - final MessageFailed _self; - final $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 - ? _self.state + ? _value.state : state // ignore: cast_nullable_to_non_nullable as FailedState, - reason: freezed == reason ? _self.reason : reason, + reason: freezed == reason ? _value.reason : reason, )); } @@ -357,107 +653,283 @@ class _$MessageFailedCopyWithImpl<$Res> @override @pragma('vm:prefer-inline') $FailedStateCopyWith<$Res> get state { - return $FailedStateCopyWith<$Res>(_self.state, (value) { - return _then(_self.copyWith(state: value)); + return $FailedStateCopyWith<$Res>(_value.state, (value) { + return _then(_value.copyWith(state: value)); }); } } -OutgoingState _$OutgoingStateFromJson(Map json) { - switch (json['runtimeType']) { - case 'sending': - return Sending.fromJson(json); - case 'updating': - return Updating.fromJson(json); - case 'deleting': - return Deleting.fromJson(json); - - default: - throw CheckedFromJsonException(json, 'runtimeType', 'OutgoingState', - 'Invalid union type "${json['runtimeType']}"!'); - } -} - /// @nodoc -mixin _$OutgoingState { - /// Serializes this OutgoingState to a JSON map. - Map toJson(); +@JsonSerializable() +class _$MessageFailedImpl implements MessageFailed { + const _$MessageFailedImpl( + {required this.state, this.reason, final String? $type}) + : $type = $type ?? 'failed'; - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is OutgoingState); - } + factory _$MessageFailedImpl.fromJson(Map json) => + _$$MessageFailedImplFromJson(json); - @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => runtimeType.hashCode; - + final FailedState state; @override - String toString() { - return 'OutgoingState()'; - } -} - -/// @nodoc -class $OutgoingStateCopyWith<$Res> { - $OutgoingStateCopyWith(OutgoingState _, $Res Function(OutgoingState) __); -} - -/// @nodoc -@JsonSerializable() -class Sending implements OutgoingState { - const Sending({final String? $type}) : $type = $type ?? 'sending'; - factory Sending.fromJson(Map json) => - _$SendingFromJson(json); + final Object? reason; @JsonKey(name: 'runtimeType') final String $type; @override - Map toJson() { - return _$SendingToJson( - this, - ); + String toString() { + return 'MessageState.failed(state: $state, reason: $reason)'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is Sending); + (other.runtimeType == runtimeType && + other is _$MessageFailedImpl && + (identical(other.state, state) || other.state == state) && + const DeepCollectionEquality().equals(other.reason, reason)); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => runtimeType.hashCode; + int get hashCode => Object.hash( + runtimeType, state, const DeepCollectionEquality().hash(reason)); + /// Create a copy of MessageState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override - String toString() { - return 'OutgoingState.sending()'; + @pragma('vm:prefer-inline') + _$$MessageFailedImplCopyWith<_$MessageFailedImpl> get copyWith => + __$$MessageFailedImplCopyWithImpl<_$MessageFailedImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(OutgoingState state) outgoing, + required TResult Function(CompletedState state) completed, + required TResult Function(FailedState state, Object? reason) failed, + }) { + return failed(state, reason); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function(OutgoingState state)? outgoing, + TResult? Function(CompletedState state)? completed, + TResult? Function(FailedState state, Object? reason)? failed, + }) { + return failed?.call(state, reason); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(OutgoingState state)? outgoing, + TResult Function(CompletedState state)? completed, + TResult Function(FailedState state, Object? reason)? failed, + required TResult orElse(), + }) { + if (failed != null) { + return failed(state, reason); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(MessageInitial value) initial, + required TResult Function(MessageOutgoing value) outgoing, + required TResult Function(MessageCompleted value) completed, + required TResult Function(MessageFailed value) failed, + }) { + return failed(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(MessageInitial value)? initial, + TResult? Function(MessageOutgoing value)? outgoing, + TResult? Function(MessageCompleted value)? completed, + TResult? Function(MessageFailed value)? failed, + }) { + return failed?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(MessageInitial value)? initial, + TResult Function(MessageOutgoing value)? outgoing, + TResult Function(MessageCompleted value)? completed, + TResult Function(MessageFailed value)? failed, + required TResult orElse(), + }) { + if (failed != null) { + return failed(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$MessageFailedImplToJson( + this, + ); + } +} + +abstract class MessageFailed implements MessageState { + const factory MessageFailed( + {required final FailedState state, + final Object? reason}) = _$MessageFailedImpl; + + factory MessageFailed.fromJson(Map json) = + _$MessageFailedImpl.fromJson; + + FailedState get state; + Object? get reason; + + /// 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; +} + +OutgoingState _$OutgoingStateFromJson(Map json) { + switch (json['runtimeType']) { + case 'sending': + return Sending.fromJson(json); + case 'updating': + return Updating.fromJson(json); + case 'deleting': + return Deleting.fromJson(json); + + default: + throw CheckedFromJsonException(json, 'runtimeType', 'OutgoingState', + 'Invalid union type "${json['runtimeType']}"!'); } } +/// @nodoc +mixin _$OutgoingState { + @optionalTypeArgs + TResult when({ + required TResult Function() sending, + required TResult Function() updating, + required TResult Function(bool hard) deleting, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sending, + TResult? Function()? updating, + TResult? Function(bool hard)? deleting, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sending, + TResult Function()? updating, + TResult Function(bool hard)? deleting, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Sending value) sending, + required TResult Function(Updating value) updating, + required TResult Function(Deleting value) deleting, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Sending value)? sending, + TResult? Function(Updating value)? updating, + TResult? Function(Deleting value)? deleting, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Sending value)? sending, + TResult Function(Updating value)? updating, + TResult Function(Deleting value)? deleting, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + /// Serializes this OutgoingState to a JSON map. + Map toJson() => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $OutgoingStateCopyWith<$Res> { + factory $OutgoingStateCopyWith( + OutgoingState value, $Res Function(OutgoingState) then) = + _$OutgoingStateCopyWithImpl<$Res, OutgoingState>; +} + +/// @nodoc +class _$OutgoingStateCopyWithImpl<$Res, $Val extends OutgoingState> + implements $OutgoingStateCopyWith<$Res> { + _$OutgoingStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + 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 _$$SendingImplCopyWith<$Res> { + factory _$$SendingImplCopyWith( + _$SendingImpl value, $Res Function(_$SendingImpl) then) = + __$$SendingImplCopyWithImpl<$Res>; +} + +/// @nodoc +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 Updating implements OutgoingState { - const Updating({final String? $type}) : $type = $type ?? 'updating'; - factory Updating.fromJson(Map json) => - _$UpdatingFromJson(json); +class _$SendingImpl implements Sending { + const _$SendingImpl({final String? $type}) : $type = $type ?? 'sending'; + + factory _$SendingImpl.fromJson(Map json) => + _$$SendingImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @override - Map toJson() { - return _$UpdatingToJson( - this, - ); + String toString() { + return 'OutgoingState.sending()'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is Updating); + (other.runtimeType == runtimeType && other is _$SendingImpl); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -465,88 +937,380 @@ class Updating implements OutgoingState { int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'OutgoingState.updating()'; + @optionalTypeArgs + TResult when({ + required TResult Function() sending, + required TResult Function() updating, + required TResult Function(bool hard) deleting, + }) { + return sending(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sending, + TResult? Function()? updating, + TResult? Function(bool hard)? deleting, + }) { + return sending?.call(); } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sending, + TResult Function()? updating, + TResult Function(bool hard)? deleting, + required TResult orElse(), + }) { + if (sending != null) { + return sending(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Sending value) sending, + required TResult Function(Updating value) updating, + required TResult Function(Deleting value) deleting, + }) { + return sending(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Sending value)? sending, + TResult? Function(Updating value)? updating, + TResult? Function(Deleting value)? deleting, + }) { + return sending?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Sending value)? sending, + TResult Function(Updating value)? updating, + TResult Function(Deleting value)? deleting, + required TResult orElse(), + }) { + if (sending != null) { + return sending(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$SendingImplToJson( + this, + ); + } +} + +abstract class Sending implements OutgoingState { + const factory Sending() = _$SendingImpl; + + factory Sending.fromJson(Map json) = _$SendingImpl.fromJson; +} + +/// @nodoc +abstract class _$$UpdatingImplCopyWith<$Res> { + factory _$$UpdatingImplCopyWith( + _$UpdatingImpl value, $Res Function(_$UpdatingImpl) then) = + __$$UpdatingImplCopyWithImpl<$Res>; +} + +/// @nodoc +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 Deleting implements OutgoingState { - const Deleting({this.hard = false, final String? $type}) - : $type = $type ?? 'deleting'; - factory Deleting.fromJson(Map json) => - _$DeletingFromJson(json); +class _$UpdatingImpl implements Updating { + const _$UpdatingImpl({final String? $type}) : $type = $type ?? 'updating'; - @JsonKey() - final bool hard; + factory _$UpdatingImpl.fromJson(Map json) => + _$$UpdatingImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; - /// Create a copy of OutgoingState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $DeletingCopyWith get copyWith => - _$DeletingCopyWithImpl(this, _$identity); - @override - Map toJson() { - return _$DeletingToJson( - this, - ); + String toString() { + return 'OutgoingState.updating()'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && - other is Deleting && - (identical(other.hard, hard) || other.hard == hard)); + (other.runtimeType == runtimeType && other is _$UpdatingImpl); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, hard); + int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'OutgoingState.deleting(hard: $hard)'; + @optionalTypeArgs + TResult when({ + required TResult Function() sending, + required TResult Function() updating, + required TResult Function(bool hard) deleting, + }) { + return updating(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sending, + TResult? Function()? updating, + TResult? Function(bool hard)? deleting, + }) { + return updating?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sending, + TResult Function()? updating, + TResult Function(bool hard)? deleting, + required TResult orElse(), + }) { + if (updating != null) { + return updating(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Sending value) sending, + required TResult Function(Updating value) updating, + required TResult Function(Deleting value) deleting, + }) { + return updating(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Sending value)? sending, + TResult? Function(Updating value)? updating, + TResult? Function(Deleting value)? deleting, + }) { + return updating?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Sending value)? sending, + TResult Function(Updating value)? updating, + TResult Function(Deleting value)? deleting, + required TResult orElse(), + }) { + if (updating != null) { + return updating(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$UpdatingImplToJson( + this, + ); } } +abstract class Updating implements OutgoingState { + const factory Updating() = _$UpdatingImpl; + + factory Updating.fromJson(Map json) = + _$UpdatingImpl.fromJson; +} + /// @nodoc -abstract mixin class $DeletingCopyWith<$Res> - implements $OutgoingStateCopyWith<$Res> { - factory $DeletingCopyWith(Deleting value, $Res Function(Deleting) _then) = - _$DeletingCopyWithImpl; +abstract class _$$DeletingImplCopyWith<$Res> { + factory _$$DeletingImplCopyWith( + _$DeletingImpl value, $Res Function(_$DeletingImpl) then) = + __$$DeletingImplCopyWithImpl<$Res>; @useResult $Res call({bool hard}); } /// @nodoc -class _$DeletingCopyWithImpl<$Res> implements $DeletingCopyWith<$Res> { - _$DeletingCopyWithImpl(this._self, this._then); - - final Deleting _self; - final $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 - ? _self.hard + ? _value.hard : hard // ignore: cast_nullable_to_non_nullable as bool, )); } } +/// @nodoc +@JsonSerializable() +class _$DeletingImpl implements Deleting { + const _$DeletingImpl({this.hard = false, final String? $type}) + : $type = $type ?? 'deleting'; + + factory _$DeletingImpl.fromJson(Map json) => + _$$DeletingImplFromJson(json); + + @override + @JsonKey() + final bool hard; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'OutgoingState.deleting(hard: $hard)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$DeletingImpl && + (identical(other.hard, hard) || other.hard == hard)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, hard); + + /// 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') + _$$DeletingImplCopyWith<_$DeletingImpl> get copyWith => + __$$DeletingImplCopyWithImpl<_$DeletingImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() sending, + required TResult Function() updating, + required TResult Function(bool hard) deleting, + }) { + return deleting(hard); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sending, + TResult? Function()? updating, + TResult? Function(bool hard)? deleting, + }) { + return deleting?.call(hard); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sending, + TResult Function()? updating, + TResult Function(bool hard)? deleting, + required TResult orElse(), + }) { + if (deleting != null) { + return deleting(hard); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Sending value) sending, + required TResult Function(Updating value) updating, + required TResult Function(Deleting value) deleting, + }) { + return deleting(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Sending value)? sending, + TResult? Function(Updating value)? updating, + TResult? Function(Deleting value)? deleting, + }) { + return deleting?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Sending value)? sending, + TResult Function(Updating value)? updating, + TResult Function(Deleting value)? deleting, + required TResult orElse(), + }) { + if (deleting != null) { + return deleting(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$DeletingImplToJson( + this, + ); + } +} + +abstract class Deleting implements OutgoingState { + const factory Deleting({final bool hard}) = _$DeletingImpl; + + factory Deleting.fromJson(Map json) = + _$DeletingImpl.fromJson; + + bool get hard; + + /// 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; +} + CompletedState _$CompletedStateFromJson(Map json) { switch (json['runtimeType']) { case 'sent': @@ -564,50 +1328,114 @@ CompletedState _$CompletedStateFromJson(Map json) { /// @nodoc mixin _$CompletedState { + @optionalTypeArgs + TResult when({ + required TResult Function() sent, + required TResult Function() updated, + required TResult Function(bool hard) deleted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sent, + TResult? Function()? updated, + TResult? Function(bool hard)? deleted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sent, + TResult Function()? updated, + TResult Function(bool hard)? deleted, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Sent value) sent, + required TResult Function(Updated value) updated, + required TResult Function(Deleted value) deleted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Sent value)? sent, + TResult? Function(Updated value)? updated, + TResult? Function(Deleted value)? deleted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Sent value)? sent, + TResult Function(Updated value)? updated, + TResult Function(Deleted value)? deleted, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + /// Serializes this CompletedState to a JSON map. - Map toJson(); + Map toJson() => throw _privateConstructorUsedError; +} - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is CompletedState); - } +/// @nodoc +abstract class $CompletedStateCopyWith<$Res> { + factory $CompletedStateCopyWith( + CompletedState value, $Res Function(CompletedState) then) = + _$CompletedStateCopyWithImpl<$Res, CompletedState>; +} - @JsonKey(includeFromJson: false, includeToJson: false) - @override - int get hashCode => runtimeType.hashCode; +/// @nodoc +class _$CompletedStateCopyWithImpl<$Res, $Val extends CompletedState> + implements $CompletedStateCopyWith<$Res> { + _$CompletedStateCopyWithImpl(this._value, this._then); - @override - String toString() { - return 'CompletedState()'; - } + // ignore: unused_field + 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 _$$SentImplCopyWith<$Res> { + factory _$$SentImplCopyWith( + _$SentImpl value, $Res Function(_$SentImpl) then) = + __$$SentImplCopyWithImpl<$Res>; } /// @nodoc -class $CompletedStateCopyWith<$Res> { - $CompletedStateCopyWith(CompletedState _, $Res Function(CompletedState) __); +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 CompletedState { - const Sent({final String? $type}) : $type = $type ?? 'sent'; - factory Sent.fromJson(Map json) => _$SentFromJson(json); +class _$SentImpl implements Sent { + const _$SentImpl({final String? $type}) : $type = $type ?? 'sent'; + + factory _$SentImpl.fromJson(Map json) => + _$$SentImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @override - Map toJson() { - return _$SentToJson( - this, - ); + String toString() { + return 'CompletedState.sent()'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is Sent); + (other.runtimeType == runtimeType && other is _$SentImpl); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -615,32 +1443,126 @@ class Sent implements CompletedState { int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'CompletedState.sent()'; + @optionalTypeArgs + TResult when({ + required TResult Function() sent, + required TResult Function() updated, + required TResult Function(bool hard) deleted, + }) { + return sent(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sent, + TResult? Function()? updated, + TResult? Function(bool hard)? deleted, + }) { + return sent?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sent, + TResult Function()? updated, + TResult Function(bool hard)? deleted, + required TResult orElse(), + }) { + if (sent != null) { + return sent(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Sent value) sent, + required TResult Function(Updated value) updated, + required TResult Function(Deleted value) deleted, + }) { + return sent(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Sent value)? sent, + TResult? Function(Updated value)? updated, + TResult? Function(Deleted value)? deleted, + }) { + return sent?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Sent value)? sent, + TResult Function(Updated value)? updated, + TResult Function(Deleted value)? deleted, + required TResult orElse(), + }) { + if (sent != null) { + return sent(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$SentImplToJson( + this, + ); } } +abstract class Sent implements CompletedState { + const factory Sent() = _$SentImpl; + + factory Sent.fromJson(Map json) = _$SentImpl.fromJson; +} + +/// @nodoc +abstract class _$$UpdatedImplCopyWith<$Res> { + factory _$$UpdatedImplCopyWith( + _$UpdatedImpl value, $Res Function(_$UpdatedImpl) then) = + __$$UpdatedImplCopyWithImpl<$Res>; +} + +/// @nodoc +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 CompletedState { - const Updated({final String? $type}) : $type = $type ?? 'updated'; - factory Updated.fromJson(Map json) => - _$UpdatedFromJson(json); +class _$UpdatedImpl implements Updated { + const _$UpdatedImpl({final String? $type}) : $type = $type ?? 'updated'; + + factory _$UpdatedImpl.fromJson(Map json) => + _$$UpdatedImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @override - Map toJson() { - return _$UpdatedToJson( - this, - ); + String toString() { + return 'CompletedState.updated()'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is Updated); + (other.runtimeType == runtimeType && other is _$UpdatedImpl); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -648,44 +1570,146 @@ class Updated implements CompletedState { int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'CompletedState.updated()'; + @optionalTypeArgs + TResult when({ + required TResult Function() sent, + required TResult Function() updated, + required TResult Function(bool hard) deleted, + }) { + return updated(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sent, + TResult? Function()? updated, + TResult? Function(bool hard)? deleted, + }) { + return updated?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sent, + TResult Function()? updated, + TResult Function(bool hard)? deleted, + required TResult orElse(), + }) { + if (updated != null) { + return updated(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Sent value) sent, + required TResult Function(Updated value) updated, + required TResult Function(Deleted value) deleted, + }) { + return updated(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Sent value)? sent, + TResult? Function(Updated value)? updated, + TResult? Function(Deleted value)? deleted, + }) { + return updated?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Sent value)? sent, + TResult Function(Updated value)? updated, + TResult Function(Deleted value)? deleted, + required TResult orElse(), + }) { + if (updated != null) { + return updated(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$UpdatedImplToJson( + this, + ); + } +} + +abstract class Updated implements CompletedState { + const factory Updated() = _$UpdatedImpl; + + factory Updated.fromJson(Map json) = _$UpdatedImpl.fromJson; +} + +/// @nodoc +abstract class _$$DeletedImplCopyWith<$Res> { + factory _$$DeletedImplCopyWith( + _$DeletedImpl value, $Res Function(_$DeletedImpl) then) = + __$$DeletedImplCopyWithImpl<$Res>; + @useResult + $Res call({bool hard}); +} + +/// @nodoc +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(_$DeletedImpl( + hard: null == hard + ? _value.hard + : hard // ignore: cast_nullable_to_non_nullable + as bool, + )); } } /// @nodoc @JsonSerializable() -class Deleted implements CompletedState { - 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() final bool hard; @JsonKey(name: 'runtimeType') final String $type; - /// Create a copy of CompletedState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $DeletedCopyWith get copyWith => - _$DeletedCopyWithImpl(this, _$identity); - @override - Map toJson() { - return _$DeletedToJson( - this, - ); + String toString() { + return 'CompletedState.deleted(hard: $hard)'; } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is Deleted && + other is _$DeletedImpl && (identical(other.hard, hard) || other.hard == hard)); } @@ -693,41 +1717,102 @@ class Deleted implements CompletedState { @override int get hashCode => Object.hash(runtimeType, hard); + /// Create a copy of CompletedState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override - String toString() { - return 'CompletedState.deleted(hard: $hard)'; + @pragma('vm:prefer-inline') + _$$DeletedImplCopyWith<_$DeletedImpl> get copyWith => + __$$DeletedImplCopyWithImpl<_$DeletedImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() sent, + required TResult Function() updated, + required TResult Function(bool hard) deleted, + }) { + return deleted(hard); } -} -/// @nodoc -abstract mixin class $DeletedCopyWith<$Res> - implements $CompletedStateCopyWith<$Res> { - factory $DeletedCopyWith(Deleted value, $Res Function(Deleted) _then) = - _$DeletedCopyWithImpl; - @useResult - $Res call({bool hard}); + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sent, + TResult? Function()? updated, + TResult? Function(bool hard)? deleted, + }) { + return deleted?.call(hard); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sent, + TResult Function()? updated, + TResult Function(bool hard)? deleted, + required TResult orElse(), + }) { + if (deleted != null) { + return deleted(hard); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Sent value) sent, + required TResult Function(Updated value) updated, + required TResult Function(Deleted value) deleted, + }) { + return deleted(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Sent value)? sent, + TResult? Function(Updated value)? updated, + TResult? Function(Deleted value)? deleted, + }) { + return deleted?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Sent value)? sent, + TResult Function(Updated value)? updated, + TResult Function(Deleted value)? deleted, + required TResult orElse(), + }) { + if (deleted != null) { + return deleted(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$DeletedImplToJson( + this, + ); + } } -/// @nodoc -class _$DeletedCopyWithImpl<$Res> implements $DeletedCopyWith<$Res> { - _$DeletedCopyWithImpl(this._self, this._then); +abstract class Deleted implements CompletedState { + const factory Deleted({final bool hard}) = _$DeletedImpl; - final Deleted _self; - final $Res Function(Deleted) _then; + factory Deleted.fromJson(Map json) = _$DeletedImpl.fromJson; + + bool get hard; /// Create a copy of CompletedState /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - $Res call({ - Object? hard = null, - }) { - return _then(Deleted( - hard: null == hard - ? _self.hard - : hard // ignore: cast_nullable_to_non_nullable - as bool, - )); - } + @JsonKey(includeFromJson: false, includeToJson: false) + _$$DeletedImplCopyWith<_$DeletedImpl> get copyWith => + throw _privateConstructorUsedError; } FailedState _$FailedStateFromJson(Map json) { @@ -747,51 +1832,116 @@ FailedState _$FailedStateFromJson(Map json) { /// @nodoc mixin _$FailedState { + @optionalTypeArgs + TResult when({ + required TResult Function() sendingFailed, + required TResult Function() updatingFailed, + required TResult Function(bool hard) deletingFailed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sendingFailed, + TResult? Function()? updatingFailed, + TResult? Function(bool hard)? deletingFailed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sendingFailed, + TResult Function()? updatingFailed, + TResult Function(bool hard)? deletingFailed, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(SendingFailed value) sendingFailed, + required TResult Function(UpdatingFailed value) updatingFailed, + required TResult Function(DeletingFailed value) deletingFailed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SendingFailed value)? sendingFailed, + TResult? Function(UpdatingFailed value)? updatingFailed, + TResult? Function(DeletingFailed value)? deletingFailed, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SendingFailed value)? sendingFailed, + TResult Function(UpdatingFailed value)? updatingFailed, + TResult Function(DeletingFailed value)? deletingFailed, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + /// Serializes this FailedState to a JSON map. - Map toJson(); + Map toJson() => throw _privateConstructorUsedError; +} - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is FailedState); - } +/// @nodoc +abstract class $FailedStateCopyWith<$Res> { + factory $FailedStateCopyWith( + FailedState value, $Res Function(FailedState) then) = + _$FailedStateCopyWithImpl<$Res, FailedState>; +} - @JsonKey(includeFromJson: false, includeToJson: false) - @override - int get hashCode => runtimeType.hashCode; +/// @nodoc +class _$FailedStateCopyWithImpl<$Res, $Val extends FailedState> + implements $FailedStateCopyWith<$Res> { + _$FailedStateCopyWithImpl(this._value, this._then); - @override - String toString() { - return 'FailedState()'; - } + // ignore: unused_field + 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 -class $FailedStateCopyWith<$Res> { - $FailedStateCopyWith(FailedState _, $Res Function(FailedState) __); +abstract class _$$SendingFailedImplCopyWith<$Res> { + factory _$$SendingFailedImplCopyWith( + _$SendingFailedImpl value, $Res Function(_$SendingFailedImpl) then) = + __$$SendingFailedImplCopyWithImpl<$Res>; +} + +/// @nodoc +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 FailedState { - const SendingFailed({final String? $type}) : $type = $type ?? 'sendingFailed'; - factory SendingFailed.fromJson(Map json) => - _$SendingFailedFromJson(json); +class _$SendingFailedImpl implements SendingFailed { + const _$SendingFailedImpl({final String? $type}) + : $type = $type ?? 'sendingFailed'; + + factory _$SendingFailedImpl.fromJson(Map json) => + _$$SendingFailedImplFromJson(json); @JsonKey(name: 'runtimeType') final String $type; @override - Map toJson() { - return _$SendingFailedToJson( - this, - ); + String toString() { + return 'FailedState.sendingFailed()'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is SendingFailed); + (other.runtimeType == runtimeType && other is _$SendingFailedImpl); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -799,33 +1949,128 @@ class SendingFailed implements FailedState { int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'FailedState.sendingFailed()'; + @optionalTypeArgs + TResult when({ + required TResult Function() sendingFailed, + required TResult Function() updatingFailed, + required TResult Function(bool hard) deletingFailed, + }) { + return sendingFailed(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sendingFailed, + TResult? Function()? updatingFailed, + TResult? Function(bool hard)? deletingFailed, + }) { + return sendingFailed?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sendingFailed, + TResult Function()? updatingFailed, + TResult Function(bool hard)? deletingFailed, + required TResult orElse(), + }) { + if (sendingFailed != null) { + return sendingFailed(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(SendingFailed value) sendingFailed, + required TResult Function(UpdatingFailed value) updatingFailed, + required TResult Function(DeletingFailed value) deletingFailed, + }) { + return sendingFailed(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SendingFailed value)? sendingFailed, + TResult? Function(UpdatingFailed value)? updatingFailed, + TResult? Function(DeletingFailed value)? deletingFailed, + }) { + return sendingFailed?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SendingFailed value)? sendingFailed, + TResult Function(UpdatingFailed value)? updatingFailed, + TResult Function(DeletingFailed value)? deletingFailed, + required TResult orElse(), + }) { + if (sendingFailed != null) { + return sendingFailed(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$SendingFailedImplToJson( + this, + ); } } +abstract class SendingFailed implements FailedState { + const factory SendingFailed() = _$SendingFailedImpl; + + factory SendingFailed.fromJson(Map json) = + _$SendingFailedImpl.fromJson; +} + +/// @nodoc +abstract class _$$UpdatingFailedImplCopyWith<$Res> { + factory _$$UpdatingFailedImplCopyWith(_$UpdatingFailedImpl value, + $Res Function(_$UpdatingFailedImpl) then) = + __$$UpdatingFailedImplCopyWithImpl<$Res>; +} + +/// @nodoc +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 FailedState { - 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; @override - Map toJson() { - return _$UpdatingFailedToJson( - this, - ); + String toString() { + return 'FailedState.updatingFailed()'; } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is UpdatingFailed); + (other.runtimeType == runtimeType && other is _$UpdatingFailedImpl); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -833,44 +2078,147 @@ class UpdatingFailed implements FailedState { int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'FailedState.updatingFailed()'; + @optionalTypeArgs + TResult when({ + required TResult Function() sendingFailed, + required TResult Function() updatingFailed, + required TResult Function(bool hard) deletingFailed, + }) { + return updatingFailed(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sendingFailed, + TResult? Function()? updatingFailed, + TResult? Function(bool hard)? deletingFailed, + }) { + return updatingFailed?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sendingFailed, + TResult Function()? updatingFailed, + TResult Function(bool hard)? deletingFailed, + required TResult orElse(), + }) { + if (updatingFailed != null) { + return updatingFailed(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(SendingFailed value) sendingFailed, + required TResult Function(UpdatingFailed value) updatingFailed, + required TResult Function(DeletingFailed value) deletingFailed, + }) { + return updatingFailed(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SendingFailed value)? sendingFailed, + TResult? Function(UpdatingFailed value)? updatingFailed, + TResult? Function(DeletingFailed value)? deletingFailed, + }) { + return updatingFailed?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SendingFailed value)? sendingFailed, + TResult Function(UpdatingFailed value)? updatingFailed, + TResult Function(DeletingFailed value)? deletingFailed, + required TResult orElse(), + }) { + if (updatingFailed != null) { + return updatingFailed(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$UpdatingFailedImplToJson( + this, + ); + } +} + +abstract class UpdatingFailed implements FailedState { + const factory UpdatingFailed() = _$UpdatingFailedImpl; + + factory UpdatingFailed.fromJson(Map json) = + _$UpdatingFailedImpl.fromJson; +} + +/// @nodoc +abstract class _$$DeletingFailedImplCopyWith<$Res> { + factory _$$DeletingFailedImplCopyWith(_$DeletingFailedImpl value, + $Res Function(_$DeletingFailedImpl) then) = + __$$DeletingFailedImplCopyWithImpl<$Res>; + @useResult + $Res call({bool hard}); +} + +/// @nodoc +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(_$DeletingFailedImpl( + hard: null == hard + ? _value.hard + : hard // ignore: cast_nullable_to_non_nullable + as bool, + )); } } /// @nodoc @JsonSerializable() -class DeletingFailed implements FailedState { - 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() final bool hard; @JsonKey(name: 'runtimeType') final String $type; - /// Create a copy of FailedState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $DeletingFailedCopyWith get copyWith => - _$DeletingFailedCopyWithImpl(this, _$identity); - @override - Map toJson() { - return _$DeletingFailedToJson( - this, - ); + String toString() { + return 'FailedState.deletingFailed(hard: $hard)'; } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is DeletingFailed && + other is _$DeletingFailedImpl && (identical(other.hard, hard) || other.hard == hard)); } @@ -878,43 +2226,102 @@ class DeletingFailed implements FailedState { @override int get hashCode => Object.hash(runtimeType, hard); + /// Create a copy of FailedState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) @override - String toString() { - return 'FailedState.deletingFailed(hard: $hard)'; + @pragma('vm:prefer-inline') + _$$DeletingFailedImplCopyWith<_$DeletingFailedImpl> get copyWith => + __$$DeletingFailedImplCopyWithImpl<_$DeletingFailedImpl>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() sendingFailed, + required TResult Function() updatingFailed, + required TResult Function(bool hard) deletingFailed, + }) { + return deletingFailed(hard); } -} -/// @nodoc -abstract mixin class $DeletingFailedCopyWith<$Res> - implements $FailedStateCopyWith<$Res> { - factory $DeletingFailedCopyWith( - DeletingFailed value, $Res Function(DeletingFailed) _then) = - _$DeletingFailedCopyWithImpl; - @useResult - $Res call({bool hard}); -} + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? sendingFailed, + TResult? Function()? updatingFailed, + TResult? Function(bool hard)? deletingFailed, + }) { + return deletingFailed?.call(hard); + } -/// @nodoc -class _$DeletingFailedCopyWithImpl<$Res> - implements $DeletingFailedCopyWith<$Res> { - _$DeletingFailedCopyWithImpl(this._self, this._then); + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? sendingFailed, + TResult Function()? updatingFailed, + TResult Function(bool hard)? deletingFailed, + required TResult orElse(), + }) { + if (deletingFailed != null) { + return deletingFailed(hard); + } + return orElse(); + } - final DeletingFailed _self; - final $Res Function(DeletingFailed) _then; + @override + @optionalTypeArgs + TResult map({ + required TResult Function(SendingFailed value) sendingFailed, + required TResult Function(UpdatingFailed value) updatingFailed, + required TResult Function(DeletingFailed value) deletingFailed, + }) { + return deletingFailed(this); + } - /// Create a copy of FailedState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - $Res call({ - Object? hard = null, + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(SendingFailed value)? sendingFailed, + TResult? Function(UpdatingFailed value)? updatingFailed, + TResult? Function(DeletingFailed value)? deletingFailed, }) { - return _then(DeletingFailed( - hard: null == hard - ? _self.hard - : hard // ignore: cast_nullable_to_non_nullable - as bool, - )); + return deletingFailed?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(SendingFailed value)? sendingFailed, + TResult Function(UpdatingFailed value)? updatingFailed, + TResult Function(DeletingFailed value)? deletingFailed, + required TResult orElse(), + }) { + if (deletingFailed != null) { + return deletingFailed(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$DeletingFailedImplToJson( + this, + ); } } -// dart format on +abstract class DeletingFailed implements FailedState { + const factory DeletingFailed({final bool hard}) = _$DeletingFailedImpl; + + factory DeletingFailed.fromJson(Map json) = + _$DeletingFailedImpl.fromJson; + + bool get hard; + + /// 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 e39b40667b..7cf2531c89 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,133 +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/poll_voting_mode.freezed.dart b/packages/stream_chat/lib/src/core/models/poll_voting_mode.freezed.dart index 7353088c2a..1545f113aa 100644 --- a/packages/stream_chat/lib/src/core/models/poll_voting_mode.freezed.dart +++ b/packages/stream_chat/lib/src/core/models/poll_voting_mode.freezed.dart @@ -1,4 +1,3 @@ -// dart format width=80 // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint @@ -10,129 +9,347 @@ part of 'poll_voting_mode.dart'; // FreezedGenerator // ************************************************************************** -// dart format off 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#adding-getters-and-methods-to-our-models'); + /// @nodoc mixin _$PollVotingMode { - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is PollVotingMode); - } + @optionalTypeArgs + TResult when({ + required TResult Function() disabled, + required TResult Function() unique, + required TResult Function(int count) limited, + required TResult Function() all, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? disabled, + TResult? Function()? unique, + TResult? Function(int count)? limited, + TResult? Function()? all, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? disabled, + TResult Function()? unique, + TResult Function(int count)? limited, + TResult Function()? all, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(VotingDisabled value) disabled, + required TResult Function(VotingUnique value) unique, + required TResult Function(VotingLimited value) limited, + required TResult Function(VotingAll value) all, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(VotingDisabled value)? disabled, + TResult? Function(VotingUnique value)? unique, + TResult? Function(VotingLimited value)? limited, + TResult? Function(VotingAll value)? all, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(VotingDisabled value)? disabled, + TResult Function(VotingUnique value)? unique, + TResult Function(VotingLimited value)? limited, + TResult Function(VotingAll value)? all, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} - @override - int get hashCode => runtimeType.hashCode; +/// @nodoc +abstract class $PollVotingModeCopyWith<$Res> { + factory $PollVotingModeCopyWith( + PollVotingMode value, $Res Function(PollVotingMode) then) = + _$PollVotingModeCopyWithImpl<$Res, PollVotingMode>; +} - @override - String toString() { - return 'PollVotingMode()'; - } +/// @nodoc +class _$PollVotingModeCopyWithImpl<$Res, $Val extends PollVotingMode> + implements $PollVotingModeCopyWith<$Res> { + _$PollVotingModeCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of PollVotingMode + /// with the given fields replaced by the non-null parameter values. } /// @nodoc -class $PollVotingModeCopyWith<$Res> { - $PollVotingModeCopyWith(PollVotingMode _, $Res Function(PollVotingMode) __); +abstract class _$$VotingDisabledImplCopyWith<$Res> { + factory _$$VotingDisabledImplCopyWith(_$VotingDisabledImpl value, + $Res Function(_$VotingDisabledImpl) then) = + __$$VotingDisabledImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$VotingDisabledImplCopyWithImpl<$Res> + extends _$PollVotingModeCopyWithImpl<$Res, _$VotingDisabledImpl> + implements _$$VotingDisabledImplCopyWith<$Res> { + __$$VotingDisabledImplCopyWithImpl( + _$VotingDisabledImpl _value, $Res Function(_$VotingDisabledImpl) _then) + : super(_value, _then); + + /// Create a copy of PollVotingMode + /// with the given fields replaced by the non-null parameter values. } /// @nodoc -class VotingDisabled implements PollVotingMode { - const VotingDisabled(); +class _$VotingDisabledImpl implements VotingDisabled { + const _$VotingDisabledImpl(); + + @override + String toString() { + return 'PollVotingMode.disabled()'; + } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is VotingDisabled); + (other.runtimeType == runtimeType && other is _$VotingDisabledImpl); } @override int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'PollVotingMode.disabled()'; + @optionalTypeArgs + TResult when({ + required TResult Function() disabled, + required TResult Function() unique, + required TResult Function(int count) limited, + required TResult Function() all, + }) { + return disabled(); } -} -/// @nodoc + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? disabled, + TResult? Function()? unique, + TResult? Function(int count)? limited, + TResult? Function()? all, + }) { + return disabled?.call(); + } -class VotingUnique implements PollVotingMode { - const VotingUnique(); + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? disabled, + TResult Function()? unique, + TResult Function(int count)? limited, + TResult Function()? all, + required TResult orElse(), + }) { + if (disabled != null) { + return disabled(); + } + return orElse(); + } @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is VotingUnique); + @optionalTypeArgs + TResult map({ + required TResult Function(VotingDisabled value) disabled, + required TResult Function(VotingUnique value) unique, + required TResult Function(VotingLimited value) limited, + required TResult Function(VotingAll value) all, + }) { + return disabled(this); } @override - int get hashCode => runtimeType.hashCode; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(VotingDisabled value)? disabled, + TResult? Function(VotingUnique value)? unique, + TResult? Function(VotingLimited value)? limited, + TResult? Function(VotingAll value)? all, + }) { + return disabled?.call(this); + } @override - String toString() { - return 'PollVotingMode.unique()'; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(VotingDisabled value)? disabled, + TResult Function(VotingUnique value)? unique, + TResult Function(VotingLimited value)? limited, + TResult Function(VotingAll value)? all, + required TResult orElse(), + }) { + if (disabled != null) { + return disabled(this); + } + return orElse(); } } -/// @nodoc +abstract class VotingDisabled implements PollVotingMode { + const factory VotingDisabled() = _$VotingDisabledImpl; +} -class VotingLimited implements PollVotingMode { - const VotingLimited({required this.count}); +/// @nodoc +abstract class _$$VotingUniqueImplCopyWith<$Res> { + factory _$$VotingUniqueImplCopyWith( + _$VotingUniqueImpl value, $Res Function(_$VotingUniqueImpl) then) = + __$$VotingUniqueImplCopyWithImpl<$Res>; +} - final int count; +/// @nodoc +class __$$VotingUniqueImplCopyWithImpl<$Res> + extends _$PollVotingModeCopyWithImpl<$Res, _$VotingUniqueImpl> + implements _$$VotingUniqueImplCopyWith<$Res> { + __$$VotingUniqueImplCopyWithImpl( + _$VotingUniqueImpl _value, $Res Function(_$VotingUniqueImpl) _then) + : super(_value, _then); /// Create a copy of PollVotingMode /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $VotingLimitedCopyWith get copyWith => - _$VotingLimitedCopyWithImpl(this, _$identity); +} + +/// @nodoc + +class _$VotingUniqueImpl implements VotingUnique { + const _$VotingUniqueImpl(); + + @override + String toString() { + return 'PollVotingMode.unique()'; + } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && - other is VotingLimited && - (identical(other.count, count) || other.count == count)); + (other.runtimeType == runtimeType && other is _$VotingUniqueImpl); } @override - int get hashCode => Object.hash(runtimeType, count); + int get hashCode => runtimeType.hashCode; @override - String toString() { - return 'PollVotingMode.limited(count: $count)'; + @optionalTypeArgs + TResult when({ + required TResult Function() disabled, + required TResult Function() unique, + required TResult Function(int count) limited, + required TResult Function() all, + }) { + return unique(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? disabled, + TResult? Function()? unique, + TResult? Function(int count)? limited, + TResult? Function()? all, + }) { + return unique?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? disabled, + TResult Function()? unique, + TResult Function(int count)? limited, + TResult Function()? all, + required TResult orElse(), + }) { + if (unique != null) { + return unique(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(VotingDisabled value) disabled, + required TResult Function(VotingUnique value) unique, + required TResult Function(VotingLimited value) limited, + required TResult Function(VotingAll value) all, + }) { + return unique(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(VotingDisabled value)? disabled, + TResult? Function(VotingUnique value)? unique, + TResult? Function(VotingLimited value)? limited, + TResult? Function(VotingAll value)? all, + }) { + return unique?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(VotingDisabled value)? disabled, + TResult Function(VotingUnique value)? unique, + TResult Function(VotingLimited value)? limited, + TResult Function(VotingAll value)? all, + required TResult orElse(), + }) { + if (unique != null) { + return unique(this); + } + return orElse(); } } +abstract class VotingUnique implements PollVotingMode { + const factory VotingUnique() = _$VotingUniqueImpl; +} + /// @nodoc -abstract mixin class $VotingLimitedCopyWith<$Res> - implements $PollVotingModeCopyWith<$Res> { - factory $VotingLimitedCopyWith( - VotingLimited value, $Res Function(VotingLimited) _then) = - _$VotingLimitedCopyWithImpl; +abstract class _$$VotingLimitedImplCopyWith<$Res> { + factory _$$VotingLimitedImplCopyWith( + _$VotingLimitedImpl value, $Res Function(_$VotingLimitedImpl) then) = + __$$VotingLimitedImplCopyWithImpl<$Res>; @useResult $Res call({int count}); } /// @nodoc -class _$VotingLimitedCopyWithImpl<$Res> - implements $VotingLimitedCopyWith<$Res> { - _$VotingLimitedCopyWithImpl(this._self, this._then); - - final VotingLimited _self; - final $Res Function(VotingLimited) _then; +class __$$VotingLimitedImplCopyWithImpl<$Res> + extends _$PollVotingModeCopyWithImpl<$Res, _$VotingLimitedImpl> + implements _$$VotingLimitedImplCopyWith<$Res> { + __$$VotingLimitedImplCopyWithImpl( + _$VotingLimitedImpl _value, $Res Function(_$VotingLimitedImpl) _then) + : super(_value, _then); /// Create a copy of PollVotingMode /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') + @override $Res call({ Object? count = null, }) { - return _then(VotingLimited( + return _then(_$VotingLimitedImpl( count: null == count - ? _self.count + ? _value.count : count // ignore: cast_nullable_to_non_nullable as int, )); @@ -141,22 +358,236 @@ class _$VotingLimitedCopyWithImpl<$Res> /// @nodoc -class VotingAll implements PollVotingMode { - const VotingAll(); +class _$VotingLimitedImpl implements VotingLimited { + const _$VotingLimitedImpl({required this.count}); + + @override + final int count; + + @override + String toString() { + return 'PollVotingMode.limited(count: $count)'; + } @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is VotingAll); + (other.runtimeType == runtimeType && + other is _$VotingLimitedImpl && + (identical(other.count, count) || other.count == count)); } @override - int get hashCode => runtimeType.hashCode; + int get hashCode => Object.hash(runtimeType, count); + + /// Create a copy of PollVotingMode + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$VotingLimitedImplCopyWith<_$VotingLimitedImpl> get copyWith => + __$$VotingLimitedImplCopyWithImpl<_$VotingLimitedImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() disabled, + required TResult Function() unique, + required TResult Function(int count) limited, + required TResult Function() all, + }) { + return limited(count); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? disabled, + TResult? Function()? unique, + TResult? Function(int count)? limited, + TResult? Function()? all, + }) { + return limited?.call(count); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? disabled, + TResult Function()? unique, + TResult Function(int count)? limited, + TResult Function()? all, + required TResult orElse(), + }) { + if (limited != null) { + return limited(count); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(VotingDisabled value) disabled, + required TResult Function(VotingUnique value) unique, + required TResult Function(VotingLimited value) limited, + required TResult Function(VotingAll value) all, + }) { + return limited(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(VotingDisabled value)? disabled, + TResult? Function(VotingUnique value)? unique, + TResult? Function(VotingLimited value)? limited, + TResult? Function(VotingAll value)? all, + }) { + return limited?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(VotingDisabled value)? disabled, + TResult Function(VotingUnique value)? unique, + TResult Function(VotingLimited value)? limited, + TResult Function(VotingAll value)? all, + required TResult orElse(), + }) { + if (limited != null) { + return limited(this); + } + return orElse(); + } +} + +abstract class VotingLimited implements PollVotingMode { + const factory VotingLimited({required final int count}) = _$VotingLimitedImpl; + + int get count; + + /// Create a copy of PollVotingMode + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$VotingLimitedImplCopyWith<_$VotingLimitedImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$VotingAllImplCopyWith<$Res> { + factory _$$VotingAllImplCopyWith( + _$VotingAllImpl value, $Res Function(_$VotingAllImpl) then) = + __$$VotingAllImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$VotingAllImplCopyWithImpl<$Res> + extends _$PollVotingModeCopyWithImpl<$Res, _$VotingAllImpl> + implements _$$VotingAllImplCopyWith<$Res> { + __$$VotingAllImplCopyWithImpl( + _$VotingAllImpl _value, $Res Function(_$VotingAllImpl) _then) + : super(_value, _then); + + /// Create a copy of PollVotingMode + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$VotingAllImpl implements VotingAll { + const _$VotingAllImpl(); @override String toString() { return 'PollVotingMode.all()'; } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$VotingAllImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() disabled, + required TResult Function() unique, + required TResult Function(int count) limited, + required TResult Function() all, + }) { + return all(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? disabled, + TResult? Function()? unique, + TResult? Function(int count)? limited, + TResult? Function()? all, + }) { + return all?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? disabled, + TResult Function()? unique, + TResult Function(int count)? limited, + TResult Function()? all, + required TResult orElse(), + }) { + if (all != null) { + return all(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(VotingDisabled value) disabled, + required TResult Function(VotingUnique value) unique, + required TResult Function(VotingLimited value) limited, + required TResult Function(VotingAll value) all, + }) { + return all(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(VotingDisabled value)? disabled, + TResult? Function(VotingUnique value)? unique, + TResult? Function(VotingLimited value)? limited, + TResult? Function(VotingAll value)? all, + }) { + return all?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(VotingDisabled value)? disabled, + TResult Function(VotingUnique value)? unique, + TResult Function(VotingLimited value)? limited, + TResult Function(VotingAll value)? all, + required TResult orElse(), + }) { + if (all != null) { + return all(this); + } + return orElse(); + } } -// dart format on +abstract class VotingAll implements PollVotingMode { + const factory VotingAll() = _$VotingAllImpl; +} diff --git a/packages/stream_chat/lib/src/core/models/reaction_group.dart b/packages/stream_chat/lib/src/core/models/reaction_group.dart new file mode 100644 index 0000000000..4410500acf --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/reaction_group.dart @@ -0,0 +1,59 @@ +import 'package:equatable/equatable.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'reaction_group.g.dart'; + +/// A model class representing a reaction group. +@JsonSerializable() +class ReactionGroup extends Equatable { + /// Create a new instance of [ReactionGroup]. + ReactionGroup({ + this.count = 0, + this.sumScores = 0, + DateTime? firstReactionAt, + DateTime? lastReactionAt, + }) : firstReactionAt = firstReactionAt ?? DateTime.timestamp(), + lastReactionAt = lastReactionAt ?? DateTime.timestamp(); + + /// Create a new instance from a json + factory ReactionGroup.fromJson(Map json) => + _$ReactionGroupFromJson(json); + + /// The number of users that reacted with this reaction. + final int count; + + /// The sum of scores of all reactions in this group. + final int sumScores; + + /// The date of the first reaction in this group. + final DateTime firstReactionAt; + + /// The date of the last reaction in this group. + final DateTime lastReactionAt; + + /// Serialize to json + Map toJson() => _$ReactionGroupToJson(this); + + /// Creates a copy of [Reaction] with specified attributes overridden. + ReactionGroup copyWith({ + int? count, + int? sumScores, + DateTime? firstReactionAt, + DateTime? lastReactionAt, + }) { + return ReactionGroup( + count: count ?? this.count, + sumScores: sumScores ?? this.sumScores, + firstReactionAt: firstReactionAt ?? this.firstReactionAt, + lastReactionAt: lastReactionAt ?? this.lastReactionAt, + ); + } + + @override + List get props => [ + count, + sumScores, + firstReactionAt, + lastReactionAt, + ]; +} diff --git a/packages/stream_chat/lib/src/core/models/reaction_group.g.dart b/packages/stream_chat/lib/src/core/models/reaction_group.g.dart new file mode 100644 index 0000000000..65e1ceedd7 --- /dev/null +++ b/packages/stream_chat/lib/src/core/models/reaction_group.g.dart @@ -0,0 +1,27 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'reaction_group.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ReactionGroup _$ReactionGroupFromJson(Map json) => + ReactionGroup( + count: (json['count'] as num?)?.toInt() ?? 0, + sumScores: (json['sum_scores'] as num?)?.toInt() ?? 0, + firstReactionAt: json['first_reaction_at'] == null + ? null + : DateTime.parse(json['first_reaction_at'] as String), + lastReactionAt: json['last_reaction_at'] == null + ? null + : DateTime.parse(json['last_reaction_at'] as String), + ); + +Map _$ReactionGroupToJson(ReactionGroup instance) => + { + 'count': instance.count, + 'sum_scores': instance.sumScores, + 'first_reaction_at': instance.firstReactionAt.toIso8601String(), + 'last_reaction_at': instance.lastReactionAt.toIso8601String(), + }; diff --git a/packages/stream_chat/lib/stream_chat.dart b/packages/stream_chat/lib/stream_chat.dart index e1cbd3da0a..426842bea3 100644 --- a/packages/stream_chat/lib/stream_chat.dart +++ b/packages/stream_chat/lib/stream_chat.dart @@ -53,6 +53,7 @@ export 'src/core/models/poll_option.dart'; export 'src/core/models/poll_vote.dart'; export 'src/core/models/poll_voting_mode.dart'; export 'src/core/models/reaction.dart'; +export 'src/core/models/reaction_group.dart'; export 'src/core/models/read.dart'; export 'src/core/models/thread.dart'; export 'src/core/models/thread_participant.dart'; diff --git a/packages/stream_chat/test/src/client/channel_test.dart b/packages/stream_chat/test/src/client/channel_test.dart index 84de97ed71..7e9e330bc1 100644 --- a/packages/stream_chat/test/src/client/channel_test.dart +++ b/packages/stream_chat/test/src/client/channel_test.dart @@ -1319,8 +1319,7 @@ void main() { isSameMessageAs( message.copyWith( state: MessageState.sent, - reactionCounts: {type: 1}, - reactionScores: {type: 1}, + reactionGroups: {type: ReactionGroup(count: 1, sumScores: 1)}, latestReactions: [reaction], ownReactions: [reaction], ), @@ -1372,8 +1371,12 @@ void main() { isSameMessageAs( message.copyWith( state: MessageState.sent, - reactionCounts: {type: 1}, - reactionScores: {type: score}, + reactionGroups: { + type: ReactionGroup( + count: 1, + sumScores: score, + ) + }, latestReactions: [reaction], ownReactions: [reaction], ), @@ -1440,8 +1443,12 @@ void main() { isSameMessageAs( message.copyWith( state: MessageState.sent, - reactionCounts: {type: 1}, - reactionScores: {type: extraDataScore}, + reactionGroups: { + type: ReactionGroup( + count: 1, + sumScores: extraDataScore, + ) + }, latestReactions: [reaction], ownReactions: [reaction], ), @@ -1497,8 +1504,12 @@ void main() { isSameMessageAs( message.copyWith( state: MessageState.sent, - reactionCounts: {type: 1}, - reactionScores: {type: 1}, + reactionGroups: { + type: ReactionGroup( + count: 1, + sumScores: 1, + ) + }, latestReactions: [reaction], ownReactions: [reaction], ), @@ -1541,8 +1552,12 @@ void main() { id: messageId, ownReactions: [prevReaction], latestReactions: [prevReaction], - reactionScores: const {prevType: 1}, - reactionCounts: const {prevType: 1}, + reactionGroups: { + prevType: ReactionGroup( + count: 1, + sumScores: 1, + ) + }, state: MessageState.sent, ); @@ -1629,8 +1644,12 @@ void main() { isSameMessageAs( message.copyWith( state: MessageState.sent, - reactionCounts: {type: 1}, - reactionScores: {type: 1}, + reactionGroups: { + type: ReactionGroup( + count: 1, + sumScores: 1, + ) + }, latestReactions: [reaction], ownReactions: [reaction], ), @@ -1676,8 +1695,12 @@ void main() { isSameMessageAs( message.copyWith( state: MessageState.sent, - reactionCounts: {type: 1}, - reactionScores: {type: 1}, + reactionGroups: { + type: ReactionGroup( + count: 1, + sumScores: 1, + ) + }, latestReactions: [reaction], ownReactions: [reaction], ), @@ -1724,8 +1747,12 @@ void main() { parentId: parentId, ownReactions: [prevReaction], latestReactions: [prevReaction], - reactionScores: const {prevType: 1}, - reactionCounts: const {prevType: 1}, + reactionGroups: { + prevType: ReactionGroup( + count: 1, + sumScores: 1, + ) + }, state: MessageState.sent, ); @@ -1802,8 +1829,12 @@ void main() { id: messageId, ownReactions: [reaction], latestReactions: [reaction], - reactionScores: const {type: 1}, - reactionCounts: const {type: 1}, + reactionGroups: { + type: ReactionGroup( + count: 1, + sumScores: 1, + ) + }, state: MessageState.sent, ); @@ -1850,8 +1881,12 @@ void main() { id: messageId, ownReactions: [reaction], latestReactions: [reaction], - reactionScores: const {type: 1}, - reactionCounts: const {type: 1}, + reactionGroups: { + type: ReactionGroup( + count: 1, + sumScores: 1, + ) + }, state: MessageState.sent, ); @@ -1911,8 +1946,12 @@ void main() { // is thread ownReactions: [reaction], latestReactions: [reaction], - reactionScores: const {type: 1}, - reactionCounts: const {type: 1}, + reactionGroups: { + type: ReactionGroup( + count: 1, + sumScores: 1, + ) + }, state: MessageState.sent, ); @@ -1964,8 +2003,12 @@ void main() { parentId: parentId, ownReactions: [reaction], latestReactions: [reaction], - reactionScores: const {type: 1}, - reactionCounts: const {type: 1}, + reactionGroups: { + type: ReactionGroup( + count: 1, + sumScores: 1, + ) + }, state: MessageState.sent, ); diff --git a/packages/stream_chat/test/src/core/models/message_reaction_helper_test.dart b/packages/stream_chat/test/src/core/models/message_reaction_helper_test.dart new file mode 100644 index 0000000000..f24748ea73 --- /dev/null +++ b/packages/stream_chat/test/src/core/models/message_reaction_helper_test.dart @@ -0,0 +1,369 @@ +// ignore_for_file: avoid_redundant_argument_values + +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/reaction_group.dart'; +import 'package:stream_chat/src/core/models/user.dart'; +import 'package:test/test.dart'; + +void main() { + group('MessageReactionHelper', () { + late User testUser; + late Message emptyMessage; + late Reaction testReaction; + + setUp(() { + testUser = User(id: 'test-user-id'); + emptyMessage = Message(id: 'test-message-id'); + testReaction = Reaction( + type: 'like', + score: 1, + user: testUser, + userId: testUser.id, + messageId: emptyMessage.id, + ); + }); + + group('addMyReaction', () { + test('should add reaction to a message without reactions', () { + final updatedMessage = emptyMessage.addMyReaction(testReaction); + + // Verify own reactions + expect(updatedMessage.ownReactions, isNotNull); + expect(updatedMessage.ownReactions!.length, 1); + expect(updatedMessage.ownReactions!.first.type, 'like'); + expect(updatedMessage.ownReactions!.first.userId, testUser.id); + + // Verify latest reactions + expect(updatedMessage.latestReactions, isNotNull); + expect(updatedMessage.latestReactions!.length, 1); + expect(updatedMessage.latestReactions!.first.type, 'like'); + expect(updatedMessage.latestReactions!.first.userId, testUser.id); + + // Verify reaction groups + expect(updatedMessage.reactionGroups, isNotNull); + expect(updatedMessage.reactionGroups!.containsKey('like'), isTrue); + expect(updatedMessage.reactionGroups!['like']!.count, 1); + expect(updatedMessage.reactionGroups!['like']!.sumScores, 1); + expect(updatedMessage.reactionGroups!['like']!.firstReactionAt, + testReaction.createdAt); + expect(updatedMessage.reactionGroups!['like']!.lastReactionAt, + testReaction.createdAt); + }); + + test('should add reaction to a message with existing reactions', () { + // Create a message with existing reactions + final otherUser = User(id: 'other-user-id'); + final otherReaction = Reaction( + type: 'love', + score: 1, + user: otherUser, + userId: otherUser.id, + messageId: emptyMessage.id, + ); + + final existingReactions = [otherReaction]; + final existingGroups = { + 'love': ReactionGroup( + count: 1, + sumScores: 1, + firstReactionAt: otherReaction.createdAt, + lastReactionAt: otherReaction.createdAt, + ), + }; + + final messageWithReactions = emptyMessage.copyWith( + ownReactions: [], + latestReactions: existingReactions, + reactionGroups: existingGroups, + ); + + // Add new reaction + final updatedMessage = messageWithReactions.addMyReaction(testReaction); + + // Verify own reactions + expect(updatedMessage.ownReactions, isNotNull); + expect(updatedMessage.ownReactions!.length, 1); + expect(updatedMessage.ownReactions!.first.type, 'like'); + + // Verify latest reactions + expect(updatedMessage.latestReactions, isNotNull); + expect(updatedMessage.latestReactions!.length, 2); + expect(updatedMessage.latestReactions!.first.type, 'like'); + expect(updatedMessage.latestReactions!.last.type, 'love'); + + // Verify reaction groups + expect(updatedMessage.reactionGroups, isNotNull); + expect(updatedMessage.reactionGroups!.length, 2); + expect(updatedMessage.reactionGroups!.containsKey('like'), isTrue); + expect(updatedMessage.reactionGroups!.containsKey('love'), isTrue); + expect(updatedMessage.reactionGroups!['like']!.count, 1); + expect(updatedMessage.reactionGroups!['love']!.count, 1); + }); + + test('should replace existing reaction when enforceUnique is true', () { + // First add a reaction + final messageWithReaction = emptyMessage.addMyReaction(testReaction); + + // Then add a different reaction with enforceUnique + final newReaction = Reaction( + type: 'love', + score: 1, + user: testUser, + userId: testUser.id, + messageId: emptyMessage.id, + ); + + final updatedMessage = messageWithReaction.addMyReaction( + newReaction, + enforceUnique: true, + ); + + // Should only have the love reaction, not the like reaction + expect(updatedMessage.ownReactions, isNotNull); + expect(updatedMessage.ownReactions!.length, 1); + expect(updatedMessage.ownReactions!.first.type, 'love'); + + // Verify reaction groups + expect(updatedMessage.reactionGroups!.containsKey('like'), isFalse); + expect(updatedMessage.reactionGroups!.containsKey('love'), isTrue); + }); + + test('should keep existing reaction when enforceUnique is false', () { + // First add a reaction + final messageWithReaction = emptyMessage.addMyReaction(testReaction); + + // Then add a different reaction without enforceUnique + final newReaction = Reaction( + type: 'love', + score: 1, + user: testUser, + userId: testUser.id, + messageId: emptyMessage.id, + ); + + final updatedMessage = messageWithReaction.addMyReaction( + newReaction, + enforceUnique: false, + ); + + // Should have both reactions + expect(updatedMessage.ownReactions, isNotNull); + expect(updatedMessage.ownReactions!.length, 2); + + final reactionTypes = + updatedMessage.ownReactions!.map((r) => r.type).toList(); + expect(reactionTypes, contains('like')); + expect(reactionTypes, contains('love')); + + // Verify reaction groups + expect(updatedMessage.reactionGroups!.containsKey('like'), isTrue); + expect(updatedMessage.reactionGroups!.containsKey('love'), isTrue); + }); + + test('should update existing reaction group with same type', () { + // First add a reaction + final messageWithReaction = emptyMessage.addMyReaction(testReaction); + + // Another user adds same reaction type + final otherUser = User(id: 'other-user-id'); + final otherReaction = Reaction( + type: 'like', + score: 2, + user: otherUser, + userId: otherUser.id, + messageId: emptyMessage.id, + ); + + final updatedMessage = messageWithReaction.addMyReaction(otherReaction); + + // Verify reaction group count and scores are updated + expect(updatedMessage.reactionGroups!['like']!.count, 2); + expect(updatedMessage.reactionGroups!['like']!.sumScores, 3); // 1 + 2 + }); + }); + + group('deleteMyReaction', () { + test('should handle message with no reactions', () { + final updatedMessage = emptyMessage.deleteMyReaction(); + expect(updatedMessage, emptyMessage); + }); + + test('should delete all reactions from current user', () { + // Setup a message with multiple reactions from test user + final reaction1 = Reaction( + type: 'like', + score: 1, + user: testUser, + userId: testUser.id, + messageId: emptyMessage.id, + ); + + final reaction2 = Reaction( + type: 'love', + score: 1, + user: testUser, + userId: testUser.id, + messageId: emptyMessage.id, + ); + + // Add reactions from the test user + final messageWithReactions = emptyMessage.copyWith( + ownReactions: [reaction1, reaction2], + latestReactions: [reaction1, reaction2], + reactionGroups: { + 'like': ReactionGroup( + count: 1, + sumScores: 1, + firstReactionAt: reaction1.createdAt, + lastReactionAt: reaction1.createdAt, + ), + 'love': ReactionGroup( + count: 1, + sumScores: 1, + firstReactionAt: reaction2.createdAt, + lastReactionAt: reaction2.createdAt, + ), + }, + ); + + // Delete all reactions + final updatedMessage = messageWithReactions.deleteMyReaction(); + + expect(updatedMessage.ownReactions, isEmpty); + expect(updatedMessage.latestReactions, isEmpty); + expect(updatedMessage.reactionGroups, isEmpty); + }); + + test('should delete only specified reaction type', () { + // Setup a message with multiple reactions from test user + final reaction1 = Reaction( + type: 'like', + score: 1, + user: testUser, + userId: testUser.id, + messageId: emptyMessage.id, + ); + + final reaction2 = Reaction( + type: 'love', + score: 1, + user: testUser, + userId: testUser.id, + messageId: emptyMessage.id, + ); + + // Add reactions from the test user + final messageWithReactions = emptyMessage.copyWith( + ownReactions: [reaction1, reaction2], + latestReactions: [reaction1, reaction2], + reactionGroups: { + 'like': ReactionGroup( + count: 1, + sumScores: 1, + firstReactionAt: reaction1.createdAt, + lastReactionAt: reaction1.createdAt, + ), + 'love': ReactionGroup( + count: 1, + sumScores: 1, + firstReactionAt: reaction2.createdAt, + lastReactionAt: reaction2.createdAt, + ), + }, + ); + + // Delete only the 'like' reaction + final updatedMessage = messageWithReactions.deleteMyReaction( + reactionType: 'like', + ); + + // Should have removed only the 'like' reaction + expect(updatedMessage.ownReactions!.length, 1); + expect(updatedMessage.ownReactions!.first.type, 'love'); + expect(updatedMessage.latestReactions!.length, 1); + expect(updatedMessage.latestReactions!.first.type, 'love'); + expect(updatedMessage.reactionGroups!.length, 1); + expect(updatedMessage.reactionGroups!.containsKey('love'), isTrue); + expect(updatedMessage.reactionGroups!.containsKey('like'), isFalse); + }); + + test('should preserve other users reactions when deleting', () { + // Setup test user reaction + final reaction1 = Reaction( + type: 'like', + score: 1, + user: testUser, + userId: testUser.id, + messageId: emptyMessage.id, + ); + + // Setup other user reaction + final otherUser = User(id: 'other-user-id'); + final otherReaction = Reaction( + type: 'like', + score: 1, + user: otherUser, + userId: otherUser.id, + messageId: emptyMessage.id, + ); + + // Add reactions from both users + final messageWithReactions = emptyMessage.copyWith( + ownReactions: [reaction1], + latestReactions: [reaction1, otherReaction], + reactionGroups: { + 'like': ReactionGroup( + count: 2, + sumScores: 2, + firstReactionAt: reaction1.createdAt, + lastReactionAt: otherReaction.createdAt, + ), + }, + ); + + // Delete test user reaction + final updatedMessage = messageWithReactions.deleteMyReaction(); + + // Should have removed only the test user's reaction + expect(updatedMessage.ownReactions, isEmpty); + expect(updatedMessage.latestReactions!.length, 1); + expect(updatedMessage.latestReactions!.first.userId, otherUser.id); + expect(updatedMessage.reactionGroups!.length, 1); + expect(updatedMessage.reactionGroups!['like']!.count, 1); + expect(updatedMessage.reactionGroups!['like']!.sumScores, 1); + }); + + test('should update reaction group counts when deleting reaction', () { + // Setup a message with reactions from multiple users + final reaction1 = Reaction( + type: 'like', + score: 3, // Higher score + user: testUser, + userId: testUser.id, + messageId: emptyMessage.id, + ); + + // Add reactions + final messageWithReactions = emptyMessage.copyWith( + ownReactions: [reaction1], + latestReactions: [reaction1], + reactionGroups: { + 'like': ReactionGroup( + count: 1, + sumScores: 3, + firstReactionAt: reaction1.createdAt, + lastReactionAt: reaction1.createdAt, + ), + }, + ); + + // Delete reaction + final updatedMessage = messageWithReactions.deleteMyReaction(); + + // Should have updated the reaction group counts + expect(updatedMessage.reactionGroups, isEmpty); + }); + }); + }); +} diff --git a/packages/stream_chat/test/src/core/models/message_test.dart b/packages/stream_chat/test/src/core/models/message_test.dart index 6d1d0644f0..8365d7fdce 100644 --- a/packages/stream_chat/test/src/core/models/message_test.dart +++ b/packages/stream_chat/test/src/core/models/message_test.dart @@ -1,9 +1,10 @@ -// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_redundant_argument_values, lines_longer_than_80_chars import 'package:stream_chat/src/core/models/attachment.dart'; import 'package:stream_chat/src/core/models/message.dart'; import 'package:stream_chat/src/core/models/moderation.dart'; import 'package:stream_chat/src/core/models/reaction.dart'; +import 'package:stream_chat/src/core/models/reaction_group.dart'; import 'package:stream_chat/src/core/models/user.dart'; import 'package:test/test.dart'; @@ -22,8 +23,11 @@ void main() { expect(message.attachments, isA>()); expect(message.latestReactions, isA>()); expect(message.ownReactions, isA>()); + // ignore: deprecated_member_use_from_same_package expect(message.reactionCounts, {'love': 1}); + // ignore: deprecated_member_use_from_same_package expect(message.reactionScores, {'love': 1}); + expect(message.reactionGroups, isA>()); expect(message.createdAt, DateTime.parse('2020-01-28T22:17:31.107978Z')); expect(message.updatedAt, DateTime.parse('2020-01-28T22:17:31.130506Z')); expect(message.mentionedUsers, isA>()); @@ -255,6 +259,54 @@ void main() { expect(field2.compareTo(field1), lessThan(0)); // 1 < 10 }); }); + + group('reactionGroups', () { + final reactionGroupLike = ReactionGroup( + count: 1, + sumScores: 1, + firstReactionAt: DateTime.now(), + lastReactionAt: DateTime.now(), + ); + + final reactionGroupLove = ReactionGroup( + count: 2, + sumScores: 5, + firstReactionAt: DateTime.now(), + lastReactionAt: DateTime.now(), + ); + + test('is populated directly if provided in constructor', () { + final message = Message( + reactionGroups: { + 'like': reactionGroupLike, + 'love': reactionGroupLove, + }, + ); + + expect(message.reactionGroups, isNotNull); + expect(message.reactionGroups!['like'], reactionGroupLike); + expect(message.reactionGroups!['love'], reactionGroupLove); + }); + + test( + 'is derived from reactionCounts and reactionScores if not provided directly in constructor', + () { + final message = Message( + // ignore: deprecated_member_use_from_same_package + reactionCounts: const {'like': 1, 'love': 2}, + // ignore: deprecated_member_use_from_same_package + reactionScores: const {'like': 1, 'love': 5}, + ); + + expect(message.reactionGroups, isNotNull); + expect(message.reactionGroups!.length, 2); + expect(message.reactionGroups!['like']!.count, 1); + expect(message.reactionGroups!['like']!.sumScores, 1); + expect(message.reactionGroups!['love']!.count, 2); + expect(message.reactionGroups!['love']!.sumScores, 5); + }, + ); + }); }); group('MessageVisibility Extension Tests', () { diff --git a/packages/stream_chat/test/src/core/models/reaction_group_test.dart b/packages/stream_chat/test/src/core/models/reaction_group_test.dart new file mode 100644 index 0000000000..602ba6ee41 --- /dev/null +++ b/packages/stream_chat/test/src/core/models/reaction_group_test.dart @@ -0,0 +1,126 @@ +import 'package:stream_chat/src/core/models/reaction_group.dart'; +import 'package:test/test.dart'; + +void main() { + group('ReactionGroup', () { + final firstReactionAtDate = DateTime.utc(2023, 10, 26, 10); + final lastReactionAtDate = DateTime.utc(2023, 10, 26, 12); + + const count = 10; + const sumScores = 50; + + test('constructor sets provided values', () { + final reactionGroup = ReactionGroup( + count: count, + sumScores: sumScores, + firstReactionAt: firstReactionAtDate, + lastReactionAt: lastReactionAtDate, + ); + expect(reactionGroup.count, count); + expect(reactionGroup.sumScores, sumScores); + expect(reactionGroup.firstReactionAt, firstReactionAtDate); + expect(reactionGroup.lastReactionAt, lastReactionAtDate); + }); + + test('fromJson creates correct object', () { + final json = { + 'count': count, + 'sum_scores': sumScores, + 'first_reaction_at': firstReactionAtDate.toIso8601String(), + 'last_reaction_at': lastReactionAtDate.toIso8601String(), + }; + final reactionGroup = ReactionGroup.fromJson(json); + expect(reactionGroup.count, count); + expect(reactionGroup.sumScores, sumScores); + expect(reactionGroup.firstReactionAt, firstReactionAtDate); + expect(reactionGroup.lastReactionAt, lastReactionAtDate); + }); + + test('copyWith creates a new object with updated values', () { + final reactionGroup = ReactionGroup( + count: count, + sumScores: sumScores, + firstReactionAt: firstReactionAtDate, + lastReactionAt: lastReactionAtDate, + ); + + final copiedGroup = reactionGroup.copyWith( + count: 20, + sumScores: 100, + ); + + expect(copiedGroup.count, 20); + expect(copiedGroup.sumScores, 100); + expect(copiedGroup.firstReactionAt, firstReactionAtDate); + expect(copiedGroup.lastReactionAt, lastReactionAtDate); + + final newFirstAt = DateTime.utc(2023, 11); + final newLastAt = DateTime.utc(2023, 11, 2); + final copiedGroup2 = reactionGroup.copyWith( + firstReactionAt: newFirstAt, + lastReactionAt: newLastAt, + ); + expect(copiedGroup2.count, count); + expect(copiedGroup2.sumScores, sumScores); + expect(copiedGroup2.firstReactionAt, newFirstAt); + expect(copiedGroup2.lastReactionAt, newLastAt); + }); + + test('copyWith uses existing values if not provided', () { + final reactionGroup = ReactionGroup( + count: count, + sumScores: sumScores, + firstReactionAt: firstReactionAtDate, + lastReactionAt: lastReactionAtDate, + ); + + final copiedGroup = reactionGroup.copyWith(); + + expect(copiedGroup.count, count); + expect(copiedGroup.sumScores, sumScores); + expect(copiedGroup.firstReactionAt, firstReactionAtDate); + expect(copiedGroup.lastReactionAt, lastReactionAtDate); + }); + + test('props returns correct list of properties', () { + final reactionGroup = ReactionGroup( + count: count, + sumScores: sumScores, + firstReactionAt: firstReactionAtDate, + lastReactionAt: lastReactionAtDate, + ); + expect(reactionGroup.props, [ + count, + sumScores, + firstReactionAtDate, + lastReactionAtDate, + ]); + }); + + test('equality works correctly', () { + final reactionGroup1 = ReactionGroup( + count: count, + sumScores: sumScores, + firstReactionAt: firstReactionAtDate, + lastReactionAt: lastReactionAtDate, + ); + final reactionGroup2 = ReactionGroup( + count: count, + sumScores: sumScores, + firstReactionAt: firstReactionAtDate, + lastReactionAt: lastReactionAtDate, + ); + final reactionGroup3 = ReactionGroup( + count: count + 1, // different count + sumScores: sumScores, + firstReactionAt: firstReactionAtDate, + lastReactionAt: lastReactionAtDate, + ); + final reactionGroup4 = ReactionGroup(); + + expect(reactionGroup1 == reactionGroup2, isTrue); + expect(reactionGroup1 == reactionGroup3, isFalse); + expect(reactionGroup1 == reactionGroup4, isFalse); + }); + }); +} diff --git a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart index 220a32c232..b8ac368678 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart @@ -637,7 +637,7 @@ class _StreamMessageWidgetState extends State /// {@endtemplate} bool get shouldShowReactions => widget.showReactions && - (widget.message.reactionCounts?.isNotEmpty == true) && + (widget.message.latestReactions?.isNotEmpty == true) && !widget.message.isDeleted; bool get shouldShowReplyAction => diff --git a/packages/stream_chat_persistence/CHANGELOG.md b/packages/stream_chat_persistence/CHANGELOG.md index 9c4aed4f44..14209dde56 100644 --- a/packages/stream_chat_persistence/CHANGELOG.md +++ b/packages/stream_chat_persistence/CHANGELOG.md @@ -1,3 +1,7 @@ +## Upcoming + +- Added support for `Message.reactionGroups` field. + ## 9.10.0 - Fixed an issue in the `getChannelStates` method where `paginationParams.offset` greater than the diff --git a/packages/stream_chat_persistence/lib/src/converter/converter.dart b/packages/stream_chat_persistence/lib/src/converter/converter.dart index 8608b30fde..bf8115e4b5 100644 --- a/packages/stream_chat_persistence/lib/src/converter/converter.dart +++ b/packages/stream_chat_persistence/lib/src/converter/converter.dart @@ -1,3 +1,4 @@ export 'list_converter.dart'; export 'map_converter.dart'; +export 'reaction_groups_converter.dart'; export 'voting_visibility_converter.dart'; diff --git a/packages/stream_chat_persistence/lib/src/converter/reaction_groups_converter.dart b/packages/stream_chat_persistence/lib/src/converter/reaction_groups_converter.dart new file mode 100644 index 0000000000..c3b1611689 --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/converter/reaction_groups_converter.dart @@ -0,0 +1,28 @@ +import 'dart:convert'; + +import 'package:drift/drift.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/converter/converter.dart'; + +/// A [TypeConverter] that serializes [VotingVisibility] to a [String] column. +class ReactionGroupsConverter extends MapConverter { + @override + Map fromSql(String fromDb) { + final json = jsonDecode(fromDb) as Map; + return json.map( + (key, e) { + final group = ReactionGroup.fromJson(e as Map); + return MapEntry(key, group); + }, + ); + } + + @override + String toSql(Map value) { + return jsonEncode( + value.map( + (k, e) => MapEntry(k, e.toJson()), + ), + ); + } +} diff --git a/packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart b/packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart index 57b58c0290..c1aa217973 100644 --- a/packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart +++ b/packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart @@ -1,5 +1,5 @@ import 'package:drift/drift.dart'; -import 'package:stream_chat/stream_chat.dart' show VotingVisibility; +import 'package:stream_chat/stream_chat.dart'; import 'package:stream_chat_persistence/src/converter/converter.dart'; import 'package:stream_chat_persistence/src/dao/dao.dart'; import 'package:stream_chat_persistence/src/entity/entity.dart'; @@ -55,20 +55,19 @@ class DriftChatDatabase extends _$DriftChatDatabase { // you should bump this number whenever you change or add a table definition. @override - int get schemaVersion => 20; + int get schemaVersion => 21; @override MigrationStrategy get migration => MigrationStrategy( beforeOpen: (details) async { await customStatement('PRAGMA foreign_keys = ON'); }, - onUpgrade: (openingDetails, before, after) async { - if (before != after) { - final m = createMigrator(); + onUpgrade: (migrator, from, to) async { + if (from != to) { for (final table in allTables) { - await m.deleteTable(table.actualTableName); - await m.createTable(table); + await migrator.deleteTable(table.actualTableName); } + await migrator.createAll(); } }, ); diff --git a/packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart b/packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart index 837ad32e91..62b81b61e0 100644 --- a/packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart +++ b/packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart @@ -697,19 +697,12 @@ class $MessagesTable extends Messages type: DriftSqlType.string, requiredDuringInsert: true) .withConverter>($MessagesTable.$convertermentionedUsers); @override - late final GeneratedColumnWithTypeConverter?, String> - reactionCounts = GeneratedColumn( - 'reaction_counts', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false) - .withConverter?>( - $MessagesTable.$converterreactionCountsn); - @override - late final GeneratedColumnWithTypeConverter?, String> - reactionScores = GeneratedColumn( - 'reaction_scores', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false) - .withConverter?>( - $MessagesTable.$converterreactionScoresn); + late final GeneratedColumnWithTypeConverter?, + String> reactionGroups = GeneratedColumn( + 'reaction_groups', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false) + .withConverter?>( + $MessagesTable.$converterreactionGroupsn); static const VerificationMeta _parentIdMeta = const VerificationMeta('parentId'); @override @@ -873,8 +866,7 @@ class $MessagesTable extends Messages state, type, mentionedUsers, - reactionCounts, - reactionScores, + reactionGroups, parentId, quotedMessageId, pollId, @@ -1068,12 +1060,9 @@ class $MessagesTable extends Messages mentionedUsers: $MessagesTable.$convertermentionedUsers.fromSql( attachedDatabase.typeMapping.read( DriftSqlType.string, data['${effectivePrefix}mentioned_users'])!), - reactionCounts: $MessagesTable.$converterreactionCountsn.fromSql( - attachedDatabase.typeMapping.read( - DriftSqlType.string, data['${effectivePrefix}reaction_counts'])), - reactionScores: $MessagesTable.$converterreactionScoresn.fromSql( + reactionGroups: $MessagesTable.$converterreactionGroupsn.fromSql( attachedDatabase.typeMapping.read( - DriftSqlType.string, data['${effectivePrefix}reaction_scores'])), + DriftSqlType.string, data['${effectivePrefix}reaction_groups'])), parentId: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}parent_id']), quotedMessageId: attachedDatabase.typeMapping.read( @@ -1137,14 +1126,11 @@ class $MessagesTable extends Messages ListConverter(); static TypeConverter, String> $convertermentionedUsers = ListConverter(); - static TypeConverter, String> $converterreactionCounts = - MapConverter(); - static TypeConverter?, String?> $converterreactionCountsn = - NullAwareTypeConverter.wrap($converterreactionCounts); - static TypeConverter, String> $converterreactionScores = - MapConverter(); - static TypeConverter?, String?> $converterreactionScoresn = - NullAwareTypeConverter.wrap($converterreactionScores); + static TypeConverter, String> + $converterreactionGroups = ReactionGroupsConverter(); + static TypeConverter?, String?> + $converterreactionGroupsn = + NullAwareTypeConverter.wrap($converterreactionGroups); static TypeConverter?, String?> $converteri18n = NullableMapConverter(); static TypeConverter, String> $converterrestrictedVisibility = @@ -1177,11 +1163,8 @@ class MessageEntity extends DataClass implements Insertable { /// The list of user mentioned in the message final List mentionedUsers; - /// A map describing the count of number of every reaction - final Map? reactionCounts; - - /// A map describing the count of score of every reaction - final Map? reactionScores; + /// A map describing the reaction group for every reaction + final Map? reactionGroups; /// The ID of the parent message, if the message is a thread reply. final String? parentId; @@ -1261,8 +1244,7 @@ class MessageEntity extends DataClass implements Insertable { required this.state, required this.type, required this.mentionedUsers, - this.reactionCounts, - this.reactionScores, + this.reactionGroups, this.parentId, this.quotedMessageId, this.pollId, @@ -1304,13 +1286,9 @@ class MessageEntity extends DataClass implements Insertable { map['mentioned_users'] = Variable( $MessagesTable.$convertermentionedUsers.toSql(mentionedUsers)); } - if (!nullToAbsent || reactionCounts != null) { - map['reaction_counts'] = Variable( - $MessagesTable.$converterreactionCountsn.toSql(reactionCounts)); - } - if (!nullToAbsent || reactionScores != null) { - map['reaction_scores'] = Variable( - $MessagesTable.$converterreactionScoresn.toSql(reactionScores)); + if (!nullToAbsent || reactionGroups != null) { + map['reaction_groups'] = Variable( + $MessagesTable.$converterreactionGroupsn.toSql(reactionGroups)); } if (!nullToAbsent || parentId != null) { map['parent_id'] = Variable(parentId); @@ -1394,10 +1372,8 @@ class MessageEntity extends DataClass implements Insertable { state: serializer.fromJson(json['state']), type: serializer.fromJson(json['type']), mentionedUsers: serializer.fromJson>(json['mentionedUsers']), - reactionCounts: - serializer.fromJson?>(json['reactionCounts']), - reactionScores: - serializer.fromJson?>(json['reactionScores']), + reactionGroups: serializer + .fromJson?>(json['reactionGroups']), parentId: serializer.fromJson(json['parentId']), quotedMessageId: serializer.fromJson(json['quotedMessageId']), pollId: serializer.fromJson(json['pollId']), @@ -1436,8 +1412,8 @@ class MessageEntity extends DataClass implements Insertable { 'state': serializer.toJson(state), 'type': serializer.toJson(type), 'mentionedUsers': serializer.toJson>(mentionedUsers), - 'reactionCounts': serializer.toJson?>(reactionCounts), - 'reactionScores': serializer.toJson?>(reactionScores), + 'reactionGroups': + serializer.toJson?>(reactionGroups), 'parentId': serializer.toJson(parentId), 'quotedMessageId': serializer.toJson(quotedMessageId), 'pollId': serializer.toJson(pollId), @@ -1474,8 +1450,8 @@ class MessageEntity extends DataClass implements Insertable { String? state, String? type, List? mentionedUsers, - Value?> reactionCounts = const Value.absent(), - Value?> reactionScores = const Value.absent(), + Value?> reactionGroups = + const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), Value pollId = const Value.absent(), @@ -1507,10 +1483,8 @@ class MessageEntity extends DataClass implements Insertable { state: state ?? this.state, type: type ?? this.type, mentionedUsers: mentionedUsers ?? this.mentionedUsers, - reactionCounts: - reactionCounts.present ? reactionCounts.value : this.reactionCounts, - reactionScores: - reactionScores.present ? reactionScores.value : this.reactionScores, + reactionGroups: + reactionGroups.present ? reactionGroups.value : this.reactionGroups, parentId: parentId.present ? parentId.value : this.parentId, quotedMessageId: quotedMessageId.present ? quotedMessageId.value @@ -1566,12 +1540,9 @@ class MessageEntity extends DataClass implements Insertable { mentionedUsers: data.mentionedUsers.present ? data.mentionedUsers.value : this.mentionedUsers, - reactionCounts: data.reactionCounts.present - ? data.reactionCounts.value - : this.reactionCounts, - reactionScores: data.reactionScores.present - ? data.reactionScores.value - : this.reactionScores, + reactionGroups: data.reactionGroups.present + ? data.reactionGroups.value + : this.reactionGroups, parentId: data.parentId.present ? data.parentId.value : this.parentId, quotedMessageId: data.quotedMessageId.present ? data.quotedMessageId.value @@ -1635,8 +1606,7 @@ class MessageEntity extends DataClass implements Insertable { ..write('state: $state, ') ..write('type: $type, ') ..write('mentionedUsers: $mentionedUsers, ') - ..write('reactionCounts: $reactionCounts, ') - ..write('reactionScores: $reactionScores, ') + ..write('reactionGroups: $reactionGroups, ') ..write('parentId: $parentId, ') ..write('quotedMessageId: $quotedMessageId, ') ..write('pollId: $pollId, ') @@ -1673,8 +1643,7 @@ class MessageEntity extends DataClass implements Insertable { state, type, mentionedUsers, - reactionCounts, - reactionScores, + reactionGroups, parentId, quotedMessageId, pollId, @@ -1710,8 +1679,7 @@ class MessageEntity extends DataClass implements Insertable { other.state == this.state && other.type == this.type && other.mentionedUsers == this.mentionedUsers && - other.reactionCounts == this.reactionCounts && - other.reactionScores == this.reactionScores && + other.reactionGroups == this.reactionGroups && other.parentId == this.parentId && other.quotedMessageId == this.quotedMessageId && other.pollId == this.pollId && @@ -1745,8 +1713,7 @@ class MessagesCompanion extends UpdateCompanion { final Value state; final Value type; final Value> mentionedUsers; - final Value?> reactionCounts; - final Value?> reactionScores; + final Value?> reactionGroups; final Value parentId; final Value quotedMessageId; final Value pollId; @@ -1779,8 +1746,7 @@ class MessagesCompanion extends UpdateCompanion { this.state = const Value.absent(), this.type = const Value.absent(), this.mentionedUsers = const Value.absent(), - this.reactionCounts = const Value.absent(), - this.reactionScores = const Value.absent(), + this.reactionGroups = const Value.absent(), this.parentId = const Value.absent(), this.quotedMessageId = const Value.absent(), this.pollId = const Value.absent(), @@ -1814,8 +1780,7 @@ class MessagesCompanion extends UpdateCompanion { required String state, this.type = const Value.absent(), required List mentionedUsers, - this.reactionCounts = const Value.absent(), - this.reactionScores = const Value.absent(), + this.reactionGroups = const Value.absent(), this.parentId = const Value.absent(), this.quotedMessageId = const Value.absent(), this.pollId = const Value.absent(), @@ -1853,8 +1818,7 @@ class MessagesCompanion extends UpdateCompanion { Expression? state, Expression? type, Expression? mentionedUsers, - Expression? reactionCounts, - Expression? reactionScores, + Expression? reactionGroups, Expression? parentId, Expression? quotedMessageId, Expression? pollId, @@ -1888,8 +1852,7 @@ class MessagesCompanion extends UpdateCompanion { if (state != null) 'state': state, if (type != null) 'type': type, if (mentionedUsers != null) 'mentioned_users': mentionedUsers, - if (reactionCounts != null) 'reaction_counts': reactionCounts, - if (reactionScores != null) 'reaction_scores': reactionScores, + if (reactionGroups != null) 'reaction_groups': reactionGroups, if (parentId != null) 'parent_id': parentId, if (quotedMessageId != null) 'quoted_message_id': quotedMessageId, if (pollId != null) 'poll_id': pollId, @@ -1927,8 +1890,7 @@ class MessagesCompanion extends UpdateCompanion { Value? state, Value? type, Value>? mentionedUsers, - Value?>? reactionCounts, - Value?>? reactionScores, + Value?>? reactionGroups, Value? parentId, Value? quotedMessageId, Value? pollId, @@ -1961,8 +1923,7 @@ class MessagesCompanion extends UpdateCompanion { state: state ?? this.state, type: type ?? this.type, mentionedUsers: mentionedUsers ?? this.mentionedUsers, - reactionCounts: reactionCounts ?? this.reactionCounts, - reactionScores: reactionScores ?? this.reactionScores, + reactionGroups: reactionGroups ?? this.reactionGroups, parentId: parentId ?? this.parentId, quotedMessageId: quotedMessageId ?? this.quotedMessageId, pollId: pollId ?? this.pollId, @@ -2014,13 +1975,9 @@ class MessagesCompanion extends UpdateCompanion { map['mentioned_users'] = Variable( $MessagesTable.$convertermentionedUsers.toSql(mentionedUsers.value)); } - if (reactionCounts.present) { - map['reaction_counts'] = Variable( - $MessagesTable.$converterreactionCountsn.toSql(reactionCounts.value)); - } - if (reactionScores.present) { - map['reaction_scores'] = Variable( - $MessagesTable.$converterreactionScoresn.toSql(reactionScores.value)); + if (reactionGroups.present) { + map['reaction_groups'] = Variable( + $MessagesTable.$converterreactionGroupsn.toSql(reactionGroups.value)); } if (parentId.present) { map['parent_id'] = Variable(parentId.value); @@ -2114,8 +2071,7 @@ class MessagesCompanion extends UpdateCompanion { ..write('state: $state, ') ..write('type: $type, ') ..write('mentionedUsers: $mentionedUsers, ') - ..write('reactionCounts: $reactionCounts, ') - ..write('reactionScores: $reactionScores, ') + ..write('reactionGroups: $reactionGroups, ') ..write('parentId: $parentId, ') ..write('quotedMessageId: $quotedMessageId, ') ..write('pollId: $pollId, ') @@ -2895,19 +2851,12 @@ class $PinnedMessagesTable extends PinnedMessages .withConverter>( $PinnedMessagesTable.$convertermentionedUsers); @override - late final GeneratedColumnWithTypeConverter?, String> - reactionCounts = GeneratedColumn( - 'reaction_counts', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false) - .withConverter?>( - $PinnedMessagesTable.$converterreactionCountsn); - @override - late final GeneratedColumnWithTypeConverter?, String> - reactionScores = GeneratedColumn( - 'reaction_scores', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false) - .withConverter?>( - $PinnedMessagesTable.$converterreactionScoresn); + late final GeneratedColumnWithTypeConverter?, + String> reactionGroups = GeneratedColumn( + 'reaction_groups', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false) + .withConverter?>( + $PinnedMessagesTable.$converterreactionGroupsn); static const VerificationMeta _parentIdMeta = const VerificationMeta('parentId'); @override @@ -3069,8 +3018,7 @@ class $PinnedMessagesTable extends PinnedMessages state, type, mentionedUsers, - reactionCounts, - reactionScores, + reactionGroups, parentId, quotedMessageId, pollId, @@ -3265,12 +3213,9 @@ class $PinnedMessagesTable extends PinnedMessages mentionedUsers: $PinnedMessagesTable.$convertermentionedUsers.fromSql( attachedDatabase.typeMapping.read( DriftSqlType.string, data['${effectivePrefix}mentioned_users'])!), - reactionCounts: $PinnedMessagesTable.$converterreactionCountsn.fromSql( - attachedDatabase.typeMapping.read( - DriftSqlType.string, data['${effectivePrefix}reaction_counts'])), - reactionScores: $PinnedMessagesTable.$converterreactionScoresn.fromSql( + reactionGroups: $PinnedMessagesTable.$converterreactionGroupsn.fromSql( attachedDatabase.typeMapping.read( - DriftSqlType.string, data['${effectivePrefix}reaction_scores'])), + DriftSqlType.string, data['${effectivePrefix}reaction_groups'])), parentId: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}parent_id']), quotedMessageId: attachedDatabase.typeMapping.read( @@ -3335,14 +3280,11 @@ class $PinnedMessagesTable extends PinnedMessages ListConverter(); static TypeConverter, String> $convertermentionedUsers = ListConverter(); - static TypeConverter, String> $converterreactionCounts = - MapConverter(); - static TypeConverter?, String?> $converterreactionCountsn = - NullAwareTypeConverter.wrap($converterreactionCounts); - static TypeConverter, String> $converterreactionScores = - MapConverter(); - static TypeConverter?, String?> $converterreactionScoresn = - NullAwareTypeConverter.wrap($converterreactionScores); + static TypeConverter, String> + $converterreactionGroups = ReactionGroupsConverter(); + static TypeConverter?, String?> + $converterreactionGroupsn = + NullAwareTypeConverter.wrap($converterreactionGroups); static TypeConverter?, String?> $converteri18n = NullableMapConverter(); static TypeConverter, String> $converterrestrictedVisibility = @@ -3376,11 +3318,8 @@ class PinnedMessageEntity extends DataClass /// The list of user mentioned in the message final List mentionedUsers; - /// A map describing the count of number of every reaction - final Map? reactionCounts; - - /// A map describing the count of score of every reaction - final Map? reactionScores; + /// A map describing the reaction group for every reaction + final Map? reactionGroups; /// The ID of the parent message, if the message is a thread reply. final String? parentId; @@ -3460,8 +3399,7 @@ class PinnedMessageEntity extends DataClass required this.state, required this.type, required this.mentionedUsers, - this.reactionCounts, - this.reactionScores, + this.reactionGroups, this.parentId, this.quotedMessageId, this.pollId, @@ -3503,13 +3441,9 @@ class PinnedMessageEntity extends DataClass map['mentioned_users'] = Variable( $PinnedMessagesTable.$convertermentionedUsers.toSql(mentionedUsers)); } - if (!nullToAbsent || reactionCounts != null) { - map['reaction_counts'] = Variable( - $PinnedMessagesTable.$converterreactionCountsn.toSql(reactionCounts)); - } - if (!nullToAbsent || reactionScores != null) { - map['reaction_scores'] = Variable( - $PinnedMessagesTable.$converterreactionScoresn.toSql(reactionScores)); + if (!nullToAbsent || reactionGroups != null) { + map['reaction_groups'] = Variable( + $PinnedMessagesTable.$converterreactionGroupsn.toSql(reactionGroups)); } if (!nullToAbsent || parentId != null) { map['parent_id'] = Variable(parentId); @@ -3594,10 +3528,8 @@ class PinnedMessageEntity extends DataClass state: serializer.fromJson(json['state']), type: serializer.fromJson(json['type']), mentionedUsers: serializer.fromJson>(json['mentionedUsers']), - reactionCounts: - serializer.fromJson?>(json['reactionCounts']), - reactionScores: - serializer.fromJson?>(json['reactionScores']), + reactionGroups: serializer + .fromJson?>(json['reactionGroups']), parentId: serializer.fromJson(json['parentId']), quotedMessageId: serializer.fromJson(json['quotedMessageId']), pollId: serializer.fromJson(json['pollId']), @@ -3636,8 +3568,8 @@ class PinnedMessageEntity extends DataClass 'state': serializer.toJson(state), 'type': serializer.toJson(type), 'mentionedUsers': serializer.toJson>(mentionedUsers), - 'reactionCounts': serializer.toJson?>(reactionCounts), - 'reactionScores': serializer.toJson?>(reactionScores), + 'reactionGroups': + serializer.toJson?>(reactionGroups), 'parentId': serializer.toJson(parentId), 'quotedMessageId': serializer.toJson(quotedMessageId), 'pollId': serializer.toJson(pollId), @@ -3674,8 +3606,8 @@ class PinnedMessageEntity extends DataClass String? state, String? type, List? mentionedUsers, - Value?> reactionCounts = const Value.absent(), - Value?> reactionScores = const Value.absent(), + Value?> reactionGroups = + const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), Value pollId = const Value.absent(), @@ -3707,10 +3639,8 @@ class PinnedMessageEntity extends DataClass state: state ?? this.state, type: type ?? this.type, mentionedUsers: mentionedUsers ?? this.mentionedUsers, - reactionCounts: - reactionCounts.present ? reactionCounts.value : this.reactionCounts, - reactionScores: - reactionScores.present ? reactionScores.value : this.reactionScores, + reactionGroups: + reactionGroups.present ? reactionGroups.value : this.reactionGroups, parentId: parentId.present ? parentId.value : this.parentId, quotedMessageId: quotedMessageId.present ? quotedMessageId.value @@ -3766,12 +3696,9 @@ class PinnedMessageEntity extends DataClass mentionedUsers: data.mentionedUsers.present ? data.mentionedUsers.value : this.mentionedUsers, - reactionCounts: data.reactionCounts.present - ? data.reactionCounts.value - : this.reactionCounts, - reactionScores: data.reactionScores.present - ? data.reactionScores.value - : this.reactionScores, + reactionGroups: data.reactionGroups.present + ? data.reactionGroups.value + : this.reactionGroups, parentId: data.parentId.present ? data.parentId.value : this.parentId, quotedMessageId: data.quotedMessageId.present ? data.quotedMessageId.value @@ -3835,8 +3762,7 @@ class PinnedMessageEntity extends DataClass ..write('state: $state, ') ..write('type: $type, ') ..write('mentionedUsers: $mentionedUsers, ') - ..write('reactionCounts: $reactionCounts, ') - ..write('reactionScores: $reactionScores, ') + ..write('reactionGroups: $reactionGroups, ') ..write('parentId: $parentId, ') ..write('quotedMessageId: $quotedMessageId, ') ..write('pollId: $pollId, ') @@ -3873,8 +3799,7 @@ class PinnedMessageEntity extends DataClass state, type, mentionedUsers, - reactionCounts, - reactionScores, + reactionGroups, parentId, quotedMessageId, pollId, @@ -3910,8 +3835,7 @@ class PinnedMessageEntity extends DataClass other.state == this.state && other.type == this.type && other.mentionedUsers == this.mentionedUsers && - other.reactionCounts == this.reactionCounts && - other.reactionScores == this.reactionScores && + other.reactionGroups == this.reactionGroups && other.parentId == this.parentId && other.quotedMessageId == this.quotedMessageId && other.pollId == this.pollId && @@ -3945,8 +3869,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { final Value state; final Value type; final Value> mentionedUsers; - final Value?> reactionCounts; - final Value?> reactionScores; + final Value?> reactionGroups; final Value parentId; final Value quotedMessageId; final Value pollId; @@ -3979,8 +3902,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { this.state = const Value.absent(), this.type = const Value.absent(), this.mentionedUsers = const Value.absent(), - this.reactionCounts = const Value.absent(), - this.reactionScores = const Value.absent(), + this.reactionGroups = const Value.absent(), this.parentId = const Value.absent(), this.quotedMessageId = const Value.absent(), this.pollId = const Value.absent(), @@ -4014,8 +3936,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { required String state, this.type = const Value.absent(), required List mentionedUsers, - this.reactionCounts = const Value.absent(), - this.reactionScores = const Value.absent(), + this.reactionGroups = const Value.absent(), this.parentId = const Value.absent(), this.quotedMessageId = const Value.absent(), this.pollId = const Value.absent(), @@ -4053,8 +3974,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { Expression? state, Expression? type, Expression? mentionedUsers, - Expression? reactionCounts, - Expression? reactionScores, + Expression? reactionGroups, Expression? parentId, Expression? quotedMessageId, Expression? pollId, @@ -4088,8 +4008,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { if (state != null) 'state': state, if (type != null) 'type': type, if (mentionedUsers != null) 'mentioned_users': mentionedUsers, - if (reactionCounts != null) 'reaction_counts': reactionCounts, - if (reactionScores != null) 'reaction_scores': reactionScores, + if (reactionGroups != null) 'reaction_groups': reactionGroups, if (parentId != null) 'parent_id': parentId, if (quotedMessageId != null) 'quoted_message_id': quotedMessageId, if (pollId != null) 'poll_id': pollId, @@ -4127,8 +4046,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { Value? state, Value? type, Value>? mentionedUsers, - Value?>? reactionCounts, - Value?>? reactionScores, + Value?>? reactionGroups, Value? parentId, Value? quotedMessageId, Value? pollId, @@ -4161,8 +4079,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { state: state ?? this.state, type: type ?? this.type, mentionedUsers: mentionedUsers ?? this.mentionedUsers, - reactionCounts: reactionCounts ?? this.reactionCounts, - reactionScores: reactionScores ?? this.reactionScores, + reactionGroups: reactionGroups ?? this.reactionGroups, parentId: parentId ?? this.parentId, quotedMessageId: quotedMessageId ?? this.quotedMessageId, pollId: pollId ?? this.pollId, @@ -4215,15 +4132,10 @@ class PinnedMessagesCompanion extends UpdateCompanion { .$convertermentionedUsers .toSql(mentionedUsers.value)); } - if (reactionCounts.present) { - map['reaction_counts'] = Variable($PinnedMessagesTable - .$converterreactionCountsn - .toSql(reactionCounts.value)); - } - if (reactionScores.present) { - map['reaction_scores'] = Variable($PinnedMessagesTable - .$converterreactionScoresn - .toSql(reactionScores.value)); + if (reactionGroups.present) { + map['reaction_groups'] = Variable($PinnedMessagesTable + .$converterreactionGroupsn + .toSql(reactionGroups.value)); } if (parentId.present) { map['parent_id'] = Variable(parentId.value); @@ -4317,8 +4229,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { ..write('state: $state, ') ..write('type: $type, ') ..write('mentionedUsers: $mentionedUsers, ') - ..write('reactionCounts: $reactionCounts, ') - ..write('reactionScores: $reactionScores, ') + ..write('reactionGroups: $reactionGroups, ') ..write('parentId: $parentId, ') ..write('quotedMessageId: $quotedMessageId, ') ..write('pollId: $pollId, ') @@ -9173,8 +9084,7 @@ typedef $$MessagesTableCreateCompanionBuilder = MessagesCompanion Function({ required String state, Value type, required List mentionedUsers, - Value?> reactionCounts, - Value?> reactionScores, + Value?> reactionGroups, Value parentId, Value quotedMessageId, Value pollId, @@ -9208,8 +9118,7 @@ typedef $$MessagesTableUpdateCompanionBuilder = MessagesCompanion Function({ Value state, Value type, Value> mentionedUsers, - Value?> reactionCounts, - Value?> reactionScores, + Value?> reactionGroups, Value parentId, Value quotedMessageId, Value pollId, @@ -9318,14 +9227,10 @@ class $$MessagesTableFilterComposer column: $table.mentionedUsers, builder: (column) => ColumnWithTypeConverterFilters(column)); - ColumnWithTypeConverterFilters?, Map, String> - get reactionCounts => $composableBuilder( - column: $table.reactionCounts, - builder: (column) => ColumnWithTypeConverterFilters(column)); - - ColumnWithTypeConverterFilters?, Map, String> - get reactionScores => $composableBuilder( - column: $table.reactionScores, + ColumnWithTypeConverterFilters?, + Map, String> + get reactionGroups => $composableBuilder( + column: $table.reactionGroups, builder: (column) => ColumnWithTypeConverterFilters(column)); ColumnFilters get parentId => $composableBuilder( @@ -9506,12 +9411,8 @@ class $$MessagesTableOrderingComposer column: $table.mentionedUsers, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get reactionCounts => $composableBuilder( - column: $table.reactionCounts, - builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get reactionScores => $composableBuilder( - column: $table.reactionScores, + ColumnOrderings get reactionGroups => $composableBuilder( + column: $table.reactionGroups, builder: (column) => ColumnOrderings(column)); ColumnOrderings get parentId => $composableBuilder( @@ -9645,13 +9546,9 @@ class $$MessagesTableAnnotationComposer $composableBuilder( column: $table.mentionedUsers, builder: (column) => column); - GeneratedColumnWithTypeConverter?, String> - get reactionCounts => $composableBuilder( - column: $table.reactionCounts, builder: (column) => column); - - GeneratedColumnWithTypeConverter?, String> - get reactionScores => $composableBuilder( - column: $table.reactionScores, builder: (column) => column); + GeneratedColumnWithTypeConverter?, String> + get reactionGroups => $composableBuilder( + column: $table.reactionGroups, builder: (column) => column); GeneratedColumn get parentId => $composableBuilder(column: $table.parentId, builder: (column) => column); @@ -9817,8 +9714,8 @@ class $$MessagesTableTableManager extends RootTableManager< Value state = const Value.absent(), Value type = const Value.absent(), Value> mentionedUsers = const Value.absent(), - Value?> reactionCounts = const Value.absent(), - Value?> reactionScores = const Value.absent(), + Value?> reactionGroups = + const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), Value pollId = const Value.absent(), @@ -9852,8 +9749,7 @@ class $$MessagesTableTableManager extends RootTableManager< state: state, type: type, mentionedUsers: mentionedUsers, - reactionCounts: reactionCounts, - reactionScores: reactionScores, + reactionGroups: reactionGroups, parentId: parentId, quotedMessageId: quotedMessageId, pollId: pollId, @@ -9887,8 +9783,8 @@ class $$MessagesTableTableManager extends RootTableManager< required String state, Value type = const Value.absent(), required List mentionedUsers, - Value?> reactionCounts = const Value.absent(), - Value?> reactionScores = const Value.absent(), + Value?> reactionGroups = + const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), Value pollId = const Value.absent(), @@ -9922,8 +9818,7 @@ class $$MessagesTableTableManager extends RootTableManager< state: state, type: type, mentionedUsers: mentionedUsers, - reactionCounts: reactionCounts, - reactionScores: reactionScores, + reactionGroups: reactionGroups, parentId: parentId, quotedMessageId: quotedMessageId, pollId: pollId, @@ -10548,8 +10443,7 @@ typedef $$PinnedMessagesTableCreateCompanionBuilder = PinnedMessagesCompanion required String state, Value type, required List mentionedUsers, - Value?> reactionCounts, - Value?> reactionScores, + Value?> reactionGroups, Value parentId, Value quotedMessageId, Value pollId, @@ -10584,8 +10478,7 @@ typedef $$PinnedMessagesTableUpdateCompanionBuilder = PinnedMessagesCompanion Value state, Value type, Value> mentionedUsers, - Value?> reactionCounts, - Value?> reactionScores, + Value?> reactionGroups, Value parentId, Value quotedMessageId, Value pollId, @@ -10669,14 +10562,10 @@ class $$PinnedMessagesTableFilterComposer column: $table.mentionedUsers, builder: (column) => ColumnWithTypeConverterFilters(column)); - ColumnWithTypeConverterFilters?, Map, String> - get reactionCounts => $composableBuilder( - column: $table.reactionCounts, - builder: (column) => ColumnWithTypeConverterFilters(column)); - - ColumnWithTypeConverterFilters?, Map, String> - get reactionScores => $composableBuilder( - column: $table.reactionScores, + ColumnWithTypeConverterFilters?, + Map, String> + get reactionGroups => $composableBuilder( + column: $table.reactionGroups, builder: (column) => ColumnWithTypeConverterFilters(column)); ColumnFilters get parentId => $composableBuilder( @@ -10821,12 +10710,8 @@ class $$PinnedMessagesTableOrderingComposer column: $table.mentionedUsers, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get reactionCounts => $composableBuilder( - column: $table.reactionCounts, - builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get reactionScores => $composableBuilder( - column: $table.reactionScores, + ColumnOrderings get reactionGroups => $composableBuilder( + column: $table.reactionGroups, builder: (column) => ColumnOrderings(column)); ColumnOrderings get parentId => $composableBuilder( @@ -10943,13 +10828,9 @@ class $$PinnedMessagesTableAnnotationComposer $composableBuilder( column: $table.mentionedUsers, builder: (column) => column); - GeneratedColumnWithTypeConverter?, String> - get reactionCounts => $composableBuilder( - column: $table.reactionCounts, builder: (column) => column); - - GeneratedColumnWithTypeConverter?, String> - get reactionScores => $composableBuilder( - column: $table.reactionScores, builder: (column) => column); + GeneratedColumnWithTypeConverter?, String> + get reactionGroups => $composableBuilder( + column: $table.reactionGroups, builder: (column) => column); GeneratedColumn get parentId => $composableBuilder(column: $table.parentId, builder: (column) => column); @@ -11079,8 +10960,8 @@ class $$PinnedMessagesTableTableManager extends RootTableManager< Value state = const Value.absent(), Value type = const Value.absent(), Value> mentionedUsers = const Value.absent(), - Value?> reactionCounts = const Value.absent(), - Value?> reactionScores = const Value.absent(), + Value?> reactionGroups = + const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), Value pollId = const Value.absent(), @@ -11114,8 +10995,7 @@ class $$PinnedMessagesTableTableManager extends RootTableManager< state: state, type: type, mentionedUsers: mentionedUsers, - reactionCounts: reactionCounts, - reactionScores: reactionScores, + reactionGroups: reactionGroups, parentId: parentId, quotedMessageId: quotedMessageId, pollId: pollId, @@ -11149,8 +11029,8 @@ class $$PinnedMessagesTableTableManager extends RootTableManager< required String state, Value type = const Value.absent(), required List mentionedUsers, - Value?> reactionCounts = const Value.absent(), - Value?> reactionScores = const Value.absent(), + Value?> reactionGroups = + const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), Value pollId = const Value.absent(), @@ -11184,8 +11064,7 @@ class $$PinnedMessagesTableTableManager extends RootTableManager< state: state, type: type, mentionedUsers: mentionedUsers, - reactionCounts: reactionCounts, - reactionScores: reactionScores, + reactionGroups: reactionGroups, parentId: parentId, quotedMessageId: quotedMessageId, pollId: pollId, diff --git a/packages/stream_chat_persistence/lib/src/entity/messages.dart b/packages/stream_chat_persistence/lib/src/entity/messages.dart index 8b8ae7da6f..766bbe5995 100644 --- a/packages/stream_chat_persistence/lib/src/entity/messages.dart +++ b/packages/stream_chat_persistence/lib/src/entity/messages.dart @@ -2,6 +2,7 @@ import 'package:drift/drift.dart'; import 'package:stream_chat_persistence/src/converter/list_converter.dart'; import 'package:stream_chat_persistence/src/converter/map_converter.dart'; +import 'package:stream_chat_persistence/src/converter/reaction_groups_converter.dart'; import 'package:stream_chat_persistence/src/entity/channels.dart'; /// Represents a [Messages] table in [MoorChatDatabase]. @@ -26,11 +27,9 @@ class Messages extends Table { /// The list of user mentioned in the message TextColumn get mentionedUsers => text().map(ListConverter())(); - /// A map describing the count of number of every reaction - TextColumn get reactionCounts => text().nullable().map(MapConverter())(); - - /// A map describing the count of score of every reaction - TextColumn get reactionScores => text().nullable().map(MapConverter())(); + /// A map describing the reaction group for every reaction + TextColumn get reactionGroups => + text().map(ReactionGroupsConverter()).nullable()(); /// The ID of the parent message, if the message is a thread reply. TextColumn get parentId => text().nullable()(); diff --git a/packages/stream_chat_persistence/lib/src/mapper/message_mapper.dart b/packages/stream_chat_persistence/lib/src/mapper/message_mapper.dart index a0020d8d78..8e4d9d544b 100644 --- a/packages/stream_chat_persistence/lib/src/mapper/message_mapper.dart +++ b/packages/stream_chat_persistence/lib/src/mapper/message_mapper.dart @@ -40,8 +40,7 @@ extension MessageEntityX on MessageEntity { quotedMessage: quotedMessage, pollId: pollId, poll: poll, - reactionCounts: reactionCounts, - reactionScores: reactionScores, + reactionGroups: reactionGroups, replyCount: replyCount, showInChannel: showInChannel, text: messageText, @@ -75,8 +74,7 @@ extension MessageX on Message { shadowed: shadowed, showInChannel: showInChannel, replyCount: replyCount, - reactionScores: reactionScores, - reactionCounts: reactionCounts, + reactionGroups: reactionGroups, mentionedUsers: mentionedUsers.map(jsonEncode).toList(), state: jsonEncode(state), remoteUpdatedAt: remoteUpdatedAt, diff --git a/packages/stream_chat_persistence/lib/src/mapper/pinned_message_mapper.dart b/packages/stream_chat_persistence/lib/src/mapper/pinned_message_mapper.dart index a41bdd4ebe..a87b716ec2 100644 --- a/packages/stream_chat_persistence/lib/src/mapper/pinned_message_mapper.dart +++ b/packages/stream_chat_persistence/lib/src/mapper/pinned_message_mapper.dart @@ -39,8 +39,7 @@ extension PinnedMessageEntityX on PinnedMessageEntity { quotedMessage: quotedMessage, pollId: pollId, poll: poll, - reactionCounts: reactionCounts, - reactionScores: reactionScores, + reactionGroups: reactionGroups, replyCount: replyCount, showInChannel: showInChannel, text: messageText, @@ -74,8 +73,7 @@ extension PMessageX on Message { shadowed: shadowed, showInChannel: showInChannel, replyCount: replyCount, - reactionScores: reactionScores, - reactionCounts: reactionCounts, + reactionGroups: reactionGroups, mentionedUsers: mentionedUsers.map(jsonEncode).toList(), state: jsonEncode(state), remoteUpdatedAt: remoteUpdatedAt, diff --git a/packages/stream_chat_persistence/test/src/dao/message_dao_test.dart b/packages/stream_chat_persistence/test/src/dao/message_dao_test.dart index ca98d622ca..58c8ecf3ab 100644 --- a/packages/stream_chat_persistence/test/src/dao/message_dao_test.dart +++ b/packages/stream_chat_persistence/test/src/dao/message_dao_test.dart @@ -40,6 +40,10 @@ void main() { pinned: math.Random().nextBool(), pinnedAt: DateTime.now(), pinnedBy: User(id: 'testUserId$index'), + reactionGroups: { + 'testType': ReactionGroup(count: 3, sumScores: 10), + 'testType2': ReactionGroup(count: 5, sumScores: 20), + }, i18n: { 'en_text': 'Hello #$index', 'hi_text': 'नमस्ते #$index', diff --git a/packages/stream_chat_persistence/test/src/dao/pinned_message_dao_test.dart b/packages/stream_chat_persistence/test/src/dao/pinned_message_dao_test.dart index 4dcf5e0e3b..e3e3408cd4 100644 --- a/packages/stream_chat_persistence/test/src/dao/pinned_message_dao_test.dart +++ b/packages/stream_chat_persistence/test/src/dao/pinned_message_dao_test.dart @@ -40,6 +40,10 @@ void main() { pinned: math.Random().nextBool(), pinnedAt: DateTime.now(), pinnedBy: User(id: 'testUserId$index'), + reactionGroups: { + 'testType': ReactionGroup(count: 3, sumScores: 10), + 'testType2': ReactionGroup(count: 5, sumScores: 20), + }, ), ); final quotedMessages = List.generate( diff --git a/packages/stream_chat_persistence/test/src/mapper/message_mapper_test.dart b/packages/stream_chat_persistence/test/src/mapper/message_mapper_test.dart index 4bdf284cb9..13d6bc3953 100644 --- a/packages/stream_chat_persistence/test/src/mapper/message_mapper_test.dart +++ b/packages/stream_chat_persistence/test/src/mapper/message_mapper_test.dart @@ -54,11 +54,20 @@ void main() { shadowed: math.Random().nextBool(), showInChannel: math.Random().nextBool(), replyCount: 33, - reactionScores: {for (final r in reactions) r.type: r.score}, - reactionCounts: reactions.fold( + reactionGroups: reactions.fold( {}, - (prev, curr) => - prev?..update(curr.type, (value) => value + 1, ifAbsent: () => 1), + (prev, curr) => prev + ?..update( + curr.type, + (value) => value.copyWith( + count: value.count + 1, + sumScores: value.sumScores + curr.score, + ), + ifAbsent: () => ReactionGroup( + count: 1, + sumScores: curr.score, + ), + ), ), mentionedUsers: [ jsonEncode(User(id: 'testuser')), @@ -109,8 +118,7 @@ void main() { expect(message.mentionedUsers[i].id, entityMentionedUser.id); } expect(message.replyCount, entity.replyCount); - expect(message.reactionScores, entity.reactionScores); - expect(message.reactionCounts, entity.reactionCounts); + expect(message.reactionGroups, entity.reactionGroups); expect(message.state, MessageState.fromJson(jsonDecode(entity.state))); expect(message.localUpdatedAt, isSameDateAs(entity.localUpdatedAt)); expect(message.remoteUpdatedAt, isSameDateAs(entity.remoteUpdatedAt)); @@ -127,8 +135,7 @@ void main() { expect(message.pinExpires, isSameDateAs(entity.pinExpires)); expect(message.pinnedAt, isSameDateAs(entity.pinnedAt)); expect(message.pinnedBy!.id, entity.pinnedByUserId); - expect(message.reactionCounts, entity.reactionCounts); - expect(message.reactionScores, entity.reactionScores); + expect(message.reactionGroups, entity.reactionGroups); expect(message.i18n, entity.i18n); for (var i = 0; i < message.attachments.length; i++) { final messageAttachment = message.attachments[i]; @@ -189,11 +196,20 @@ void main() { mentionedUsers: [ User(id: 'testuser'), ], - reactionScores: {for (final r in reactions) r.type: r.score}, - reactionCounts: reactions.fold( + reactionGroups: reactions.fold( {}, - (prev, curr) => - prev?..update(curr.type, (value) => value + 1, ifAbsent: () => 1), + (prev, curr) => prev + ?..update( + curr.type, + (value) => value.copyWith( + count: value.count + 1, + sumScores: value.sumScores + curr.score, + ), + ifAbsent: () => ReactionGroup( + count: 1, + sumScores: curr.score, + ), + ), ), localUpdatedAt: DateTime.now(), updatedAt: DateTime.now().add(const Duration(seconds: 1)), @@ -229,8 +245,6 @@ void main() { expect(entity.replyCount, message.replyCount); expect( entity.mentionedUsers, message.mentionedUsers.map(jsonEncode).toList()); - expect(entity.reactionScores, message.reactionScores); - expect(entity.reactionCounts, message.reactionCounts); expect(entity.state, jsonEncode(message.state)); expect(entity.localUpdatedAt, isSameDateAs(message.localUpdatedAt)); expect(entity.remoteUpdatedAt, isSameDateAs(message.remoteUpdatedAt)); @@ -247,8 +261,7 @@ void main() { expect(entity.pinExpires, isSameDateAs(message.pinExpires)); expect(entity.pinnedAt, isSameDateAs(message.pinnedAt)); expect(entity.pinnedByUserId, message.pinnedBy!.id); - expect(entity.reactionCounts, message.reactionCounts); - expect(entity.reactionScores, message.reactionScores); + expect(entity.reactionGroups, message.reactionGroups); expect( entity.attachments, message.attachments.map((it) => jsonEncode(it.toData())).toList(), diff --git a/packages/stream_chat_persistence/test/src/mapper/pinned_message_mapper_test.dart b/packages/stream_chat_persistence/test/src/mapper/pinned_message_mapper_test.dart index 2095a3fdb6..133a49c39e 100644 --- a/packages/stream_chat_persistence/test/src/mapper/pinned_message_mapper_test.dart +++ b/packages/stream_chat_persistence/test/src/mapper/pinned_message_mapper_test.dart @@ -54,11 +54,20 @@ void main() { shadowed: math.Random().nextBool(), showInChannel: math.Random().nextBool(), replyCount: 33, - reactionScores: {for (final r in reactions) r.type: r.score}, - reactionCounts: reactions.fold( + reactionGroups: reactions.fold( {}, - (prev, curr) => - prev?..update(curr.type, (value) => value + 1, ifAbsent: () => 1), + (prev, curr) => prev + ?..update( + curr.type, + (value) => value.copyWith( + count: value.count + 1, + sumScores: value.sumScores + curr.score, + ), + ifAbsent: () => ReactionGroup( + count: 1, + sumScores: curr.score, + ), + ), ), mentionedUsers: [ jsonEncode(User(id: 'testuser')), @@ -109,8 +118,7 @@ void main() { expect(message.mentionedUsers[i].id, entityMentionedUser.id); } expect(message.replyCount, entity.replyCount); - expect(message.reactionScores, entity.reactionScores); - expect(message.reactionCounts, entity.reactionCounts); + expect(message.reactionGroups, entity.reactionGroups); expect(message.state, MessageState.fromJson(jsonDecode(entity.state))); expect(message.localUpdatedAt, isSameDateAs(entity.localUpdatedAt)); expect(message.remoteUpdatedAt, isSameDateAs(entity.remoteUpdatedAt)); @@ -127,8 +135,7 @@ void main() { expect(message.pinExpires, isSameDateAs(entity.pinExpires)); expect(message.pinnedAt, isSameDateAs(entity.pinnedAt)); expect(message.pinnedBy!.id, entity.pinnedByUserId); - expect(message.reactionCounts, entity.reactionCounts); - expect(message.reactionScores, entity.reactionScores); + expect(message.reactionGroups, entity.reactionGroups); expect(message.i18n, entity.i18n); for (var i = 0; i < message.attachments.length; i++) { final messageAttachment = message.attachments[i]; @@ -189,11 +196,20 @@ void main() { mentionedUsers: [ User(id: 'testuser'), ], - reactionScores: {for (final r in reactions) r.type: r.score}, - reactionCounts: reactions.fold( + reactionGroups: reactions.fold( {}, - (prev, curr) => - prev?..update(curr.type, (value) => value + 1, ifAbsent: () => 1), + (prev, curr) => prev + ?..update( + curr.type, + (value) => value.copyWith( + count: value.count + 1, + sumScores: value.sumScores + curr.score, + ), + ifAbsent: () => ReactionGroup( + count: 1, + sumScores: curr.score, + ), + ), ), localUpdatedAt: DateTime.now(), updatedAt: DateTime.now().add(const Duration(seconds: 1)), @@ -229,8 +245,6 @@ void main() { expect(entity.replyCount, message.replyCount); expect( entity.mentionedUsers, message.mentionedUsers.map(jsonEncode).toList()); - expect(entity.reactionScores, message.reactionScores); - expect(entity.reactionCounts, message.reactionCounts); expect(entity.state, jsonEncode(message.state)); expect(entity.localUpdatedAt, isSameDateAs(message.localUpdatedAt)); expect(entity.remoteUpdatedAt, isSameDateAs(message.remoteUpdatedAt)); @@ -247,8 +261,7 @@ void main() { expect(entity.pinExpires, isSameDateAs(message.pinExpires)); expect(entity.pinnedAt, isSameDateAs(message.pinnedAt)); expect(entity.pinnedByUserId, message.pinnedBy!.id); - expect(entity.reactionCounts, message.reactionCounts); - expect(entity.reactionScores, message.reactionScores); + expect(entity.reactionGroups, message.reactionGroups); expect( entity.attachments, message.attachments.map((it) => jsonEncode(it.toData())).toList(),