|
| 1 | +// Copyright (C) 2024-2025 ZenonEl |
| 2 | +// This program is free software: you can redistribute it and/or modify |
| 3 | +// it under the terms of the GNU Affero General Public License as published |
| 4 | +// by the Free Software Foundation, either version 3 of the License, or |
| 5 | +// (at your option) any later version. |
| 6 | + |
| 7 | +// Эта программа является свободным программным обеспечением: вы можете распространять и/или изменять |
| 8 | +// её на условиях Стандартной общественной лицензии GNU Affero, опубликованной |
| 9 | +// Фондом свободного программного обеспечения, либо версии 3 лицензии, либо |
| 10 | +// (по вашему выбору) любой более поздней версии. |
| 11 | + |
| 12 | +using System.Text.Json; |
| 13 | +using System.Text.Json.Serialization; |
| 14 | + |
| 15 | +namespace TelegramMediaRelayBot.Domain.Models; |
| 16 | + |
| 17 | +public sealed class UserSettings |
| 18 | +{ |
| 19 | + public DistributionSettings Distribution { get; set; } = new(); |
| 20 | + public PrivacyUserSettings Privacy { get; set; } = new(); |
| 21 | + |
| 22 | + private static readonly JsonSerializerOptions JsonOptions = new() |
| 23 | + { |
| 24 | + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, |
| 25 | + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault |
| 26 | + }; |
| 27 | + |
| 28 | + public string ToJson() => JsonSerializer.Serialize(this, JsonOptions); |
| 29 | + |
| 30 | + public static UserSettings FromJson(string json) |
| 31 | + { |
| 32 | + if (string.IsNullOrWhiteSpace(json)) return new(); |
| 33 | + try { return JsonSerializer.Deserialize<UserSettings>(json, JsonOptions) ?? new(); } |
| 34 | + catch { return new(); } |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +public sealed class DistributionSettings |
| 39 | +{ |
| 40 | + public string DefaultAction { get; set; } = "send_only_to_me"; |
| 41 | + public string DefaultActionCondition { get; set; } = ""; |
| 42 | + public int AutoSendDelaySeconds { get; set; } = 30; |
| 43 | + public List<int> TargetGroupIds { get; set; } = []; |
| 44 | + public List<int> TargetContactIds { get; set; } = []; |
| 45 | +} |
| 46 | + |
| 47 | +public sealed class PrivacyUserSettings |
| 48 | +{ |
| 49 | + public bool InboxEnabled { get; set; } = false; |
| 50 | + public bool AllowContentForwarding { get; set; } = true; |
| 51 | + public string WhoCanFindMe { get; set; } = "everyone"; |
| 52 | + public SiteFilterSettings SiteFilter { get; set; } = new(); |
| 53 | +} |
| 54 | + |
| 55 | +public sealed class SiteFilterSettings |
| 56 | +{ |
| 57 | + public bool Enabled { get; set; } = false; |
| 58 | + public string FilterType { get; set; } = "none"; |
| 59 | + public List<string> BlockedDomains { get; set; } = []; |
| 60 | +} |
0 commit comments