using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Iceshrimp.Backend.Core.Database.Tables; [Table("oauth_token")] [Index(nameof(Token))] [Index(nameof(Code))] public class OauthToken { [Key] [Column("id")] [StringLength(32)] public string Id { get; set; } = null!; /// /// The created date of the OAuth token /// [Column("createdAt")] public DateTime CreatedAt { get; set; } [Column("appId")] [StringLength(32)] public string AppId { get; set; } = null!; [Column("userId")] [StringLength(32)] public string UserId { get; set; } = null!; /// /// The auth code for the OAuth token /// [Column("code")] [StringLength(64)] public string Code { get; set; } = null!; /// /// The OAuth token /// [Column("token")] [StringLength(64)] public string Token { get; set; } = null!; /// /// Whether or not the token has been activated /// [Column("active")] public bool Active { get; set; } /// /// The scopes requested by the OAuth token /// [Column("scopes", TypeName = "character varying(64)[]")] public List Scopes { get; set; } = null!; /// /// The redirect URI of the OAuth token /// [Column("redirectUri")] [StringLength(512)] public string RedirectUri { get; set; } = null!; [ForeignKey(nameof(AppId))] [InverseProperty(nameof(OauthApp.OauthTokens))] public virtual OauthApp App { get; set; } = null!; [ForeignKey(nameof(UserId))] [InverseProperty(nameof(Tables.User.OauthTokens))] public virtual User User { get; set; } = null!; [InverseProperty(nameof(Tables.PushSubscription.OauthToken))] public virtual PushSubscription? PushSubscription { get; set; } [Column("supportsHtmlFormatting")] public bool SupportsHtmlFormatting { get; set; } [Column("autoDetectQuotes")] public bool AutoDetectQuotes { get; set; } [Column("isPleroma")] public bool IsPleroma { get; set; } [Column("lastActiveDate")] public DateTime? LastActiveDate { get; set; } private class EntityTypeConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder entity) { entity.Property(e => e.Active).HasComment("Whether or not the token has been activated"); entity.Property(e => e.Code).HasComment("The auth code for the OAuth token"); entity.Property(e => e.CreatedAt).HasComment("The created date of the OAuth token"); entity.Property(e => e.RedirectUri).HasComment("The redirect URI of the OAuth token"); entity.Property(e => e.Scopes).HasComment("The scopes requested by the OAuth token"); entity.Property(e => e.Token).HasComment("The OAuth token"); entity.Property(e => e.SupportsHtmlFormatting) .HasComment("Whether the client supports HTML inline formatting (bold, italic, strikethrough, ...)") .HasDefaultValue(true); entity.Property(e => e.AutoDetectQuotes) .HasComment("Whether the backend should automatically detect quote posts coming from this client") .HasDefaultValue(true); entity.Property(e => e.IsPleroma) .HasComment("Whether Pleroma or Akkoma specific behavior should be enabled for this client") .HasDefaultValue(false); entity.HasOne(d => d.App) .WithMany(p => p.OauthTokens) .OnDelete(DeleteBehavior.Cascade); entity.HasOne(d => d.User) .WithMany(p => p.OauthTokens) .OnDelete(DeleteBehavior.Cascade); } } }