diff --git a/src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs b/src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs index 45a6db2ca6..6cb665a0f7 100644 --- a/src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs +++ b/src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs @@ -809,29 +809,29 @@ public class CipherRepository : Repository archives; - if (string.IsNullOrWhiteSpace(cipher.Archives)) - { - archives = new Dictionary(); - } - else - { - archives = JsonSerializer.Deserialize>(cipher.Archives) - ?? new Dictionary(); - } + // Build or load the per-user archives map + var archives = string.IsNullOrWhiteSpace(cipher.Archives) + ? new Dictionary() + : CoreHelpers.LoadClassFromJsonData>(cipher.Archives) + ?? new Dictionary(); if (action == CipherStateAction.Unarchive) { + // Remove this user's archive record archives.Remove(userId); + cipher.ArchivedDate = null; } else if (action == CipherStateAction.Archive) { + // Set this user's archive date archives[userId] = utcNow; + cipher.ArchivedDate = utcNow; } + // Persist the updated JSON or clear it if empty cipher.Archives = archives.Count == 0 ? null - : JsonSerializer.Serialize(archives); + : CoreHelpers.ClassToJsonData(archives); cipher.RevisionDate = utcNow; });