feat: rewrite database schema for localized autoproxy

This commit is contained in:
spiral
2022-03-21 23:43:33 -04:00
parent ca108813b7
commit 982812333b
16 changed files with 245 additions and 188 deletions

View File

@@ -0,0 +1,21 @@
using Newtonsoft.Json.Linq;
using NodaTime;
using SqlKata;
namespace PluralKit.Core;
public class AutoproxyPatch : PatchObject
{
public Partial<AutoproxyMode> AutoproxyMode { get; set; }
public Partial<MemberId?> AutoproxyMember { get; set; }
public Partial<Instant> LastLatchTimestamp { get; set; }
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("autoproxy_mode", AutoproxyMode)
.With("autoproxy_member", AutoproxyMember)
.With("last_latch_timestamp", LastLatchTimestamp)
);
}

View File

@@ -9,15 +9,11 @@ namespace PluralKit.Core;
public class SystemGuildPatch: PatchObject
{
public Partial<bool> ProxyEnabled { get; set; }
public Partial<AutoproxyMode> AutoproxyMode { get; set; }
public Partial<MemberId?> AutoproxyMember { get; set; }
public Partial<string?> Tag { get; set; }
public Partial<bool?> TagEnabled { get; set; }
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("proxy_enabled", ProxyEnabled)
.With("autoproxy_mode", AutoproxyMode)
.With("autoproxy_member", AutoproxyMember)
.With("tag", Tag)
.With("tag_enabled", TagEnabled)
);
@@ -29,24 +25,13 @@ public class SystemGuildPatch: PatchObject
}
#nullable disable
public static SystemGuildPatch FromJson(JObject o, MemberId? memberId)
public static SystemGuildPatch FromJson(JObject o)
{
var patch = new SystemGuildPatch();
if (o.ContainsKey("proxying_enabled") && o["proxying_enabled"].Type != JTokenType.Null)
patch.ProxyEnabled = o.Value<bool>("proxying_enabled");
if (o.ContainsKey("autoproxy_mode"))
{
var (val, err) = o["autoproxy_mode"].ParseAutoproxyMode();
if (err != null)
patch.Errors.Add(err);
else
patch.AutoproxyMode = val.Value;
}
patch.AutoproxyMember = memberId;
if (o.ContainsKey("tag"))
patch.Tag = o.Value<string>("tag").NullIfEmpty();
@@ -56,7 +41,7 @@ public class SystemGuildPatch: PatchObject
return patch;
}
public JObject ToJson(string memberRef, ulong guild_id)
public JObject ToJson(ulong guild_id)
{
var o = new JObject();
@@ -65,12 +50,6 @@ public class SystemGuildPatch: PatchObject
if (ProxyEnabled.IsPresent)
o.Add("proxying_enabled", ProxyEnabled.Value);
if (AutoproxyMode.IsPresent)
o.Add("autoproxy_mode", AutoproxyMode.Value.ToString().ToLower());
if (AutoproxyMember.IsPresent)
o.Add("autoproxy_member", memberRef);
if (Tag.IsPresent)
o.Add("tag", Tag.Value);