diff --git a/ext_calckey_model/src/note_model.rs b/ext_calckey_model/src/note_model.rs index 5d2283e..de2b0d7 100644 --- a/ext_calckey_model/src/note_model.rs +++ b/ext_calckey_model/src/note_model.rs @@ -1,11 +1,12 @@ use sea_orm::sea_query::{Alias, Expr, IntoIden, SelectExpr, SimpleExpr}; use sea_orm::{ ColumnTrait, DbErr, EntityTrait, FromQueryResult, Iden, Iterable, JoinType, QueryFilter, - QueryResult, QuerySelect, RelationTrait, Select, + QueryResult, QuerySelect, QueryTrait, RelationTrait, Select, }; use serde::{Deserialize, Serialize}; use ck::{drive_file, note, user}; +use magnetar_sdk::types::RangeFilter; use once_cell::unsync::Lazy; use crate::{AliasSourceExt, CalckeyDbError, CalckeyModel}; @@ -81,6 +82,7 @@ pub trait NoteVisibilityFilterFactory { pub struct NoteResolveOptions { visibility_filter: Box, + time_range: Option, with_user: bool, with_reply_target: bool, with_renote_target: bool, @@ -136,8 +138,17 @@ impl NoteResolver { let visibility_filter = options .visibility_filter .with_note_and_user_tables(None, Some(ALIAS_USER.clone())); + let time_filter = options.time_range.as_ref().map(|f| match f { + RangeFilter::TimeStart(start) => note::Column::CreatedAt.gte(start.clone()), + RangeFilter::TimeRange(range) => { + note::Column::CreatedAt.between(range.start().clone(), range.end().clone()) + } + RangeFilter::TimeEnd(end) => note::Column::CreatedAt.lt(end.clone()), + }); + let notes = select .filter(visibility_filter) + .apply_if(time_filter, Select::::filter) .into_model::() .one(self.db.inner()) .await?;