forked from adam/discord-bot-shtik
self referencing serialization ignored
Some checks failed
gitea.arg.rip/vassago/pipeline/head There was a failure building this commit
Some checks failed
gitea.arg.rip/vassago/pipeline/head There was a failure building this commit
This commit is contained in:
parent
53753374f0
commit
6881816c94
@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class Account
|
||||
@ -27,5 +28,6 @@ public class Account
|
||||
public bool IsBot { get; set; } //webhook counts
|
||||
public Channel SeenInChannel { get; set; }
|
||||
public string Protocol { get; set; }
|
||||
[JsonIgnore]
|
||||
public User IsUser {get; set;}
|
||||
}
|
@ -7,6 +7,7 @@ using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using static vassago.Models.Enumerations;
|
||||
|
||||
public class Channel
|
||||
@ -17,6 +18,7 @@ public class Channel
|
||||
public string DisplayName { get; set; }
|
||||
[DeleteBehavior(DeleteBehavior.Cascade)]
|
||||
public List<Channel> SubChannels { get; set; }
|
||||
[JsonIgnore]
|
||||
public Channel ParentChannel { get; set; }
|
||||
public string Protocol { get; set; }
|
||||
[DeleteBehavior(DeleteBehavior.Cascade)]
|
||||
@ -82,6 +84,23 @@ public class Channel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///break self-referencing loops for library-agnostic serialization
|
||||
///</summary>
|
||||
public Channel AsSerializable()
|
||||
{
|
||||
var toReturn = this.MemberwiseClone() as Channel;
|
||||
toReturn.ParentChannel = null;
|
||||
if(toReturn.Users?.Count > 0)
|
||||
{
|
||||
foreach (var account in toReturn.Users)
|
||||
{
|
||||
account.SeenInChannel = null;
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
public class DefinitePermissionSettings
|
||||
|
@ -11,7 +11,10 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddSingleton<IHostedService, vassago.ConsoleService>();
|
||||
builder.Services.AddDbContext<ChattingContext>();
|
||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||
builder.Services.AddControllers().AddNewtonsoftJson(options => {
|
||||
options.SerializerSettings.ReferenceLoopHandling =
|
||||
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
|
||||
});
|
||||
builder.Services.AddProblemDetails();
|
||||
builder.Services.Configure<RazorViewEngineOptions>(o => {
|
||||
o.ViewLocationFormats.Clear();
|
||||
|
@ -33,6 +33,10 @@ public class ChannelsController : ControllerBase
|
||||
{
|
||||
_logger.LogError($"attempt to update channel {channel.Id}, not found");
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogDebug($"patching {channel.DisplayName} (id: {channel.Id})");
|
||||
}
|
||||
//settable values: lewdness filter level, meanness filter level. maybe i could decorate them...
|
||||
fromDb.LewdnessFilterLevel = channel.LewdnessFilterLevel;
|
||||
|
Loading…
Reference in New Issue
Block a user