From aea035a6d45929cb734eee95f1481639f91ea8d6 Mon Sep 17 00:00:00 2001 From: JieningYu Date: Tue, 16 Apr 2024 20:52:49 +0800 Subject: [PATCH] fix screen filtering --- src/config.rs | 3 +++ src/handle/post.rs | 4 ++-- src/tests/mod.rs | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 5930a8f..4cb424c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,6 +18,9 @@ pub struct Config { /// The root path of resource files. pub resource_path: PathBuf, + + /// Numbers of public screens. + pub screens: usize, } /// SMTP mailing configuration. diff --git a/src/handle/post.rs b/src/handle/post.rs index 1f250dc..4556167 100644 --- a/src/handle/post.rs +++ b/src/handle/post.rs @@ -236,7 +236,7 @@ pub async fn filter( screen, }): Query, auth: Auth, - State(Global { worlds, .. }): State>, + State(Global { worlds, config, .. }): State>, ) -> Result, Error> { let select = sd!(worlds.account, auth.account); let lazy_this = va!(auth, select); @@ -279,7 +279,7 @@ pub async fn filter( let mut posts = Vec::new(); while let Some(Ok(lazy)) = iter.next().await { if from.is_some_and(|a| lazy.id() <= a.0) - || screen.is_some_and(|s| lazy.id() % (s + 1) as u64 != 0) + || screen.is_some_and(|s| lazy.id() % config.screens as u64 != s as u64) { continue; } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 487e31c..a4855cc 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -24,6 +24,7 @@ fn router() -> (Global, Router) { db_path: Default::default(), port: 8080, resource_path: PathBuf::from(".test/resources"), + screens: 2, }; let state = Global { smtp_transport: Arc::new(config.smtp.to_transport().unwrap()),