From f3bfe0957bd8dca4f0d663232251d62e47da4584 Mon Sep 17 00:00:00 2001 From: 01zulfi <85733202+01zulfi@users.noreply.github.com> Date: Thu, 14 May 2026 11:20:17 +0500 Subject: [PATCH] inbox: create InboxItemsHistory synced collection (#96) --- Notesnook.API/Accessors/SyncItemsRepositoryAccessor.cs | 4 ++++ Notesnook.API/Constants.cs | 1 + Notesnook.API/Controllers/InboxController.cs | 1 + Notesnook.API/Hubs/SyncV2Hub.cs | 3 +++ Notesnook.API/Interfaces/ISyncItemsRepositoryAccessor.cs | 1 + Notesnook.API/Services/UserService.cs | 2 ++ Notesnook.API/Startup.cs | 3 ++- 7 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Notesnook.API/Accessors/SyncItemsRepositoryAccessor.cs b/Notesnook.API/Accessors/SyncItemsRepositoryAccessor.cs index d672500..727a394 100644 --- a/Notesnook.API/Accessors/SyncItemsRepositoryAccessor.cs +++ b/Notesnook.API/Accessors/SyncItemsRepositoryAccessor.cs @@ -42,6 +42,7 @@ namespace Notesnook.API.Accessors public SyncItemsRepository Colors { get; } public SyncItemsRepository Vaults { get; } public SyncItemsRepository Tags { get; } + public SyncItemsRepository InboxItemsHistory { get; } public Repository UsersSettings { get; } public Repository Monographs { get; } public Repository InboxApiKey { get; } @@ -75,6 +76,8 @@ namespace Notesnook.API.Accessors IMongoCollection vaults, [FromKeyedServices(Collections.TagsKey)] IMongoCollection tags, + [FromKeyedServices(Collections.InboxItemsHistoryKey)] + IMongoCollection inboxItemsHistory, Repository usersSettings, Repository monographs, @@ -102,6 +105,7 @@ namespace Notesnook.API.Accessors Colors = new SyncItemsRepository(dbContext, colors, logger); Vaults = new SyncItemsRepository(dbContext, vaults, logger); Tags = new SyncItemsRepository(dbContext, tags, logger); + InboxItemsHistory = new SyncItemsRepository(dbContext, inboxItemsHistory, logger); } } } \ No newline at end of file diff --git a/Notesnook.API/Constants.cs b/Notesnook.API/Constants.cs index c220118..a988aec 100644 --- a/Notesnook.API/Constants.cs +++ b/Notesnook.API/Constants.cs @@ -18,5 +18,6 @@ namespace Notesnook.API public const string InboxApiKeysKey = "inbox_api_keys"; public const string SyncDevicesKey = "sync_devices"; public const string DeviceIdsChunksKey = "device_ids_chunks"; + public const string InboxItemsHistoryKey = "inbox_items_history"; } } \ No newline at end of file diff --git a/Notesnook.API/Controllers/InboxController.cs b/Notesnook.API/Controllers/InboxController.cs index 17603c3..5cff13e 100644 --- a/Notesnook.API/Controllers/InboxController.cs +++ b/Notesnook.API/Controllers/InboxController.cs @@ -18,6 +18,7 @@ along with this program. If not, see . */ using System; +using System.Collections.Generic; using System.Security.Claims; using System.Text.Json; using System.Threading.Tasks; diff --git a/Notesnook.API/Hubs/SyncV2Hub.cs b/Notesnook.API/Hubs/SyncV2Hub.cs index 74150f0..5ec6aa4 100644 --- a/Notesnook.API/Hubs/SyncV2Hub.cs +++ b/Notesnook.API/Hubs/SyncV2Hub.cs @@ -68,6 +68,7 @@ namespace Notesnook.API.Hubs "color", "tag", "vault", + "inboxitemhistory", "relation", // relations must sync at the end to prevent invalid state ]; private readonly FrozenDictionary, string, long>> UpsertActionsMap; @@ -92,6 +93,7 @@ namespace Notesnook.API.Hubs Repositories.Colors.FindItemsById, Repositories.Tags.FindItemsById, Repositories.Vaults.FindItemsById, + Repositories.InboxItemsHistory.FindItemsById, Repositories.Relations.FindItemsById, ]; UpsertActionsMap = new Dictionary, string, long>> { @@ -106,6 +108,7 @@ namespace Notesnook.API.Hubs { "color", Repositories.Colors.UpsertMany }, { "vault", Repositories.Vaults.UpsertMany }, { "tag", Repositories.Tags.UpsertMany }, + { "inboxitemhistory", Repositories.InboxItemsHistory.UpsertMany }, }.ToFrozenDictionary(); } diff --git a/Notesnook.API/Interfaces/ISyncItemsRepositoryAccessor.cs b/Notesnook.API/Interfaces/ISyncItemsRepositoryAccessor.cs index 80611df..0d9657f 100644 --- a/Notesnook.API/Interfaces/ISyncItemsRepositoryAccessor.cs +++ b/Notesnook.API/Interfaces/ISyncItemsRepositoryAccessor.cs @@ -38,6 +38,7 @@ namespace Notesnook.API.Interfaces SyncItemsRepository Colors { get; } SyncItemsRepository Vaults { get; } SyncItemsRepository Tags { get; } + SyncItemsRepository InboxItemsHistory { get; } Repository UsersSettings { get; } Repository Monographs { get; } Repository InboxApiKey { get; } diff --git a/Notesnook.API/Services/UserService.cs b/Notesnook.API/Services/UserService.cs index c9e2c24..a06f81f 100644 --- a/Notesnook.API/Services/UserService.cs +++ b/Notesnook.API/Services/UserService.cs @@ -199,6 +199,7 @@ namespace Notesnook.API.Services Repositories.Colors.DeleteByUserId(userId); Repositories.Tags.DeleteByUserId(userId); Repositories.Vaults.DeleteByUserId(userId); + Repositories.InboxItemsHistory.DeleteByUserId(userId); Repositories.UsersSettings.Delete((u) => u.UserId == userId); Repositories.Monographs.DeleteMany((m) => m.UserId == userId); Repositories.InboxApiKey.DeleteMany((t) => t.UserId == userId); @@ -260,6 +261,7 @@ namespace Notesnook.API.Services Repositories.Colors.DeleteByUserId(userId); Repositories.Tags.DeleteByUserId(userId); Repositories.Vaults.DeleteByUserId(userId); + Repositories.InboxItemsHistory.DeleteByUserId(userId); Repositories.Monographs.DeleteMany((m) => m.UserId == userId); Repositories.InboxApiKey.DeleteMany((t) => t.UserId == userId); if (!await unit.Commit()) return false; diff --git a/Notesnook.API/Startup.cs b/Notesnook.API/Startup.cs index f294b42..4a9e5ea 100644 --- a/Notesnook.API/Startup.cs +++ b/Notesnook.API/Startup.cs @@ -197,7 +197,8 @@ namespace Notesnook.API .AddMongoCollection(Collections.ColorsKey) .AddMongoCollection(Collections.VaultsKey) .AddMongoCollection(Collections.InboxItemsKey) - .AddMongoCollection(Collections.InboxApiKeysKey); + .AddMongoCollection(Collections.InboxApiKeysKey) + .AddMongoCollection(Collections.InboxItemsHistoryKey); services.AddScoped(); services.AddScoped();