mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-14 02:45:29 +00:00
Keep guest rooms moderated and restore owner moderation
This commit is contained in:
@@ -30,7 +30,7 @@ class RemoveAbsentPlayers implements ShouldQueue
|
||||
->select(['id', 'room_id'])
|
||||
->chunkById(100, function ($players) use ($cutoff, $realtimeState): void {
|
||||
foreach ($players as $player) {
|
||||
$room = DB::transaction(function () use ($player, $cutoff): ?Room {
|
||||
$result = DB::transaction(function () use ($player, $cutoff): ?array {
|
||||
$room = Room::withTrashed()
|
||||
->lockForUpdate()
|
||||
->find($player->room_id);
|
||||
@@ -54,14 +54,49 @@ class RemoveAbsentPlayers implements ShouldQueue
|
||||
}
|
||||
|
||||
$currentPlayer->delete();
|
||||
$roomDeleted = false;
|
||||
|
||||
if ($room->owner_id === null && ! $room->trashed()) {
|
||||
if (! $room->players()->exists()) {
|
||||
$room->delete();
|
||||
$roomDeleted = true;
|
||||
} elseif (! $room->players()->where('is_moderator', true)->exists()) {
|
||||
$successor = $room->players()
|
||||
->where(function ($query) use ($cutoff): void {
|
||||
$query->where('last_seen_at', '>', $cutoff)
|
||||
->orWhere(function ($query) use ($cutoff): void {
|
||||
$query->whereNull('last_seen_at')
|
||||
->where('created_at', '>', $cutoff);
|
||||
});
|
||||
})
|
||||
->orderBy('created_at')
|
||||
->orderBy('id')
|
||||
->first();
|
||||
|
||||
$successor?->update(['is_moderator' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
$room->update([
|
||||
'state_version' => $room->state_version + 1,
|
||||
]);
|
||||
|
||||
return $room;
|
||||
return [$room, $roomDeleted];
|
||||
});
|
||||
|
||||
if ($room !== null && ! $room->trashed()) {
|
||||
if ($result === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
[$room, $roomDeleted] = $result;
|
||||
|
||||
if ($roomDeleted) {
|
||||
RoomStateChanged::dispatch(
|
||||
$room->id,
|
||||
$room->state_version,
|
||||
RoomStateChange::RoomDeleted,
|
||||
);
|
||||
} elseif (! $room->trashed()) {
|
||||
RoomStateChanged::dispatch(
|
||||
$room->id,
|
||||
$room->state_version,
|
||||
|
||||
Reference in New Issue
Block a user