From 9a98c1afb87e5f1d763662f02147d9b1988849fe Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 5 Mar 2024 10:25:54 +0500 Subject: [PATCH] notesnook: add support for user profile --- Notesnook.API/Interfaces/IUserService.cs | 1 + Notesnook.API/Models/Responses/UserResponse.cs | 3 +++ Notesnook.API/Models/UserSettings.cs | 1 + Notesnook.API/Services/UserService.cs | 9 +++++++++ 4 files changed, 14 insertions(+) diff --git a/Notesnook.API/Interfaces/IUserService.cs b/Notesnook.API/Interfaces/IUserService.cs index dc84d08..a4ce240 100644 --- a/Notesnook.API/Interfaces/IUserService.cs +++ b/Notesnook.API/Interfaces/IUserService.cs @@ -31,5 +31,6 @@ namespace Notesnook.API.Interfaces Task ResetUserAsync(string userId, bool removeAttachments); Task GetUserAsync(bool repair = true); Task SetUserAttachmentsKeyAsync(string userId, IEncrypted key); + Task SetUserProfileAsync(string userId, IEncrypted profile); } } \ No newline at end of file diff --git a/Notesnook.API/Models/Responses/UserResponse.cs b/Notesnook.API/Models/Responses/UserResponse.cs index 1b24e63..a2c11a2 100644 --- a/Notesnook.API/Models/Responses/UserResponse.cs +++ b/Notesnook.API/Models/Responses/UserResponse.cs @@ -15,6 +15,9 @@ namespace Notesnook.API.Models.Responses [JsonPropertyName("subscription")] public ISubscription Subscription { get; set; } + [JsonPropertyName("profile")] + public EncryptedData Profile { get; set; } + [JsonIgnore] public bool Success { get; set; } public int StatusCode { get; set; } diff --git a/Notesnook.API/Models/UserSettings.cs b/Notesnook.API/Models/UserSettings.cs index 885ec93..77675e6 100644 --- a/Notesnook.API/Models/UserSettings.cs +++ b/Notesnook.API/Models/UserSettings.cs @@ -34,6 +34,7 @@ namespace Notesnook.API.Models public string Salt { get; set; } public EncryptedData VaultKey { get; set; } public EncryptedData AttachmentsKey { get; set; } + public EncryptedData Profile { get; set; } [BsonId] [BsonRepresentation(BsonType.ObjectId)] diff --git a/Notesnook.API/Services/UserService.cs b/Notesnook.API/Services/UserService.cs index 0a30c1b..a36f6f0 100644 --- a/Notesnook.API/Services/UserService.cs +++ b/Notesnook.API/Services/UserService.cs @@ -153,6 +153,7 @@ namespace Notesnook.API.Services response.AttachmentsKey = userSettings.AttachmentsKey; response.Salt = userSettings.Salt; response.Subscription = subscription; + response.Profile = userSettings.Profile; return response; } @@ -163,6 +164,13 @@ namespace Notesnook.API.Services await Repositories.UsersSettings.UpdateAsync(userSettings.Id, userSettings); } + public async Task SetUserProfileAsync(string userId, IEncrypted profile) + { + var userSettings = await Repositories.UsersSettings.FindOneAsync((u) => u.UserId == userId); + userSettings.Profile = (EncryptedData)profile; + await Repositories.UsersSettings.UpdateAsync(userSettings.Id, userSettings); + } + public async Task DeleteUserAsync(string userId, string jti) { var cc = new CancellationTokenSource(); @@ -220,6 +228,7 @@ namespace Notesnook.API.Services userSettings.AttachmentsKey = null; userSettings.VaultKey = null; + userSettings.Profile = null; userSettings.LastSynced = 0; await Repositories.UsersSettings.UpsertAsync(userSettings, (s) => s.UserId == userId);