[backend] Add Emojis to UserResponse

This commit is contained in:
pancakes 2024-11-04 17:08:48 +10:00
parent ceb8da8f3d
commit 72c68d2d5a
No known key found for this signature in database
GPG key ID: ED53D426432B861B
3 changed files with 27 additions and 0 deletions

View file

@ -20,6 +20,8 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, DatabaseConte
var instanceName = user.IsLocalUser ? config.Value.AccountDomain : instance?.Name;
var instanceIcon = user.IsLocalUser ? null : instance?.FaviconUrl;
var emojis = await GetEmojis([user]);
return new UserResponse
{
Id = user.Id,
@ -30,6 +32,7 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, DatabaseConte
BannerUrl = user.BannerUrl,
InstanceName = instanceName,
InstanceIconUrl = instanceIcon,
Emojis = emojis,
MovedTo = user.MovedToUri
};
}
@ -47,6 +50,27 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, DatabaseConte
return await userList.Select(p => RenderOne(p, data)).AwaitAllAsync();
}
private async Task<List<EmojiResponse>> GetEmojis(IEnumerable<User> users)
{
var ids = users.SelectMany(p => p.Emojis).ToList();
if (ids.Count == 0) return [];
return await db.Emojis
.Where(p => ids.Contains(p.Id))
.Select(p => new EmojiResponse
{
Id = p.Id,
Name = p.Name,
Uri = p.Uri,
Aliases = p.Aliases,
Category = p.Category,
PublicUrl = p.PublicUrl,
License = p.License,
Sensitive = p.Sensitive
})
.ToListAsync();
}
public class UserRendererDto
{
public List<Instance>? InstanceData;

View file

@ -72,6 +72,7 @@
Token = res.Token!,
Host = res.User.Host,
IsAdmin = res.IsAdmin ?? false,
Emojis = res.User.Emojis,
MovedTo = res.User.MovedTo
});
SessionService.SetSession(res.User.Id);

View file

@ -14,5 +14,7 @@ public class UserResponse
public required string? InstanceName { get; set; }
public required string? InstanceIconUrl { get; set; }
public List<EmojiResponse> Emojis { get; set; } = [];
[JI(Condition = WhenWritingNull)] public string? MovedTo { get; set; }
}