fix(backend): return last_sid_reroll in API, update last sid reroll + last active correctly

This commit is contained in:
sam 2024-09-26 17:09:27 +02:00
parent b5f9ef9bd6
commit e83895255e
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
3 changed files with 17 additions and 6 deletions

View file

@ -128,13 +128,18 @@ public class MembersController(
if (CurrentUser!.LastSidReroll > minTimeAgo)
throw new ApiError.BadRequest("Cannot reroll short ID yet");
// Using ExecuteUpdateAsync here as the new short ID is generated by the database
await db.Members.Where(m => m.Id == member.Id)
.ExecuteUpdateAsync(s => s
.SetProperty(m => m.Sid, _ => db.FindFreeMemberSid()));
// Re-fetch member so we can be sure the sid is correct
var updatedMember = await db.ResolveMemberAsync(CurrentUser!.Id, memberRef);
await db.Users.Where(u => u.Id == CurrentUser.Id)
.ExecuteUpdateAsync(s => s
.SetProperty(u => u.LastSidReroll, clock.GetCurrentInstant())
.SetProperty(u => u.LastActive, clock.GetCurrentInstant()));
// Re-fetch member to fetch the new sid
var updatedMember = await db.ResolveMemberAsync(CurrentUser!.Id, memberRef);
return Ok(memberRenderer.RenderMember(updatedMember, CurrentToken));
}
}

View file

@ -225,10 +225,12 @@ public class UsersController(
if (CurrentUser!.LastSidReroll > minTimeAgo)
throw new ApiError.BadRequest("Cannot reroll short ID yet");
// Using ExecuteUpdateAsync here as the new short ID is generated by the database
await db.Users.Where(u => u.Id == CurrentUser.Id)
.ExecuteUpdateAsync(s => s
.SetProperty(u => u.Sid, _ => db.FindFreeUserSid())
.SetProperty(u => u.LastSidReroll, _ => clock.GetCurrentInstant()));
.SetProperty(u => u.LastSidReroll, clock.GetCurrentInstant())
.SetProperty(u => u.LastActive, clock.GetCurrentInstant()));
var user = await db.ResolveUserAsync(CurrentUser.Id);
return Ok(await userRenderer.RenderUserAsync(user, CurrentUser, CurrentToken, renderMembers: false));

View file

@ -37,7 +37,8 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
: [];
return new UserResponse(
user.Id, user.Sid, 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,
renderMembers ? members.Select(m => memberRenderer.RenderPartialMember(m, tokenHidden)) : null,
renderAuthMethods
@ -47,7 +48,8 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
))
: null,
tokenHidden ? user.ListHidden : null,
tokenHidden ? user.LastActive : null
tokenHidden ? user.LastActive : null,
tokenHidden ? user.LastSidReroll : null
);
}
@ -77,7 +79,9 @@ public class UserRendererService(DatabaseContext db, MemberRendererService membe
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
bool? MemberListHidden,
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
Instant? LastActive
Instant? LastActive,
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
Instant? LastSidReroll
);
public record AuthenticationMethodResponse(