Skip to content

Delete leaderboard instead of throwing error if last member tries to leave #117

@Eldemarkki

Description

@Eldemarkki

Now if a leaderboard only has 1 member and they try to leave, it will throw an error saying "There are no more admins left, you cannot leave". In this case the last member should be an admin so they could just delete the leaderboard, but would be nice to not throw an error.

return Err(TimeError::LastAdmin);

In that case we can just delete the database because there are no other members left anyways.

So the if condition can be changed from

if db.is_leaderboard_admin(user.identity.id, lid).await?
    && db.get_leaderboard_admin_count(lid).await? == 1
{
    return Err(TimeError::LastAdmin);
}

to

if getLeaderboardMemberCount(lid) == 1 {
  deleteLeaderboard(lid)
}

(a real world case where I encountered this: open two browser windows, each one with a different user. Create a leaderboard, join it with both users, and make both users admins. Leave the leaderboard from one window, and then trying to leave it from the other window will throw the error)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions