[backend/api] Render instance theme color for users
This commit is contained in:
parent
bb58b0f573
commit
6975fa9495
2 changed files with 25 additions and 5 deletions
|
@ -17,6 +17,7 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, DatabaseConte
|
||||||
|
|
||||||
var instanceName = user.IsLocalUser ? data.LocalInstanceData.Name : instance?.Name;
|
var instanceName = user.IsLocalUser ? data.LocalInstanceData.Name : instance?.Name;
|
||||||
var instanceIcon = user.IsLocalUser ? data.LocalInstanceData.FaviconUrl : instance?.FaviconUrl;
|
var instanceIcon = user.IsLocalUser ? data.LocalInstanceData.FaviconUrl : instance?.FaviconUrl;
|
||||||
|
var instanceColor = user.IsLocalUser ? data.LocalInstanceData.ThemeColor : instance?.ThemeColor;
|
||||||
|
|
||||||
if (!data.Emojis.TryGetValue(user.Id, out var emoji))
|
if (!data.Emojis.TryGetValue(user.Id, out var emoji))
|
||||||
throw new Exception("DTO didn't contain emoji for user");
|
throw new Exception("DTO didn't contain emoji for user");
|
||||||
|
@ -36,6 +37,7 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, DatabaseConte
|
||||||
BannerAlt = bannerAlt,
|
BannerAlt = bannerAlt,
|
||||||
InstanceName = instanceName,
|
InstanceName = instanceName,
|
||||||
InstanceIconUrl = instanceIcon,
|
InstanceIconUrl = instanceIcon,
|
||||||
|
InstanceColor = instanceColor,
|
||||||
Emojis = emoji,
|
Emojis = emoji,
|
||||||
MovedTo = user.MovedToUri,
|
MovedTo = user.MovedToUri,
|
||||||
IsBot = user.IsBot,
|
IsBot = user.IsBot,
|
||||||
|
@ -55,7 +57,12 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, DatabaseConte
|
||||||
InstanceData = instanceData,
|
InstanceData = instanceData,
|
||||||
AvatarAlt = avatarAlt,
|
AvatarAlt = avatarAlt,
|
||||||
BannerAlt = bannerAlt,
|
BannerAlt = bannerAlt,
|
||||||
LocalInstanceData = (await metaSvc.GetAsync(MetaEntity.InstanceName) ?? config.Value.AccountDomain, "/_content/Iceshrimp.Assets.Branding/favicon.png")
|
LocalInstanceData = new LocalInstance
|
||||||
|
{
|
||||||
|
Name = await metaSvc.GetAsync(MetaEntity.InstanceName) ?? config.Value.AccountDomain,
|
||||||
|
FaviconUrl = null,
|
||||||
|
ThemeColor = await metaSvc.GetAsync(MetaEntity.ThemeColor)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return Render(user, data);
|
return Render(user, data);
|
||||||
|
@ -94,7 +101,12 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, DatabaseConte
|
||||||
Emojis = await GetEmojisAsync(userList),
|
Emojis = await GetEmojisAsync(userList),
|
||||||
AvatarAlt = await GetAvatarAltAsync(userList),
|
AvatarAlt = await GetAvatarAltAsync(userList),
|
||||||
BannerAlt = await GetBannerAltAsync(userList),
|
BannerAlt = await GetBannerAltAsync(userList),
|
||||||
LocalInstanceData = (await metaSvc.GetAsync(MetaEntity.InstanceName) ?? config.Value.AccountDomain, "/_content/Iceshrimp.Assets.Branding/favicon.png")
|
LocalInstanceData = new LocalInstance
|
||||||
|
{
|
||||||
|
Name = await metaSvc.GetAsync(MetaEntity.InstanceName) ?? config.Value.AccountDomain,
|
||||||
|
FaviconUrl = null,
|
||||||
|
ThemeColor = await metaSvc.GetAsync(MetaEntity.ThemeColor)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return userList.Select(p => Render(p, data));
|
return userList.Select(p => Render(p, data));
|
||||||
|
@ -129,6 +141,13 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, DatabaseConte
|
||||||
public required Dictionary<string, List<EmojiResponse>> Emojis;
|
public required Dictionary<string, List<EmojiResponse>> Emojis;
|
||||||
public required Dictionary<string, string?> AvatarAlt;
|
public required Dictionary<string, string?> AvatarAlt;
|
||||||
public required Dictionary<string, string?> BannerAlt;
|
public required Dictionary<string, string?> BannerAlt;
|
||||||
public required (string Name, string? FaviconUrl) LocalInstanceData;
|
public required LocalInstance LocalInstanceData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LocalInstance
|
||||||
|
{
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public required string? FaviconUrl { get; set; }
|
||||||
|
public required string? ThemeColor { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ public class UserResponse : IIdentifiable
|
||||||
public string? BannerAlt { get; set; }
|
public string? BannerAlt { get; set; }
|
||||||
public required string? InstanceName { get; set; }
|
public required string? InstanceName { get; set; }
|
||||||
public required string? InstanceIconUrl { get; set; }
|
public required string? InstanceIconUrl { get; set; }
|
||||||
|
public string? InstanceColor { get; set; }
|
||||||
|
|
||||||
public bool IsBot { get; set; } = false;
|
public bool IsBot { get; set; } = false;
|
||||||
public bool IsCat { get; set; } = false;
|
public bool IsCat { get; set; } = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue