feat(backend): return short IDs

This commit is contained in:
sam 2024-09-26 15:26:52 +02:00
parent e7e4937082
commit e76c634738
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
2 changed files with 9 additions and 5 deletions

View file

@ -29,15 +29,15 @@ public class MemberRendererService(DatabaseContext db, Config config)
var renderUnlisted = token?.UserId == member.UserId && token.HasScope("user.read_hidden"); var renderUnlisted = token?.UserId == member.UserId && token.HasScope("user.read_hidden");
return new MemberResponse( return new MemberResponse(
member.Id, member.Name, member.DisplayName, member.Bio, member.Id, member.Sid, member.Name, member.DisplayName, member.Bio,
AvatarUrlFor(member), member.Links, member.Names, member.Pronouns, member.Fields, AvatarUrlFor(member), member.Links, member.Names, member.Pronouns, member.Fields,
RenderPartialUser(member.User), renderUnlisted ? member.Unlisted : null); RenderPartialUser(member.User), renderUnlisted ? member.Unlisted : null);
} }
private UserRendererService.PartialUser RenderPartialUser(User user) => private UserRendererService.PartialUser RenderPartialUser(User user) =>
new(user.Id, user.Username, user.DisplayName, AvatarUrlFor(user), user.CustomPreferences); new(user.Id, user.Sid, user.Username, user.DisplayName, AvatarUrlFor(user), user.CustomPreferences);
public PartialMember RenderPartialMember(Member member, bool renderUnlisted = false) => new(member.Id, member.Name, public PartialMember RenderPartialMember(Member member, bool renderUnlisted = false) => new(member.Id, member.Sid, member.Name,
member.DisplayName, member.Bio, AvatarUrlFor(member), member.Names, member.Pronouns, member.DisplayName, member.Bio, AvatarUrlFor(member), member.Names, member.Pronouns,
renderUnlisted ? member.Unlisted : null); renderUnlisted ? member.Unlisted : null);
@ -49,6 +49,7 @@ public class MemberRendererService(DatabaseContext db, Config config)
public record PartialMember( public record PartialMember(
Snowflake Id, Snowflake Id,
string Sid,
string Name, string Name,
string? DisplayName, string? DisplayName,
string? Bio, string? Bio,
@ -60,6 +61,7 @@ public class MemberRendererService(DatabaseContext db, Config config)
public record MemberResponse( public record MemberResponse(
Snowflake Id, Snowflake Id,
string Sid,
string Name, string Name,
string? DisplayName, string? DisplayName,
string? Bio, string? Bio,

View file

@ -37,7 +37,7 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
: []; : [];
return new UserResponse( return new UserResponse(
user.Id, user.Username, user.DisplayName, user.Bio, user.MemberTitle, AvatarUrlFor(user), user.Links, user.Id, user.Sid, user.Username, user.DisplayName, user.Bio, user.MemberTitle, AvatarUrlFor(user), user.Links,
user.Names, user.Pronouns, user.Fields, user.CustomPreferences, user.Names, user.Pronouns, user.Fields, user.CustomPreferences,
renderMembers ? members.Select(m => memberRenderer.RenderPartialMember(m, tokenHidden)) : null, renderMembers ? members.Select(m => memberRenderer.RenderPartialMember(m, tokenHidden)) : null,
renderAuthMethods renderAuthMethods
@ -52,13 +52,14 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
} }
public PartialUser RenderPartialUser(User user) => public PartialUser RenderPartialUser(User user) =>
new(user.Id, user.Username, user.DisplayName, AvatarUrlFor(user), user.CustomPreferences); new(user.Id, user.Sid, user.Username, user.DisplayName, AvatarUrlFor(user), user.CustomPreferences);
private string? AvatarUrlFor(User user) => private string? AvatarUrlFor(User user) =>
user.Avatar != null ? $"{config.MediaBaseUrl}/users/{user.Id}/avatars/{user.Avatar}.webp" : null; user.Avatar != null ? $"{config.MediaBaseUrl}/users/{user.Id}/avatars/{user.Avatar}.webp" : null;
public record UserResponse( public record UserResponse(
Snowflake Id, Snowflake Id,
string Sid,
string Username, string Username,
string? DisplayName, string? DisplayName,
string? Bio, string? Bio,
@ -92,6 +93,7 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
public record PartialUser( public record PartialUser(
Snowflake Id, Snowflake Id,
string Sid,
string Username, string Username,
string? DisplayName, string? DisplayName,
string? AvatarUrl, string? AvatarUrl,