private MemberPatch ToMemberPatch(DataFileMember fileMember) { var newMember = new MemberPatch { Name = fileMember.Name, DisplayName = fileMember.DisplayName, Description = fileMember.Description, Color = fileMember.Color, Pronouns = fileMember.Pronouns, AvatarUrl = fileMember.AvatarUrl, KeepProxy = fileMember.KeepProxy, }; if (fileMember.Prefix != null || fileMember.Suffix != null) { newMember.ProxyTags = new[] { new ProxyTag(fileMember.Prefix, fileMember.Suffix) } } ; else { // Ignore proxy tags where both prefix and suffix are set to null (would be invalid anyway) newMember.ProxyTags = (fileMember.ProxyTags ?? new ProxyTag[] { }).Where(tag => !tag.IsEmpty).ToArray(); } if (fileMember.Birthday != null) { var birthdayParse = DateTimeFormats.DateExportFormat.Parse(fileMember.Birthday); newMember.Birthday = birthdayParse.Success ? (LocalDate?)birthdayParse.Value : null; } return(newMember); }
public static MemberPatch WithAllPrivacy(this MemberPatch member, PrivacyLevel level) { foreach (var subject in Enum.GetValues(typeof(MemberPrivacySubject))) { member.WithPrivacy((MemberPrivacySubject)subject, level); } return(member); }
public Task <PKMember> UpdateMember(IPKConnection conn, MemberId id, MemberPatch patch, IDbTransaction?transaction = null) { _logger.Information("Updated {MemberId}: {@MemberPatch}", id, patch); var(query, pms) = patch.Apply(UpdateQueryBuilder.Update("members", "id = @id")) .WithConstant("id", id) .Build("returning *"); return(conn.QueryFirstAsync <PKMember>(query, pms, transaction)); }
public static MemberPatch WithPrivacy(this MemberPatch member, MemberPrivacySubject subject, PrivacyLevel level) { // what do you mean switch expressions can't be statements >.> _ = subject switch { MemberPrivacySubject.Name => member.NamePrivacy = level, MemberPrivacySubject.Description => member.DescriptionPrivacy = level, MemberPrivacySubject.Avatar => member.AvatarPrivacy = level, MemberPrivacySubject.Pronouns => member.PronounPrivacy = level, MemberPrivacySubject.Birthday => member.BirthdayPrivacy = level, MemberPrivacySubject.Metadata => member.MetadataPrivacy = level, MemberPrivacySubject.Visibility => member.Visibility = level, _ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}") }; return(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(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"); 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.Pronouns.IsPresent) { qb.Variable("pronouns", "@Pronouns"); } 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"); } // don't overwrite message count on existing members if (existingMember == null) { if (patch.MessageCount.IsPresent) { qb.Variable("message_count", "@MessageCount"); } } var newMember = await _conn.QueryFirstAsync <PKMember>(qb.Build("returning *"), new { Hid = newHid, System = _systemId, Name = patch.Name.Value, DisplayName = patch.DisplayName.Value, Description = patch.Description.Value, Pronouns = patch.Pronouns.Value, Color = patch.Color.Value, AvatarUrl = patch.AvatarUrl.Value, KeepProxy = patch.KeepProxy.Value, ProxyTags = patch.ProxyTags.Value, Birthday = patch.Birthday.Value, MessageCount = patch.MessageCount.Value, }); // Log this member ID by the given identifier _knownMembers[identifier] = newMember.Id; return(newMember); }
public static Task <PKMember> UpdateMember(this IPKConnection conn, MemberId id, MemberPatch patch) { var(query, pms) = patch.Apply(UpdateQueryBuilder.Update("members", "id = @id")) .WithConstant("id", id) .Build("returning *"); return(conn.QueryFirstAsync <PKMember>(query, pms)); }