Note filtering by time frame
This commit is contained in:
parent
3cd43d840a
commit
4bbc368f92
|
@ -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<dyn NoteVisibilityFilterFactory>,
|
||||
time_range: Option<RangeFilter>,
|
||||
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::<note::Entity>::filter)
|
||||
.into_model::<NoteData>()
|
||||
.one(self.db.inner())
|
||||
.await?;
|
||||
|
|
Loading…
Reference in New Issue