[backend/federation] Use LDLocalizedString for pancakes:Pronouns

This commit is contained in:
pancakes 2025-01-27 02:13:22 +10:00 committed by Laura Hausmann
parent 9e713419ce
commit 2b25affa2b
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 15 additions and 26 deletions

View file

@ -84,8 +84,8 @@ public class UserRenderer(
?
[
profile.Pronouns.TryGetValue("", out var pronouns)
? new ASPronouns { Name = pronouns }
: new ASPronouns { NameMap = profile.Pronouns }
? new ASPronouns { Name = new LDLocalizedString(null, pronouns) }
: new ASPronouns { Name = new LDLocalizedString { Values = profile.Pronouns! } }
]
: [])
.ToList();

View file

@ -58,14 +58,9 @@ public class ASPronouns : ASAttachment
public ASPronouns() => Type = $"{Constants.PancakesNs}#Pronouns";
[J($"{Constants.ActivityStreamsNs}#name")]
[JC(typeof(ValueObjectConverter))]
[JC(typeof(LocalizedValueObjectConverter))]
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Name { get; set; }
[J($"{Constants.ActivityStreamsNs}#nameMap")]
[JC(typeof(ValueObjectConverter))]
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Dictionary<string, string>? NameMap { get; set; }
public LDLocalizedString? Name { get; set; }
}
public class ASImageConverter : ASSerializer.ListSingleObjectConverter<ASImage>;

View file

@ -159,14 +159,11 @@ public class UserService(
.AwaitAllAsync()
: null;
var pronounsAttachment = actor.Attachments?.OfType<ASPronouns>()
.FirstOrDefault(p => p is { Name: not null } or { NameMap: not null });
var pronouns = pronounsAttachment switch
{
{ Name: not null } => new Dictionary<string, string> { { "", pronounsAttachment.Name } },
{ NameMap: not null } => pronounsAttachment.NameMap,
_ => 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 bio = actor.MkSummary?.ReplaceLineEndings("\n").Trim();
if (bio == null)
@ -336,14 +333,11 @@ public class UserService(
.AwaitAllAsync()
: null;
var pronounsAttachment = actor.Attachments?.OfType<ASPronouns>()
.FirstOrDefault(p => p is { Name: not null } or { NameMap: not null });
var pronouns = pronounsAttachment switch
{
{ Name: not null } => new Dictionary<string, string> { { "", pronounsAttachment.Name } },
{ NameMap: not null } => pronounsAttachment.NameMap,
_ => 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 ?? "");
user.Emojis = emoji.Select(p => p.Id).ToList();
//TODO: FollowersCount