Finally retire the PKMember setters!
This commit is contained in:
@@ -60,43 +60,45 @@ namespace PluralKit.Core
|
||||
/// </summary>
|
||||
/// <remarks>If an existing member exists in this system that matches this member in either HID or name, it'll overlay the member information on top of this instead.</remarks>
|
||||
/// <param name="identifier">An opaque identifier string that refers to this member regardless of source. Is used when importing switches. Value is irrelevant, but should be consistent with the same member later.</param>
|
||||
/// <param name="member">A member struct containing the data to apply to this member. Null fields will be ignored.</param>
|
||||
/// <param name="potentialHid">When trying to match the member to an existing member, will use a member with this HID if present in system.</param>
|
||||
/// <param name="potentialName">When trying to match the member to an existing member, will use a member with this name if present in system.</param>
|
||||
/// <param name="patch">A member patch struct containing the data to apply to this member </param>
|
||||
/// <returns>The inserted member object, which may or may not share an ID or HID with the input member.</returns>
|
||||
public async Task<PKMember> AddMember(string identifier, PKMember member)
|
||||
public async Task<PKMember> AddMember(string identifier, string potentialHid, string potentialName, MemberPatch patch)
|
||||
{
|
||||
// See if we can find a member that matches this one
|
||||
// if not, roll a new hid and we'll insert one with that
|
||||
// (we can't trust the hid given in the member, it might let us overwrite another system's members)
|
||||
var existingMember = FindExistingMemberInSystem(member.Hid, member.Name);
|
||||
var existingMember = FindExistingMemberInSystem(potentialHid, potentialName);
|
||||
string newHid = existingMember?.Hid ?? await _conn.QuerySingleAsync<string>("find_free_member_hid", commandType: CommandType.StoredProcedure);
|
||||
|
||||
// Upsert member data and return the ID
|
||||
QueryBuilder qb = QueryBuilder.Upsert("members", "hid")
|
||||
.Constant("hid", "@Hid")
|
||||
.Constant("system", "@System")
|
||||
.Variable("name", "@Name")
|
||||
.Variable("keep_proxy", "@KeepProxy");
|
||||
.Constant("system", "@System");
|
||||
|
||||
if (member.DisplayName != null) qb.Variable("display_name", "@DisplayName");
|
||||
if (member.Description != null) qb.Variable("description", "@Description");
|
||||
if (member.Color != null) qb.Variable("color", "@Color");
|
||||
if (member.AvatarUrl != null) qb.Variable("avatar_url", "@AvatarUrl");
|
||||
if (member.ProxyTags != null) qb.Variable("proxy_tags", "@ProxyTags");
|
||||
if (member.Birthday != null) qb.Variable("birthday", "@Birthday");
|
||||
if (patch.Name.IsPresent) qb.Variable("name", "@Name");
|
||||
if (patch.DisplayName.IsPresent) qb.Variable("display_name", "@DisplayName");
|
||||
if (patch.Description.IsPresent) qb.Variable("description", "@Description");
|
||||
if (patch.Color.IsPresent) qb.Variable("color", "@Color");
|
||||
if (patch.AvatarUrl.IsPresent) qb.Variable("avatar_url", "@AvatarUrl");
|
||||
if (patch.ProxyTags.IsPresent) qb.Variable("proxy_tags", "@ProxyTags");
|
||||
if (patch.Birthday.IsPresent) qb.Variable("birthday", "@Birthday");
|
||||
if (patch.KeepProxy.IsPresent) qb.Variable("keep_proxy", "@KeepProxy");
|
||||
|
||||
var newMember = await _conn.QueryFirstAsync<PKMember>(qb.Build("returning *"),
|
||||
new
|
||||
{
|
||||
Hid = newHid,
|
||||
System = _systemId,
|
||||
member.Name,
|
||||
member.DisplayName,
|
||||
member.Description,
|
||||
member.Color,
|
||||
member.AvatarUrl,
|
||||
member.KeepProxy,
|
||||
member.ProxyTags,
|
||||
member.Birthday
|
||||
Name = patch.Name.Value,
|
||||
DisplayName = patch.DisplayName.Value,
|
||||
Description = patch.Description.Value,
|
||||
Color = patch.Color.Value,
|
||||
AvatarUrl = patch.AvatarUrl.Value,
|
||||
KeepProxy = patch.KeepProxy.Value,
|
||||
ProxyTags = patch.ProxyTags.Value,
|
||||
Birthday = patch.Birthday.Value
|
||||
});
|
||||
|
||||
// Log this member ID by the given identifier
|
||||
|
@@ -30,6 +30,8 @@ namespace PluralKit.Core
|
||||
public IEnumerator<T> GetEnumerator() => ToArray().GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => ToArray().GetEnumerator();
|
||||
|
||||
public static implicit operator Partial<T>(T val) => Present(val);
|
||||
}
|
||||
|
||||
public class PartialConverter: JsonConverter
|
||||
|
Reference in New Issue
Block a user