claude refactor

This commit is contained in:
2026-05-04 13:54:39 +02:00
parent 9973f12733
commit 551c1bf1fa
125 changed files with 4484 additions and 2544 deletions
@@ -0,0 +1,46 @@
import 'package:flutter_app_badge/flutter_app_badge.dart';
import '../../../infrastructure/utilityWidgets/loadableHydratedBloc/loadable_hydrated_bloc.dart';
import '../../../infrastructure/utilityWidgets/loadableHydratedBloc/loadable_hydrated_bloc_event.dart';
import '../repository/chat_list_repository.dart';
import 'chat_list_event.dart';
import 'chat_list_state.dart';
class ChatListBloc extends LoadableHydratedBloc<ChatListEvent, ChatListState, ChatListRepository> {
@override
ChatListRepository repository() => ChatListRepository();
@override
ChatListState fromNothing() => const ChatListState();
@override
ChatListState fromStorage(Map<String, dynamic> json) => ChatListState.fromJson(json);
@override
Map<String, dynamic>? toStorage(ChatListState state) => state.toJson();
@override
Future<void> gatherData() async {
final rooms = await repo.data.getRooms();
add(DataGathered((s) => s.copyWith(rooms: rooms)));
_updateAppBadge(rooms);
}
Future<void> refresh({bool renew = true}) async {
final rooms = await repo.data.getRooms(renew: renew);
add(DataGathered((s) => s.copyWith(rooms: rooms)));
_updateAppBadge(rooms);
}
Future<void> createDirectChat(String invite) async {
await repo.data.createDirectRoom(invite);
await refresh();
}
void _updateAppBadge(dynamic rooms) {
try {
final unread = rooms.data.map((e) => e.unreadMessages).fold<int>(0, (a, b) => a + b as int);
FlutterAppBadge.count(unread);
} catch (_) {}
}
}
@@ -0,0 +1,4 @@
import '../../../infrastructure/utilityWidgets/loadableHydratedBloc/loadable_hydrated_bloc_event.dart';
import 'chat_list_state.dart';
sealed class ChatListEvent extends LoadableHydratedBlocEvent<ChatListState> {}
@@ -0,0 +1,15 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../../../../api/marianumcloud/talk/room/getRoomResponse.dart';
part 'chat_list_state.freezed.dart';
part 'chat_list_state.g.dart';
@freezed
abstract class ChatListState with _$ChatListState {
const factory ChatListState({
GetRoomResponse? rooms,
}) = _ChatListState;
factory ChatListState.fromJson(Map<String, Object?> json) => _$ChatListStateFromJson(json);
}
@@ -0,0 +1,277 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'chat_list_state.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$ChatListState {
GetRoomResponse? get rooms;
/// Create a copy of ChatListState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ChatListStateCopyWith<ChatListState> get copyWith => _$ChatListStateCopyWithImpl<ChatListState>(this as ChatListState, _$identity);
/// Serializes this ChatListState to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ChatListState&&(identical(other.rooms, rooms) || other.rooms == rooms));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,rooms);
@override
String toString() {
return 'ChatListState(rooms: $rooms)';
}
}
/// @nodoc
abstract mixin class $ChatListStateCopyWith<$Res> {
factory $ChatListStateCopyWith(ChatListState value, $Res Function(ChatListState) _then) = _$ChatListStateCopyWithImpl;
@useResult
$Res call({
GetRoomResponse? rooms
});
}
/// @nodoc
class _$ChatListStateCopyWithImpl<$Res>
implements $ChatListStateCopyWith<$Res> {
_$ChatListStateCopyWithImpl(this._self, this._then);
final ChatListState _self;
final $Res Function(ChatListState) _then;
/// Create a copy of ChatListState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? rooms = freezed,}) {
return _then(_self.copyWith(
rooms: freezed == rooms ? _self.rooms : rooms // ignore: cast_nullable_to_non_nullable
as GetRoomResponse?,
));
}
}
/// Adds pattern-matching-related methods to [ChatListState].
extension ChatListStatePatterns on ChatListState {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _ChatListState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _ChatListState() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _ChatListState value) $default,){
final _that = this;
switch (_that) {
case _ChatListState():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _ChatListState value)? $default,){
final _that = this;
switch (_that) {
case _ChatListState() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( GetRoomResponse? rooms)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ChatListState() when $default != null:
return $default(_that.rooms);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( GetRoomResponse? rooms) $default,) {final _that = this;
switch (_that) {
case _ChatListState():
return $default(_that.rooms);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( GetRoomResponse? rooms)? $default,) {final _that = this;
switch (_that) {
case _ChatListState() when $default != null:
return $default(_that.rooms);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _ChatListState implements ChatListState {
const _ChatListState({this.rooms});
factory _ChatListState.fromJson(Map<String, dynamic> json) => _$ChatListStateFromJson(json);
@override final GetRoomResponse? rooms;
/// Create a copy of ChatListState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ChatListStateCopyWith<_ChatListState> get copyWith => __$ChatListStateCopyWithImpl<_ChatListState>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$ChatListStateToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ChatListState&&(identical(other.rooms, rooms) || other.rooms == rooms));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,rooms);
@override
String toString() {
return 'ChatListState(rooms: $rooms)';
}
}
/// @nodoc
abstract mixin class _$ChatListStateCopyWith<$Res> implements $ChatListStateCopyWith<$Res> {
factory _$ChatListStateCopyWith(_ChatListState value, $Res Function(_ChatListState) _then) = __$ChatListStateCopyWithImpl;
@override @useResult
$Res call({
GetRoomResponse? rooms
});
}
/// @nodoc
class __$ChatListStateCopyWithImpl<$Res>
implements _$ChatListStateCopyWith<$Res> {
__$ChatListStateCopyWithImpl(this._self, this._then);
final _ChatListState _self;
final $Res Function(_ChatListState) _then;
/// Create a copy of ChatListState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? rooms = freezed,}) {
return _then(_ChatListState(
rooms: freezed == rooms ? _self.rooms : rooms // ignore: cast_nullable_to_non_nullable
as GetRoomResponse?,
));
}
}
// dart format on
@@ -0,0 +1,17 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'chat_list_state.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_ChatListState _$ChatListStateFromJson(Map<String, dynamic> json) =>
_ChatListState(
rooms: json['rooms'] == null
? null
: GetRoomResponse.fromJson(json['rooms'] as Map<String, dynamic>),
);
Map<String, dynamic> _$ChatListStateToJson(_ChatListState instance) =>
<String, dynamic>{'rooms': instance.rooms};