feat: proxy tag privacy (#571)

Merges PluralKit/PluralKit#571
This commit is contained in:
rladenson 2023-08-10 17:54:53 +12:00 committed by Iris System
parent 084df88624
commit 68cd21fb2f
8 changed files with 46 additions and 9 deletions

View file

@ -0,0 +1,7 @@
-- database version 37
-- add proxy tag privacy
alter table members add column proxy_privacy integer not null default 1;
alter table members add constraint members_proxy_privacy_check check (proxy_privacy = ANY (ARRAY[1,2]));
update info set schema_version = 37;

View file

@ -9,7 +9,7 @@ namespace PluralKit.Core;
internal class DatabaseMigrator
{
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
private const int TargetSchemaVersion = 36;
private const int TargetSchemaVersion = 37;
private readonly ILogger _logger;
public DatabaseMigrator(ILogger logger)

View file

@ -60,8 +60,8 @@ public class PKMember
public PrivacyLevel NamePrivacy { get; private set; } //ignore setting if no display name is set
public PrivacyLevel BirthdayPrivacy { get; private set; }
public PrivacyLevel PronounPrivacy { get; private set; }
public PrivacyLevel MetadataPrivacy { get; private set; }
public PrivacyLevel ProxyPrivacy { get; private set; }
// public PrivacyLevel ColorPrivacy { get; private set; }
/// Returns a formatted string representing the member's birthday, taking into account that a year of "0001" or "0004" is hidden
@ -144,8 +144,11 @@ public static class PKMemberExt
o.Add("last_message_timestamp", member.LastMessageTimestampFor(ctx)?.FormatExport());
var tagArray = new JArray();
foreach (var tag in member.ProxyTags)
tagArray.Add(new JObject { { "prefix", tag.Prefix }, { "suffix", tag.Suffix } });
if (member.ProxyPrivacy.CanAccess(ctx))
{
foreach (var tag in member.ProxyTags)
tagArray.Add(new JObject { { "prefix", tag.Prefix }, { "suffix", tag.Suffix } });
}
o.Add("proxy_tags", tagArray);
if (includePrivacy)
@ -159,6 +162,7 @@ public static class PKMemberExt
p.Add("pronoun_privacy", member.PronounPrivacy.ToJsonString());
p.Add("avatar_privacy", member.AvatarPrivacy.ToJsonString());
p.Add("metadata_privacy", member.MetadataPrivacy.ToJsonString());
p.Add("proxy_privacy", member.ProxyPrivacy.ToJsonString());
o.Add("privacy", p);
}

View file

@ -29,8 +29,10 @@ public class MemberPatch: PatchObject
public Partial<PrivacyLevel> PronounPrivacy { get; set; }
public Partial<PrivacyLevel> BirthdayPrivacy { get; set; }
public Partial<PrivacyLevel> AvatarPrivacy { get; set; }
public Partial<PrivacyLevel> ProxyPrivacy { get; set; }
public Partial<PrivacyLevel> MetadataPrivacy { get; set; }
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("name", Name)
.With("hid", Hid)
@ -52,6 +54,7 @@ public class MemberPatch: PatchObject
.With("pronoun_privacy", PronounPrivacy)
.With("birthday_privacy", BirthdayPrivacy)
.With("avatar_privacy", AvatarPrivacy)
.With("proxy_privacy", ProxyPrivacy)
.With("metadata_privacy", MetadataPrivacy)
);
@ -140,6 +143,8 @@ public class MemberPatch: PatchObject
patch.BirthdayPrivacy = patch.ParsePrivacy(o, "birthday_privacy");
if (o.ContainsKey("pronoun_privacy"))
patch.PronounPrivacy = patch.ParsePrivacy(o, "pronoun_privacy");
if (o.ContainsKey("proxy_privacy"))
patch.ProxyPrivacy = patch.ParsePrivacy(o, "proxy_privacy");
if (o.ContainsKey("metadata_privacy"))
patch.MetadataPrivacy = patch.ParsePrivacy(o, "metadata_privacy");
}
@ -173,6 +178,9 @@ public class MemberPatch: PatchObject
if (privacy.ContainsKey("pronoun_privacy"))
patch.PronounPrivacy = patch.ParsePrivacy(privacy, "pronoun_privacy");
if (privacy.ContainsKey("proxy_privacy"))
patch.ProxyPrivacy = patch.ParsePrivacy(privacy, "proxy_privacy");
if (privacy.ContainsKey("metadata_privacy"))
patch.MetadataPrivacy = patch.ParsePrivacy(privacy, "metadata_privacy");
}
@ -222,6 +230,7 @@ public class MemberPatch: PatchObject
|| PronounPrivacy.IsPresent
|| BirthdayPrivacy.IsPresent
|| AvatarPrivacy.IsPresent
|| ProxyPrivacy.IsPresent
|| MetadataPrivacy.IsPresent
)
{
@ -245,6 +254,9 @@ public class MemberPatch: PatchObject
if (AvatarPrivacy.IsPresent)
p.Add("avatar_privacy", AvatarPrivacy.Value.ToJsonString());
if (ProxyPrivacy.IsPresent)
p.Add("proxy_privacy", ProxyPrivacy.Value.ToJsonString());
if (MetadataPrivacy.IsPresent)
p.Add("metadata_privacy", MetadataPrivacy.Value.ToJsonString());

View file

@ -8,6 +8,7 @@ public enum MemberPrivacySubject
Avatar,
Birthday,
Pronouns,
Proxy,
Metadata
}
@ -24,6 +25,7 @@ public static class MemberPrivacyUtils
MemberPrivacySubject.Pronouns => member.PronounPrivacy = level,
MemberPrivacySubject.Birthday => member.BirthdayPrivacy = level,
MemberPrivacySubject.Metadata => member.MetadataPrivacy = level,
MemberPrivacySubject.Proxy => member.ProxyPrivacy = level,
MemberPrivacySubject.Visibility => member.Visibility = level,
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
};
@ -73,6 +75,12 @@ public static class MemberPrivacyUtils
case "created":
subject = MemberPrivacySubject.Metadata;
break;
case "proxy":
case "proxies":
case "tag":
case "tags":
subject = MemberPrivacySubject.Proxy;
break;
case "visibility":
case "hidden":
case "shown":