From de9cae0cbde52c877c6986c36d67ac0296412cca Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 15 Dec 2022 00:50:24 +0000 Subject: [PATCH] feat(api): add member.message_count, member.last_message_timestamp --- PluralKit.Core/Models/PKMember.cs | 10 ++++++++-- docs/content/api/models.md | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/PluralKit.Core/Models/PKMember.cs b/PluralKit.Core/Models/PKMember.cs index 913704f8..bbae8440 100644 --- a/PluralKit.Core/Models/PKMember.cs +++ b/PluralKit.Core/Models/PKMember.cs @@ -102,8 +102,11 @@ public static class PKMemberExt public static Instant? CreatedFor(this PKMember member, LookupContext ctx) => member.MetadataPrivacy.Get(ctx, (Instant?)member.Created); - public static int MessageCountFor(this PKMember member, LookupContext ctx) => - member.MetadataPrivacy.Get(ctx, member.MessageCount); + public static int? MessageCountFor(this PKMember member, LookupContext ctx) => + member.MetadataPrivacy.Get(ctx, member.MessageCount, fallback: null); + + public static Instant? LastMessageTimestampFor(this PKMember member, LookupContext ctx) => + member.MetadataPrivacy.Get(ctx, member.LastMessageTimestamp); public static JObject ToJson(this PKMember member, LookupContext ctx, bool needsLegacyProxyTags = false, string systemStr = null) @@ -132,6 +135,9 @@ public static class PKMemberExt o.Add("autoproxy_enabled", ctx == LookupContext.ByOwner ? member.AllowAutoproxy : null); + o.Add("message_count", member.MessageCountFor(ctx)); + 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 } }); diff --git a/docs/content/api/models.md b/docs/content/api/models.md index 39f09acc..35d159fe 100644 --- a/docs/content/api/models.md +++ b/docs/content/api/models.md @@ -52,6 +52,8 @@ Every PluralKit entity has two IDs: a short (5-character) ID and a longer UUID. |proxy_tags|array of [ProxyTag objects](#proxytag-object)| |keep_proxy|boolean|| |autoproxy_enabled|?boolean|| +|message_count|?int|| +|last_message_timestamp|?datetime|| |privacy|?member privacy object|| * Member privacy keys: `visibility`, `name_privacy`, `description_privacy`, `birthday_privacy`, `pronoun_privacy`, `avatar_privacy`, `metadata_privacy`