Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Full game & roster lifecycle controls: players can leave a game during Lobby or Drafting (with automatic host transfer if the host departs, and automatic return to Lobby if fewer than 3 players remain), hosts can remove disruptive players, transfer host ownership, or abandon a game cleanly without awarding Gold Medals, and latecomers can join an already active round to receive an instant starter-deck board.
- Optional game completion deadline (`Spiel endet spätestens am`): hosts can set an end timestamp at game creation or in the Lobby; if reached before anyone scores Bingo, the scheduler completes the game automatically and awards victory to the player with the most filled tiles (breaking ties by earliest latest-capture timestamp, or ending in a draw with no Gold Medal on zero captures).
- Real-time in-app toast alerts for newly arriving unread notifications plus dedicated notifications for "Fast Bingo" (when a contender is one tile away from winning) and drafting deadline reminders.
- Shutter-first quick capture sheet (`Schnellfoto` with native camera, optional live viewfinder burst into a local photo tray, and delayed tile assignment), IndexedDB offline capture queue with automatic background upload and post-completion preservation (`Spiel bereits beendet` with one-tap local download), capture retraction (`Foto zurückziehen` in the lightbox while a game is active), and a lightweight static-asset PWA service worker.
- Faster drafting: expanded all four Quick-Start starter decks to 36 unique prompts, added an "Alle Decks mischen" option, one-tap "Leere füllen & bereit", a Quick-Pick suggestion bar, an 80-character prompt limit with live counter, board-assembly duplicate avoidance, and optional drafting deadlines (`Kein Limit`, `+15 Min.`, `+1 Std.`, `+24 Std.`, or custom) with host "Offene Plätze automatisch füllen" override.
- Target-grouped board view (`Nach Ziel`) alongside the classic Bingo grid in both active games and the post-game recap (including an aggregated per-target match overview), plus target pinning (up to 3 focus friends), a `Nur offene` filter, instant prompt/target search, an in-game `?` rules & visibility guide, and a dismissible first-capture tip.
Expand Down
19 changes: 19 additions & 0 deletions backend/scheduler/src/jobs/finish_expired_games.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use friendarazzi_core::App;
use friendarazzi_core::ResultReport;
use friendarazzi_core::application::AuthContext;
use friendarazzi_core::service::{FinishExpiredGames, GameUseCaseError};
use tracing::info;

pub async fn run_finish_expired_games(app: &App) -> ResultReport<(), GameUseCaseError> {
let outcome = app
.execute(AuthContext::Anonymous, FinishExpiredGames)
.await?;
if !outcome.finished_games.is_empty() {
info!(
count = outcome.finished_games.len(),
next_ends_at = ?outcome.next_ends_at,
"scheduled finish_expired_games finalized expired active games"
);
}
Ok(())
}
27 changes: 22 additions & 5 deletions backend/scheduler/src/jobs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
mod finish_expired_games;
mod start_ready_games;

use std::future::Future;
use std::pin::Pin;

use ::scheduler::{Scheduler, SchedulerError, SchedulerReport, StateStore};
use ::scheduler::{
Job, Schedule, Scheduler, SchedulerError, SchedulerReport, StateStore, Task, TaskContext,
};
use friendarazzi_core::App;
use friendarazzi_core::domain::READY_GRACE_PERIOD_SECONDS;

pub use start_ready_games::{
START_READY_GAMES_JOB_ID, build_start_ready_games_job, run_start_ready_games,
};
pub use finish_expired_games::run_finish_expired_games;
pub use start_ready_games::{START_READY_GAMES_JOB_ID, run_start_ready_games};

pub fn run<S: StateStore + Send + Sync + 'static>(
scheduler: Scheduler<S>,
app: App,
) -> Pin<Box<dyn Future<Output = Result<SchedulerReport, SchedulerError>> + Send>> {
let job = build_start_ready_games_job(app);
let job = Job::new(
START_READY_GAMES_JOB_ID,
Schedule::Interval(std::time::Duration::from_secs(
READY_GRACE_PERIOD_SECONDS as u64,
)),
app,
Task::from_async(|context: TaskContext<App>| async move {
tokio::try_join!(
run_start_ready_games(&context.deps),
run_finish_expired_games(&context.deps),
)
.map(|_| ())
.map_err(|err| err.to_string())
}),
);
Box::pin(async move { scheduler.run(job).await })
}
14 changes: 0 additions & 14 deletions backend/scheduler/src/jobs/start_ready_games.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::time::Duration;

use ::scheduler::{Job, Schedule, Task, TaskContext};
use friendarazzi_core::App;
use friendarazzi_core::ResultReport;
use friendarazzi_core::application::AuthContext;
Expand Down Expand Up @@ -46,16 +45,3 @@ pub async fn run_start_ready_games(app: &App) -> ResultReport<(), GameUseCaseErr

Ok(())
}

pub fn build_start_ready_games_job(app: App) -> Job<App> {
Job::new(
START_READY_GAMES_JOB_ID,
Schedule::Interval(Duration::from_secs(READY_GRACE_PERIOD_SECONDS as u64)),
app,
Task::from_async(|context: TaskContext<App>| async move {
run_start_ready_games(&context.deps)
.await
.map_err(|err| err.to_string())
}),
)
}
2 changes: 1 addition & 1 deletion backend/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod runtime;
pub use ::scheduler::{
InMemoryStateStore, SchedulerError, SchedulerHandle, SchedulerReport, StateStore,
};
pub use jobs::{START_READY_GAMES_JOB_ID, run_start_ready_games};
pub use jobs::{START_READY_GAMES_JOB_ID, run_finish_expired_games, run_start_ready_games};
pub use runtime::{FriendarazziScheduler, FriendarazziSchedulerConfig, SchedulerFuture};
68 changes: 66 additions & 2 deletions backend/scheduler/tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use friendarazzi_core::{
},
ports::{ClientKey, Clock, RepositoryError},
service::{
CreateGame, DraftPromptInput, JoinGame, LockDraftPrompts, RegistrierungAbschließen,
RegistrierungStarten, SaveDraftPrompts, StartDrafting,
CreateGame, DraftPromptInput, HostFillRemainingDrafts, JoinGame, LockDraftPrompts,
RegistrierungAbschließen, RegistrierungStarten, SaveDraftPrompts, StartDrafting,
},
uow::UnitOfWorkProvider,
};
Expand Down Expand Up @@ -75,6 +75,69 @@ pub async fn load_game(app: &App, game_id: GameId) -> Game {
.unwrap()
}

#[allow(dead_code)]
pub async fn setup_active_game_with_deadline(
uow_provider: Box<dyn UnitOfWorkProvider>,
clock: Arc<FixedClock>,
ends_at: DateTime<Utc>,
) -> (App, GameId) {
let mail = Arc::new(FakeMailSender::new());
let app = App::builder()
.uow_provider(uow_provider)
.signing(Arc::new(InMemorySigning::from_secret_bytes(&[9u8; 32])))
.throttle(Arc::new(InMemoryThrottle::new()))
.mail_sender(Arc::clone(&mail) as Arc<dyn friendarazzi_core::ports::MailSender>)
.konto(IdentityProviderConfiguration::neu(
"friendarazzi.app",
"friendarazzi-api",
))
.clock(clock.clone() as Arc<dyn Clock>)
.rng(Arc::new(FixedRng::default()))
.build();

let alice = register(&app, &mail, "exp-a@example.com").await;
let bob = register(&app, &mail, "exp-b@example.com").await;
let carol = register(&app, &mail, "exp-c@example.com").await;

let game = app
.execute(
alice,
CreateGame {
title: NonEmptyString::neu("Expire Sched").unwrap(),
grid_size: GridSize::Three,
visibility_mode: VisibilityMode::LiveFeed,
draft_deadline_at: None,
ends_at: Some(ends_at),
},
)
.await
.unwrap();
for guest in [bob, carol] {
app.execute(
guest,
JoinGame {
invite_code: game.invite_code().clone(),
},
)
.await
.unwrap();
}
app.execute(alice, StartDrafting { game_id: game.id() })
.await
.unwrap();
app.execute(
alice,
HostFillRemainingDrafts {
game_id: game.id(),
start_immediately: true,
},
)
.await
.unwrap();

(app, game.id())
}

pub async fn setup_locked_drafting_game(
uow_provider: Box<dyn UnitOfWorkProvider>,
clock: Arc<FixedClock>,
Expand Down Expand Up @@ -105,6 +168,7 @@ pub async fn setup_locked_drafting_game(
grid_size: GridSize::Three,
visibility_mode: VisibilityMode::LiveFeed,
draft_deadline_at: None,
ends_at: None,
},
)
.await
Expand Down
32 changes: 30 additions & 2 deletions backend/scheduler/tests/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::sync::Arc;
use std::time::Duration as StdDuration;

use chrono::Duration;
use friendarazzi_core::domain::{Game, READY_GRACE_PERIOD_SECONDS};
use friendarazzi_core::domain::{CompletionReason, Game, READY_GRACE_PERIOD_SECONDS};
use friendarazzi_fakes::{FakeUnitOfWorkProvider, FixedClock};
use friendarazzi_scheduler::{InMemoryStateStore, run_start_ready_games};
use friendarazzi_scheduler::{InMemoryStateStore, run_finish_expired_games, run_start_ready_games};

#[test_log::test(tokio::test)]
async fn job_activates_ready_game_past_deadline() {
Expand Down Expand Up @@ -59,3 +59,31 @@ async fn scheduler_framework_with_in_memory_store() {
)
.await;
}

#[test_log::test(tokio::test)]
async fn job_finishes_expired_active_game_past_ends_at() {
use friendarazzi_core::ports::Clock;

let clock = Arc::new(FixedClock::new(cases::test_time()));
let ends_at = clock.now() + Duration::minutes(10);
let (app, game_id) = cases::setup_active_game_with_deadline(
Box::new(FakeUnitOfWorkProvider::empty()),
clock.clone(),
ends_at,
)
.await;

run_finish_expired_games(&app).await.unwrap();
assert!(matches!(
cases::load_game(&app, game_id).await,
Game::Active(_)
));

clock.advance_by(Duration::minutes(11));
run_finish_expired_games(&app).await.unwrap();
let Game::Completed(done) = cases::load_game(&app, game_id).await else {
panic!("expected game to complete after ends_at");
};
assert_eq!(done.completion_reason(), CompletionReason::Deadline);
assert_eq!(done.winner_user_id(), None);
}
Loading
Loading