fix(backend): return fedi info in /users/@me routes

This commit is contained in:
Sam 2023-03-17 14:14:31 +01:00
parent 7a156558b6
commit d6bb2f7743
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
3 changed files with 49 additions and 8 deletions

View file

@ -30,6 +30,10 @@ type GetMeResponse struct {
MaxInvites int `json:"max_invites"`
Discord *string `json:"discord"`
DiscordUsername *string `json:"discord_username"`
Fediverse *string `json:"fediverse"`
FediverseUsername *string `json:"fediverse_username"`
FediverseInstance *string `json:"fediverse_instance"`
}
type PartialMember struct {
@ -155,11 +159,23 @@ func (s *Server) getMeUser(w http.ResponseWriter, r *http.Request) error {
return err
}
// get fedi instance name if the user has a linked fedi account
var fediInstance *string
if u.FediverseAppID != nil {
app, err := s.DB.FediverseAppByID(ctx, *u.FediverseAppID)
if err == nil {
fediInstance = &app.Instance
}
}
render.JSON(w, r, GetMeResponse{
GetUserResponse: dbUserToResponse(u, fields, members),
MaxInvites: u.MaxInvites,
Discord: u.Discord,
DiscordUsername: u.DiscordUsername,
GetUserResponse: dbUserToResponse(u, fields, members),
MaxInvites: u.MaxInvites,
Discord: u.Discord,
DiscordUsername: u.DiscordUsername,
Fediverse: u.Fediverse,
FediverseUsername: u.FediverseUsername,
FediverseInstance: fediInstance,
})
return nil
}