[backend/federation] Switch from pancakes:Pronouns (V1) to pancakes:pronouns (V2)

This commit is contained in:
pancakes 2025-01-27 14:51:41 +10:00 committed by Laura Hausmann
parent 2b25affa2b
commit df9d3388cf
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
6 changed files with 17 additions and 32 deletions

View file

@ -21,7 +21,7 @@ public static class Constants
public const string MastodonNs = "http://joinmastodon.org/ns";
public const string MisskeyNs = "https://misskey-hub.net/ns";
public const string FedibirdNs = "http://fedibird.com/ns";
public const string PancakesNs = "https://ns.pancakes.gay/as/";
public const string PancakesNs = "https://ns.pancakes.gay/as";
public static readonly string[] SystemUsers = ["instance.actor", "relay.actor"];
public const string APMime = "application/activity+json";

View file

@ -80,20 +80,15 @@ public class UserRenderer(
var attachments = profile?.Fields
.Select(p => new ASField { Name = p.Name, Value = RenderFieldValue(p.Value) })
.Concat<ASAttachment>(profile.Pronouns != null && profile.Pronouns.Count != 0
?
[
profile.Pronouns.TryGetValue("", out var pronouns)
? new ASPronouns { Name = new LDLocalizedString(null, pronouns) }
: new ASPronouns { Name = new LDLocalizedString { Values = profile.Pronouns! } }
]
: [])
.Cast<ASAttachment>()
.ToList();
var summary = profile?.Description != null
? (await mfmConverter.ToHtmlAsync(profile.Description, profile.Mentions, user.Host)).Html
: null;
var pronouns = profile?.Pronouns != null ? new LDLocalizedString { Values = profile.Pronouns! } : null;
return new ASActor
{
Id = id,
@ -141,7 +136,8 @@ public class UserRenderer(
PublicKey = keypair.PublicKey
},
Tags = tags,
Attachments = attachments
Attachments = attachments,
Pronouns = pronouns
};
}

View file

@ -44,7 +44,11 @@
"Bite": "https://ns.mia.jetzt/as#Bite",
"quoteUri": "http://fedibird.com/ns#quoteUri",
"EmojiReact": "http://litepub.social/ns#EmojiReact",
"Pronouns": "https://ns.pancakes.gay/as/#Pronouns"
"pancakes": "https://ns.pancakes.gay/as#",
"pancakes:pronouns": {
"@id": "https://ns.pancakes.gay/as#pronouns",
"@container": "@language"
}
}
]
}

View file

@ -131,6 +131,10 @@ public class ASActor : ASObjectWithId
[JC(typeof(VC))]
private XsdString? WebfingerAddressXsd { get; set; }
[J($"{Constants.PancakesNs}#pronouns")]
[JC(typeof(LocalizedValueObjectConverter))]
public LDLocalizedString? Pronouns { get; set; }
[JI]
public string? WebfingerAddress
{

View file

@ -53,16 +53,6 @@ public class ASField : ASAttachment
public ASField() => Type = $"{Constants.SchemaNs}#PropertyValue";
}
public class ASPronouns : ASAttachment
{
public ASPronouns() => Type = $"{Constants.PancakesNs}#Pronouns";
[J($"{Constants.ActivityStreamsNs}#name")]
[JC(typeof(LocalizedValueObjectConverter))]
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
public LDLocalizedString? Name { get; set; }
}
public class ASImageConverter : ASSerializer.ListSingleObjectConverter<ASImage>;
public sealed class ASAttachmentConverter : JsonConverter
@ -112,7 +102,6 @@ public sealed class ASAttachmentConverter : JsonConverter
$"{Constants.ActivityStreamsNs}#Document" => obj.ToObject<ASDocument?>(),
$"{Constants.ActivityStreamsNs}#Image" => obj.ToObject<ASImage?>(),
$"{Constants.SchemaNs}#PropertyValue" => obj.ToObject<ASField?>(),
$"{Constants.PancakesNs}#Pronouns" => obj.ToObject<ASPronouns?>(),
_ => attachment
};
}

View file

@ -159,11 +159,7 @@ public class UserService(
.AwaitAllAsync()
: null;
var pronouns = actor.Attachments?.OfType<ASPronouns>()
.FirstOrDefault(p => p.Name?.Values.Count != 0)
?.Name?.Values
.Where(p => p.Value != null)
.ToDictionary(p => p.Key, p => p.Value ?? "");
var pronouns = actor.Pronouns?.Values.ToDictionary(p => p.Key, p => p.Value ?? "");
var bio = actor.MkSummary?.ReplaceLineEndings("\n").Trim();
if (bio == null)
@ -333,11 +329,7 @@ public class UserService(
.AwaitAllAsync()
: null;
var pronouns = actor.Attachments?.OfType<ASPronouns>()
.FirstOrDefault(p => p.Name?.Values.Count != 0)
?.Name?.Values
.Where(p => p.Value != null)
.ToDictionary(p => p.Key, p => p.Value ?? "");
var pronouns = actor.Pronouns?.Values.ToDictionary(p => p.Key, p => p.Value ?? "");
user.Emojis = emoji.Select(p => p.Id).ToList();
//TODO: FollowersCount