namespace vassago.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Reflection; using System.Threading.Tasks; using static vassago.Models.Enumerations; public class Channel { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public string ExternalId { get; set; } public string DisplayName { get; set; } public ChannelPermissions Permissions { get; set; } public List SubChannels { get; set; } public Channel ParentChannel { get; set; } public string Protocol { get; set; } public List Messages { get; set; } public List Users { get; set; } public ChannelType ChannelType {get; set; } [NonSerialized] public Func SendFile; [NonSerialized] public Func SendMessage; public DefinitePermissionSettings EffectivePermissions { get { ChannelPermissions toReturn = Permissions ?? new ChannelPermissions(); return GetEffectivePermissions(ref toReturn).Definite(); } } private ChannelPermissions GetEffectivePermissions(ref ChannelPermissions settings) { if(settings == null) throw new ArgumentNullException(); settings.LewdnessFilterLevel = settings.LewdnessFilterLevel ?? Permissions?.LewdnessFilterLevel; settings.MeannessFilterLevel = settings.MeannessFilterLevel ?? Permissions?.MeannessFilterLevel; settings.LinksAllowed = settings.LinksAllowed ?? Permissions?.LinksAllowed; settings.MaxAttachmentBytes = settings.MaxAttachmentBytes ?? Permissions?.MaxAttachmentBytes; settings.MaxTextChars = settings.MaxTextChars ?? Permissions?.MaxTextChars; settings.ReactionsPossible = settings.ReactionsPossible ?? Permissions?.ReactionsPossible; if(this.ParentChannel != null && (settings.LewdnessFilterLevel == null || settings.MeannessFilterLevel == null || settings.LinksAllowed == null || settings.MaxAttachmentBytes == null || settings.MaxTextChars == null || settings.ReactionsPossible == null)) { return this.ParentChannel.GetEffectivePermissions(ref settings); } else { return settings; } } public string LineageSummary { get { if(this.ParentChannel != null) { return this.ParentChannel.LineageSummary + '/' + this.DisplayName; } else { return this.Protocol; } } } }