2020-07-18 11:53:02 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PluralKit.Core
|
|
|
|
|
{
|
|
|
|
|
public enum GroupPrivacySubject
|
|
|
|
|
{
|
|
|
|
|
Description,
|
|
|
|
|
Icon,
|
2020-08-20 19:43:17 +00:00
|
|
|
|
List,
|
2020-07-18 11:53:02 +00:00
|
|
|
|
Visibility
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class GroupPrivacyUtils
|
|
|
|
|
{
|
|
|
|
|
public static GroupPatch WithPrivacy(this GroupPatch group, GroupPrivacySubject subject, PrivacyLevel level)
|
|
|
|
|
{
|
|
|
|
|
// what do you mean switch expressions can't be statements >.>
|
|
|
|
|
_ = subject switch
|
|
|
|
|
{
|
|
|
|
|
GroupPrivacySubject.Description => group.DescriptionPrivacy = level,
|
|
|
|
|
GroupPrivacySubject.Icon => group.IconPrivacy = level,
|
2020-08-20 19:43:17 +00:00
|
|
|
|
GroupPrivacySubject.List => group.ListPrivacy = level,
|
2020-07-18 11:53:02 +00:00
|
|
|
|
GroupPrivacySubject.Visibility => group.Visibility = level,
|
|
|
|
|
_ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GroupPatch WithAllPrivacy(this GroupPatch member, PrivacyLevel level)
|
|
|
|
|
{
|
|
|
|
|
foreach (var subject in Enum.GetValues(typeof(GroupPrivacySubject)))
|
|
|
|
|
member.WithPrivacy((GroupPrivacySubject) subject, level);
|
|
|
|
|
return member;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool TryParseGroupPrivacy(string input, out GroupPrivacySubject subject)
|
|
|
|
|
{
|
|
|
|
|
switch (input.ToLowerInvariant())
|
|
|
|
|
{
|
|
|
|
|
case "description":
|
|
|
|
|
case "desc":
|
|
|
|
|
case "text":
|
|
|
|
|
case "info":
|
|
|
|
|
subject = GroupPrivacySubject.Description;
|
|
|
|
|
break;
|
|
|
|
|
case "avatar":
|
|
|
|
|
case "pfp":
|
|
|
|
|
case "pic":
|
|
|
|
|
case "icon":
|
|
|
|
|
subject = GroupPrivacySubject.Icon;
|
|
|
|
|
break;
|
|
|
|
|
case "visibility":
|
|
|
|
|
case "hidden":
|
|
|
|
|
case "shown":
|
|
|
|
|
case "visible":
|
|
|
|
|
subject = GroupPrivacySubject.Visibility;
|
|
|
|
|
break;
|
2020-08-20 19:43:17 +00:00
|
|
|
|
case "list":
|
|
|
|
|
case "listing":
|
|
|
|
|
case "members":
|
|
|
|
|
subject = GroupPrivacySubject.List;
|
|
|
|
|
break;
|
2020-07-18 11:53:02 +00:00
|
|
|
|
default:
|
|
|
|
|
subject = default;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|