From e351b281ef74a017156a35947e10796b18abd049 Mon Sep 17 00:00:00 2001 From: Li Date: Sun, 30 Jun 2024 10:42:06 +1000 Subject: [PATCH 1/2] Automatically create feed accounts on app startup These accounts will be configured to not publish anything, however features with sharing are about to be built which will require feed features. --- LiftLog.Api/Controllers/UserController.cs | 4 +++- LiftLog.Api/Validators/UserRequestValidators.cs | 5 +---- LiftLog.Lib/Models/UserActions.cs | 4 ++-- LiftLog.Ui/Pages/Feed/CreateFeedIdentityPage.razor | 2 +- LiftLog.Ui/Services/FeedIdentityService.cs | 5 ++--- LiftLog.Ui/Store/Feed/FeedActions.cs | 1 - LiftLog.Ui/Store/Feed/FeedStateInitMiddleware.cs | 13 +++++++++++++ 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/LiftLog.Api/Controllers/UserController.cs b/LiftLog.Api/Controllers/UserController.cs index 8fe47887..411038e0 100644 --- a/LiftLog.Api/Controllers/UserController.cs +++ b/LiftLog.Api/Controllers/UserController.cs @@ -36,9 +36,10 @@ [FromServices] IValidator validator var password = Guid.NewGuid().ToString(); var hashedPassword = passwordService.HashPassword(password, out var salt); + var id = request.Id ?? Guid.NewGuid(); var user = new User { - Id = request.Id, + Id = id, HashedPassword = hashedPassword, Salt = salt, LastAccessed = DateTimeOffset.UtcNow, @@ -50,6 +51,7 @@ [FromServices] IValidator validator await db.SaveChangesAsync(); return Ok( new CreateUserResponse( + Id: id, Lookup: idEncodingService.EncodeId(user.UserLookup), Password: password ) diff --git a/LiftLog.Api/Validators/UserRequestValidators.cs b/LiftLog.Api/Validators/UserRequestValidators.cs index be8af431..3492957b 100644 --- a/LiftLog.Api/Validators/UserRequestValidators.cs +++ b/LiftLog.Api/Validators/UserRequestValidators.cs @@ -6,10 +6,7 @@ namespace LiftLog.Api.Validators; public class CreateUserRequestValidator : AbstractValidator { - public CreateUserRequestValidator() - { - RuleFor(x => x.Id).NotEmpty(); - } + public CreateUserRequestValidator() { } } public class GetUsersRequestValidator : AbstractValidator diff --git a/LiftLog.Lib/Models/UserActions.cs b/LiftLog.Lib/Models/UserActions.cs index ac8957cc..ba5a80bb 100644 --- a/LiftLog.Lib/Models/UserActions.cs +++ b/LiftLog.Lib/Models/UserActions.cs @@ -1,6 +1,6 @@ namespace LiftLog.Lib.Models; -public record CreateUserRequest(Guid Id); +public record CreateUserRequest(Guid? Id); public record GetUsersRequest(Guid[] Ids); @@ -8,7 +8,7 @@ public record DeleteUserRequest(Guid Id, string Password); public record GetUsersResponse(Dictionary Users); -public record CreateUserResponse(string Lookup, string Password); +public record CreateUserResponse(Guid Id, string Lookup, string Password); public record PutUserDataRequest( Guid Id, diff --git a/LiftLog.Ui/Pages/Feed/CreateFeedIdentityPage.razor b/LiftLog.Ui/Pages/Feed/CreateFeedIdentityPage.razor index e0cbb2fb..0eac05b4 100644 --- a/LiftLog.Ui/Pages/Feed/CreateFeedIdentityPage.razor +++ b/LiftLog.Ui/Pages/Feed/CreateFeedIdentityPage.razor @@ -77,7 +77,7 @@ else private void StartPublishing() { - Dispatcher.Dispatch(new CreateFeedIdentityAction(Guid.NewGuid(), string.IsNullOrEmpty(name) ? null : name, null, publishBodyweight, publishPlan, publishWorkouts, From == null ? null : From)); + Dispatcher.Dispatch(new CreateFeedIdentityAction(string.IsNullOrEmpty(name) ? null : name, null, publishBodyweight, publishPlan, publishWorkouts, From == null ? null : From)); } private void UpdatePublishingDetails() diff --git a/LiftLog.Ui/Services/FeedIdentityService.cs b/LiftLog.Ui/Services/FeedIdentityService.cs index 97b95d95..de1a28e1 100644 --- a/LiftLog.Ui/Services/FeedIdentityService.cs +++ b/LiftLog.Ui/Services/FeedIdentityService.cs @@ -24,8 +24,7 @@ public async Task> CreateFeedIdentityAsync( ImmutableListValue currentPlan ) { - var id = Guid.NewGuid(); - var response = await feedApiService.CreateUserAsync(new CreateUserRequest(id)); + var response = await feedApiService.CreateUserAsync(new CreateUserRequest(null)); if (!response.IsSuccess) { return ApiResult.FromFailure(response); @@ -34,7 +33,7 @@ ImmutableListValue currentPlan var aesKey = await encryptionService.GenerateAesKeyAsync(); var rsaKeyPair = await encryptionService.GenerateRsaKeysAsync(); return await UpdateFeedIdentityAsync( - id: id, + id: response.Data.Id, lookup: response.Data.Lookup, password: response.Data.Password, aesKey: aesKey, diff --git a/LiftLog.Ui/Store/Feed/FeedActions.cs b/LiftLog.Ui/Store/Feed/FeedActions.cs index 7d3bba3e..f5617b38 100644 --- a/LiftLog.Ui/Store/Feed/FeedActions.cs +++ b/LiftLog.Ui/Store/Feed/FeedActions.cs @@ -6,7 +6,6 @@ namespace LiftLog.Ui.Store.Feed; public record SetFeedIsHydratedAction(); public record CreateFeedIdentityAction( - Guid Id, string? Name, byte[]? ProfilePicture, bool PublishBodyweight, diff --git a/LiftLog.Ui/Store/Feed/FeedStateInitMiddleware.cs b/LiftLog.Ui/Store/Feed/FeedStateInitMiddleware.cs index 5ec71348..cbaa1a88 100644 --- a/LiftLog.Ui/Store/Feed/FeedStateInitMiddleware.cs +++ b/LiftLog.Ui/Store/Feed/FeedStateInitMiddleware.cs @@ -35,6 +35,19 @@ public override async Task InitializeAsync(IDispatcher dispatch, IStore store) } dispatch.Dispatch(new SetFeedIsHydratedAction()); + if (((FeedState)store.Features[nameof(FeedFeature)].GetState()) is { Identity: null }) + { + dispatch.Dispatch( + new CreateFeedIdentityAction( + Name: null, + ProfilePicture: null, + PublishBodyweight: false, + PublishPlan: false, + PublishWorkouts: false, + RedirectAfterCreation: null + ) + ); + } } catch (Exception e) { From 10eadb7cff96c266a2f8a1c2f1e9f69c7f45d750 Mon Sep 17 00:00:00 2001 From: Li Date: Sun, 30 Jun 2024 10:48:15 +1000 Subject: [PATCH 2/2] Add leading button --- LiftLog.Ui/Pages/Feed/FeedPage.razor | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/LiftLog.Ui/Pages/Feed/FeedPage.razor b/LiftLog.Ui/Pages/Feed/FeedPage.razor index 3e1b8eae..802d3249 100644 --- a/LiftLog.Ui/Pages/Feed/FeedPage.razor +++ b/LiftLog.Ui/Pages/Feed/FeedPage.razor @@ -39,8 +39,17 @@ } else { -
- Your details +
+ @if(!FeedState.Value.Identity.PublishWorkouts) + { +
+ You're not currently publishing your workouts for your friends to see. Tap to start! +
+ }else{ +
+ Your details +
+ }
}