vassago/Models/Channel.cs

91 lines
3.1 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 Microsoft.AspNetCore.Components.Web;
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; }
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
//Permissions
public ulong? MaxAttachmentBytes { get; set; }
public uint? MaxTextChars { get; set; }
public bool? LinksAllowed { get; set; }
public bool? ReactionsPossible { get; set; }
public Enumerations.LewdnessFilterLevel? LewdnessFilterLevel { get; set; }
public Enumerations.MeannessFilterLevel? MeannessFilterLevel { get; set; }
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
{
var path = new Stack<Channel>(); //omg i actually get to use a data structure from university
var walker = this;
path.Push(this);
while(walker.ParentChannel != null)
{
walker = walker.ParentChannel;
path.Push(walker);
}
DefinitePermissionSettings toReturn = new DefinitePermissionSettings();
while(path.Count > 0)
{
walker = path.Pop();
toReturn.LewdnessFilterLevel = walker.LewdnessFilterLevel ?? toReturn.LewdnessFilterLevel;
toReturn.MeannessFilterLevel = walker.MeannessFilterLevel ?? toReturn.MeannessFilterLevel;
toReturn.LinksAllowed = walker.LinksAllowed ?? toReturn.LinksAllowed;
toReturn.MaxAttachmentBytes = walker.MaxAttachmentBytes ?? toReturn.MaxAttachmentBytes;
toReturn.MaxTextChars = walker.MaxTextChars ?? toReturn.MaxTextChars;
toReturn.ReactionsPossible = walker.ReactionsPossible ?? toReturn.ReactionsPossible;
}
return toReturn;
2023-06-19 11:03:06 -04:00
}
}
public string LineageSummary
{
get
{
if(this.ParentChannel != null)
{
return this.ParentChannel.LineageSummary + '/' + this.DisplayName;
}
else
{
return this.Protocol;
}
}
}
}
public class DefinitePermissionSettings
{
public ulong MaxAttachmentBytes { get; set; }
public uint MaxTextChars { get; set; }
public bool LinksAllowed { get; set; }
public bool ReactionsPossible { get; set; }
public Enumerations.LewdnessFilterLevel LewdnessFilterLevel { get; set; }
public Enumerations.MeannessFilterLevel MeannessFilterLevel { get; set; }
2023-06-05 14:55:48 -04:00
}