vassago/Models/Channel.cs

78 lines
2.6 KiB
C#
Raw Normal View History

2023-06-01 00:03:23 -04:00
namespace vassago.Models;
using System;
2023-06-01 00:03:23 -04:00
using System.Collections.Generic;
2023-06-05 14:55:48 -04:00
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
2023-06-01 00:03:23 -04:00
using System.Threading.Tasks;
using static vassago.Models.Enumerations;
2023-06-01 00:03:23 -04:00
public class Channel
{
2023-06-05 14:55:48 -04:00
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
2023-06-01 00:03:23 -04:00
public Guid Id { get; set; }
public string ExternalId { get; set; }
2023-06-01 00:03:23 -04:00
public string DisplayName { get; set; }
public ChannelPermissions Permissions { get; set; }
2023-06-05 14:55:48 -04:00
public List<Channel> SubChannels { get; set; }
2023-06-01 00:03:23 -04:00
public Channel ParentChannel { get; set; }
2023-06-05 14:55:48 -04:00
public string Protocol { get; set; }
public List<Message> Messages { get; set; }
2023-06-19 12:56:40 -04:00
public List<Account> Users { get; set; }
public ChannelType ChannelType {get; set; }
2023-06-01 00:03:23 -04:00
2023-06-05 14:55:48 -04:00
[NonSerialized]
public Func<string, string, Task> SendFile;
[NonSerialized]
public Func<string, Task> SendMessage;
2023-06-19 11:03:06 -04:00
public DefinitePermissionSettings EffectivePermissions
2023-06-19 11:03:06 -04:00
{
get
{
ChannelPermissions toReturn = Permissions ?? new ChannelPermissions();
return GetEffectivePermissions(ref toReturn).Definite();
2023-06-19 11:03:06 -04:00
}
}
private ChannelPermissions GetEffectivePermissions(ref ChannelPermissions settings)
2023-06-19 11:03:06 -04:00
{
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;
}
}
}
2023-06-05 14:55:48 -04:00
}