Skip to content

Commit

Permalink
fix screen filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Apr 16, 2024
1 parent c5fc631 commit aea035a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/handle/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub async fn filter<Io: IoHandle>(
screen,
}): Query<FilterPostsParams>,
auth: Auth,
State(Global { worlds, .. }): State<Global<Io>>,
State(Global { worlds, config, .. }): State<Global<Io>>,
) -> Result<Json<FilterPostsRes>, Error> {
let select = sd!(worlds.account, auth.account);
let lazy_this = va!(auth, select);
Expand Down Expand Up @@ -279,7 +279,7 @@ pub async fn filter<Io: IoHandle>(
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;
}
Expand Down
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn router() -> (Global<MemStorage>, 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()),
Expand Down

0 comments on commit aea035a

Please sign in to comment.