#nullable enable using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using API.Entities.Enums; using API.Entities.Interfaces; using API.Entities.Progress; using API.Entities.Scrobble; using API.Entities.User; using API.Helpers; using Microsoft.AspNetCore.Identity; namespace API.Entities; public class AppUser : IdentityUser, IHasConcurrencyToken, IHasCoverImage { public DateTime Created { get; set; } = DateTime.Now; public DateTime CreatedUtc { get; set; } = DateTime.UtcNow; public DateTime LastActive { get; set; } public DateTime LastActiveUtc { get; set; } public ICollection Libraries { get; set; } = null!; public ICollection UserRoles { get; set; } = null!; public ICollection Progresses { get; set; } = null!; public ICollection ReadingSessions { get; set; } = null!; public ICollection ReadingHistory { get; set; } = null!; public ICollection Ratings { get; set; } = null!; public ICollection ChapterRatings { get; set; } = null!; public AppUserPreferences UserPreferences { get; set; } = null!; public ICollection ReadingProfiles { get; set; } = null!; public ICollection ClientDevices { get; set; } = null!; /// /// Bookmarks associated with this User /// public ICollection Bookmarks { get; set; } = null!; /// /// Reading lists associated with this user /// public ICollection ReadingLists { get; set; } = null!; /// /// Collections associated with this user /// public ICollection Collections { get; set; } = null!; /// /// A list of Series the user want's to read /// public ICollection WantToRead { get; set; } = null!; /// /// A list of Devices which allows the user to send files to /// public ICollection Devices { get; set; } = null!; /// /// A list of Table of Contents for a given Chapter /// public ICollection TableOfContents { get; set; } = null!; public ICollection Annotations { get; set; } = null!; /// /// An API Key to interact with external services, like OPDS /// [Obsolete("Migrated to AuthKey in v0.8.9")] public string? ApiKey { get; set; } /// /// The confirmation token for the user (invite). This will be set to null after the user confirms. /// public string? ConfirmationToken { get; set; } /// /// The highest age rating the user has access to. Not applicable for admins /// public AgeRating AgeRestriction { get; set; } = AgeRating.NotApplicable; /// /// If an age rating restriction is applied to the account, if Unknowns should be allowed for the user. Defaults to false. /// public bool AgeRestrictionIncludeUnknowns { get; set; } = false; /// /// The JWT for the user's AniList account. Expires after a year. /// /// Requires Kavita+ Subscription public string? AniListAccessToken { get; set; } /// /// The Username of the MAL user /// public string? MalUserName { get; set; } /// /// The Client ID for the user's MAL account. User should create a client on MAL for this. /// public string? MalAccessToken { get; set; } /// /// Has the user ran Scrobble Event Generation /// /// Only applicable for Kavita+ and when a Token is present public bool HasRunScrobbleEventGeneration { get; set; } /// /// The timestamp of when Scrobble Event Generation ran (Utc) /// /// Kavita+ only public DateTime ScrobbleEventGenerationRan { get; set; } /// /// The sub returned the by OIDC provider /// public string? OidcId { get; set; } /// /// The IdentityProvider for the user, default to /// public IdentityProvider IdentityProvider { get; set; } = IdentityProvider.Kavita; public string? CoverImage { get; set; } public string? PrimaryColor { get; set; } public string? SecondaryColor { get; set; } /// /// A list of Series the user doesn't want scrobbling for /// public ICollection ScrobbleHolds { get; set; } = null!; /// /// A collection of user Smart Filters for their account /// public ICollection SmartFilters { get; set; } = null!; /// /// An ordered list of Streams (pre-configured) or Smart Filters that makes up the User's Dashboard /// public IList DashboardStreams { get; set; } = null!; /// /// An ordered list of Streams (pre-configured) or Smart Filters that makes up the User's SideNav /// public IList SideNavStreams { get; set; } = null!; public IList ExternalSources { get; set; } = null!; /// /// Auth keys for access to Kavita /// public ICollection AuthKeys { get; set; } = null!; /// [ConcurrencyCheck] public uint RowVersion { get; private set; } /// public void OnSavingChanges() { RowVersion++; } public void UpdateLastActive() { LastActive = DateTime.Now; LastActiveUtc = DateTime.UtcNow; } public void ResetColorScape() { PrimaryColor = string.Empty; SecondaryColor = string.Empty; } public string GetOpdsAuthKey() { if (AuthKeys == null || AuthKeys.Count == 0) { throw new ArgumentNullException("AuthKeys not loaded"); } return AuthKeys.Where(k => k.Name == AuthKeyHelper.OpdsKeyName).Select(k => k.Key).First(); } }