2024-12-09 21:11:46 +01:00
|
|
|
// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions)
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2024-12-14 16:51:58 +01:00
|
|
|
|
|
|
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
2024-07-13 03:09:00 +02:00
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2024-08-22 15:13:46 +02:00
|
|
|
using Foxnouns.Backend.Utils;
|
|
|
|
using Newtonsoft.Json;
|
2024-07-13 03:09:00 +02:00
|
|
|
using NodaTime;
|
2024-07-12 17:12:24 +02:00
|
|
|
|
2024-05-27 15:53:54 +02:00
|
|
|
namespace Foxnouns.Backend.Database.Models;
|
|
|
|
|
|
|
|
public class User : BaseModel
|
|
|
|
{
|
|
|
|
public required string Username { get; set; }
|
2024-09-26 15:08:08 +02:00
|
|
|
public string Sid { get; set; } = string.Empty;
|
2024-12-25 17:19:50 +01:00
|
|
|
public required string LegacyId { get; init; }
|
2024-05-27 15:53:54 +02:00
|
|
|
public string? DisplayName { get; set; }
|
|
|
|
public string? Bio { get; set; }
|
|
|
|
public string? MemberTitle { get; set; }
|
|
|
|
public string? Avatar { get; set; }
|
|
|
|
public string[] Links { get; set; } = [];
|
2024-05-28 17:09:50 +02:00
|
|
|
public bool ListHidden { get; set; }
|
2024-11-24 22:19:53 +01:00
|
|
|
public string? Timezone { get; set; }
|
2024-05-27 15:53:54 +02:00
|
|
|
|
|
|
|
public List<FieldEntry> Names { get; set; } = [];
|
|
|
|
public List<Pronoun> Pronouns { get; set; } = [];
|
|
|
|
public List<Field> Fields { get; set; } = [];
|
2024-08-22 15:13:46 +02:00
|
|
|
public Dictionary<Snowflake, CustomPreference> CustomPreferences { get; set; } = [];
|
2024-05-27 15:53:54 +02:00
|
|
|
|
2024-09-26 20:15:04 +02:00
|
|
|
public List<PrideFlag> Flags { get; set; } = [];
|
|
|
|
public List<UserFlag> ProfileFlags { get; set; } = [];
|
|
|
|
|
2024-05-27 15:53:54 +02:00
|
|
|
public UserRole Role { get; set; } = UserRole.User;
|
2024-06-04 17:38:59 +02:00
|
|
|
public string? Password { get; set; } // Password may be null if the user doesn't authenticate with an email address
|
2024-05-27 15:53:54 +02:00
|
|
|
|
|
|
|
public List<Member> Members { get; } = [];
|
|
|
|
public List<AuthMethod> AuthMethods { get; } = [];
|
2024-12-03 14:55:19 +01:00
|
|
|
public List<DataExport> DataExports { get; } = [];
|
2024-09-05 22:17:10 +02:00
|
|
|
public UserSettings Settings { get; set; } = new();
|
2024-07-13 03:09:00 +02:00
|
|
|
|
|
|
|
public required Instant LastActive { get; set; }
|
2024-09-26 15:08:08 +02:00
|
|
|
public Instant LastSidReroll { get; set; }
|
2024-07-13 03:09:00 +02:00
|
|
|
|
|
|
|
public bool Deleted { get; set; }
|
|
|
|
public Instant? DeletedAt { get; set; }
|
|
|
|
public Snowflake? DeletedBy { get; set; }
|
2024-10-02 00:28:07 +02:00
|
|
|
|
|
|
|
[NotMapped]
|
|
|
|
public bool? SelfDelete => Deleted ? DeletedBy != null : null;
|
2024-08-22 15:13:46 +02:00
|
|
|
|
|
|
|
public class CustomPreference
|
|
|
|
{
|
|
|
|
public required string Icon { get; set; }
|
|
|
|
public required string Tooltip { get; set; }
|
|
|
|
public bool Muted { get; set; }
|
|
|
|
public bool Favourite { get; set; }
|
2024-09-04 14:25:44 +02:00
|
|
|
|
2024-08-22 15:13:46 +02:00
|
|
|
// This type is generally serialized directly, so the converter is applied here.
|
|
|
|
[JsonConverter(typeof(ScreamingSnakeCaseEnumConverter))]
|
|
|
|
public PreferenceSize Size { get; set; }
|
2024-12-25 17:19:50 +01:00
|
|
|
|
|
|
|
public Guid LegacyId { get; init; } = Guid.NewGuid();
|
2024-08-22 15:13:46 +02:00
|
|
|
}
|
2024-12-03 14:55:19 +01:00
|
|
|
|
|
|
|
public static readonly Duration DeleteAfter = Duration.FromDays(30);
|
|
|
|
public static readonly Duration DeleteSuspendedAfter = Duration.FromDays(180);
|
2024-05-27 15:53:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum UserRole
|
|
|
|
{
|
|
|
|
User,
|
|
|
|
Moderator,
|
|
|
|
Admin,
|
2024-08-22 15:13:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum PreferenceSize
|
|
|
|
{
|
|
|
|
Large,
|
|
|
|
Normal,
|
|
|
|
Small,
|
2024-09-05 22:17:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public class UserSettings
|
|
|
|
{
|
2024-12-14 16:51:58 +01:00
|
|
|
public bool? DarkMode { get; set; }
|
2024-10-02 00:28:07 +02:00
|
|
|
}
|