Fix profile edit with new url

This commit is contained in:
problematicconsumer
2024-01-01 17:46:29 +03:30
parent ec957cc88b
commit d28d852faf
2 changed files with 29 additions and 14 deletions

View File

@@ -45,9 +45,11 @@ abstract interface class ProfileRepository {
TaskEither<ProfileFailure, String> generateConfig(String id); TaskEither<ProfileFailure, String> generateConfig(String id);
/// using [patchBaseProfile] name, url, etc will also be patched (useful when editing with a new url)
TaskEither<ProfileFailure, Unit> updateSubscription( TaskEither<ProfileFailure, Unit> updateSubscription(
RemoteProfileEntity baseProfile, RemoteProfileEntity baseProfile, {
); bool patchBaseProfile = false,
});
TaskEither<ProfileFailure, Unit> patch(ProfileEntity profile); TaskEither<ProfileFailure, Unit> patch(ProfileEntity profile);
TaskEither<ProfileFailure, Unit> setAsActive(String id); TaskEither<ProfileFailure, Unit> setAsActive(String id);
@@ -263,8 +265,9 @@ class ProfileRepositoryImpl
@override @override
TaskEither<ProfileFailure, Unit> updateSubscription( TaskEither<ProfileFailure, Unit> updateSubscription(
RemoteProfileEntity baseProfile, RemoteProfileEntity baseProfile, {
) { bool patchBaseProfile = false,
}) {
return exceptionHandler( return exceptionHandler(
() async { () async {
loggy.debug( loggy.debug(
@@ -272,15 +275,26 @@ class ProfileRepositoryImpl
); );
return fetch(baseProfile.url, baseProfile.id) return fetch(baseProfile.url, baseProfile.id)
.flatMap( .flatMap(
(remoteProfile) => TaskEither(() async { (remoteProfile) => TaskEither(
await profileDataSource.edit( () async {
baseProfile.id, final profilePatch = remoteProfile
remoteProfile
.subInfoPatch() .subInfoPatch()
.copyWith(lastUpdate: Value(DateTime.now())), .copyWith(lastUpdate: Value(DateTime.now()));
);
return right(unit); 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(); .run();
}, },

View File

@@ -97,8 +97,9 @@ class ProfileDetailsNotifier extends _$ProfileDetailsNotifier with AppLogger {
failureOrSuccess = await _profilesRepo.patch(profile).run(); failureOrSuccess = await _profilesRepo.patch(profile).run();
} else { } else {
loggy.debug('updating profile'); loggy.debug('updating profile');
failureOrSuccess = failureOrSuccess = await _profilesRepo
await _profilesRepo.updateSubscription(profile).run(); .updateSubscription(profile, patchBaseProfile: true)
.run();
} }
} else { } else {
loggy.debug('adding profile, url: [${profile.url}]'); loggy.debug('adding profile, url: [${profile.url}]');