From d28d852faf156ee48f060c8e8d2c263cff998c2f Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Mon, 1 Jan 2024 17:46:29 +0330 Subject: [PATCH] Fix profile edit with new url --- .../profile/data/profile_repository.dart | 38 +++++++++++++------ .../details/profile_details_notifier.dart | 5 ++- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/features/profile/data/profile_repository.dart b/lib/features/profile/data/profile_repository.dart index 4f4494c8..8b65806f 100644 --- a/lib/features/profile/data/profile_repository.dart +++ b/lib/features/profile/data/profile_repository.dart @@ -45,9 +45,11 @@ abstract interface class ProfileRepository { TaskEither generateConfig(String id); + /// using [patchBaseProfile] name, url, etc will also be patched (useful when editing with a new url) TaskEither updateSubscription( - RemoteProfileEntity baseProfile, - ); + RemoteProfileEntity baseProfile, { + bool patchBaseProfile = false, + }); TaskEither patch(ProfileEntity profile); TaskEither setAsActive(String id); @@ -263,8 +265,9 @@ class ProfileRepositoryImpl @override TaskEither updateSubscription( - RemoteProfileEntity baseProfile, - ) { + RemoteProfileEntity baseProfile, { + bool patchBaseProfile = false, + }) { return exceptionHandler( () async { loggy.debug( @@ -272,15 +275,26 @@ class ProfileRepositoryImpl ); return fetch(baseProfile.url, baseProfile.id) .flatMap( - (remoteProfile) => TaskEither(() async { - await profileDataSource.edit( - baseProfile.id, - remoteProfile + (remoteProfile) => TaskEither( + () async { + final profilePatch = remoteProfile .subInfoPatch() - .copyWith(lastUpdate: Value(DateTime.now())), - ); - return right(unit); - }), + .copyWith(lastUpdate: Value(DateTime.now())); + + await profileDataSource.edit( + baseProfile.id, + patchBaseProfile + ? profilePatch.copyWith( + name: Value(baseProfile.name), + url: Value(baseProfile.url), + updateInterval: + Value(baseProfile.options?.updateInterval), + ) + : profilePatch, + ); + return right(unit); + }, + ), ) .run(); }, diff --git a/lib/features/profile/details/profile_details_notifier.dart b/lib/features/profile/details/profile_details_notifier.dart index 6cd5df65..b291bf6d 100644 --- a/lib/features/profile/details/profile_details_notifier.dart +++ b/lib/features/profile/details/profile_details_notifier.dart @@ -97,8 +97,9 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger { failureOrSuccess = await _profilesRepo.patch(profile).run(); } else { loggy.debug('updating profile'); - failureOrSuccess = - await _profilesRepo.updateSubscription(profile).run(); + failureOrSuccess = await _profilesRepo + .updateSubscription(profile, patchBaseProfile: true) + .run(); } } else { loggy.debug('adding profile, url: [${profile.url}]');