add: infinitely scrolling timelines
This commit is contained in:
parent
822aaed0c8
commit
2b253c811c
12 changed files with 316 additions and 9 deletions
|
@ -9,7 +9,9 @@ use axum::{
|
|||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use serde::Deserialize;
|
||||
use tetratto_core::model::{permissions::FinePermission, requests::ActionType, Error};
|
||||
use tetratto_core::model::{
|
||||
auth::DefaultTimelineChoice, permissions::FinePermission, requests::ActionType, Error,
|
||||
};
|
||||
use std::fs::read_to_string;
|
||||
use pathbufd::PathBufD;
|
||||
|
||||
|
@ -649,3 +651,111 @@ pub async fn search_request(
|
|||
data.1.render("timelines/search.html", &context).unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TimelineQuery {
|
||||
pub tl: DefaultTimelineChoice,
|
||||
pub page: usize,
|
||||
}
|
||||
|
||||
/// `/_swiss_army_timeline`
|
||||
pub async fn swiss_army_timeline_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Query(req): Query<TimelineQuery>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = get_user_from_token!(jar, data.0);
|
||||
|
||||
let ignore_users = crate::ignore_users_gen!(user, data);
|
||||
|
||||
let list = match match req.tl {
|
||||
DefaultTimelineChoice::AllPosts => data.0.get_latest_posts(12, req.page).await,
|
||||
DefaultTimelineChoice::PopularPosts => {
|
||||
data.0.get_popular_posts(12, req.page, 604_800_000).await
|
||||
}
|
||||
DefaultTimelineChoice::FollowingPosts => {
|
||||
if let Some(ref ua) = user {
|
||||
data.0
|
||||
.get_posts_from_user_following(ua.id, 12, req.page)
|
||||
.await
|
||||
} else {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
||||
));
|
||||
}
|
||||
}
|
||||
DefaultTimelineChoice::MyCommunities => {
|
||||
if let Some(ref ua) = user {
|
||||
data.0
|
||||
.get_posts_from_user_communities(ua.id, 12, req.page)
|
||||
.await
|
||||
} else {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
||||
));
|
||||
}
|
||||
}
|
||||
DefaultTimelineChoice::Stack(ref s) => {
|
||||
data.0
|
||||
.get_posts_by_stack(
|
||||
match s.parse::<usize>() {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
return Err(Html(
|
||||
render_error(
|
||||
Error::MiscError("ID deserialization error".to_string()),
|
||||
&jar,
|
||||
&data,
|
||||
&user,
|
||||
)
|
||||
.await,
|
||||
));
|
||||
}
|
||||
},
|
||||
12,
|
||||
req.page,
|
||||
)
|
||||
.await
|
||||
}
|
||||
// questions bad
|
||||
_ => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
||||
));
|
||||
}
|
||||
} {
|
||||
Ok(l) => match data
|
||||
.0
|
||||
.fill_posts_with_community(
|
||||
l,
|
||||
if let Some(ref ua) = user { ua.id } else { 0 },
|
||||
&ignore_users,
|
||||
&user,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(l) => data.0.posts_muted_phrase_filter(
|
||||
&l,
|
||||
if let Some(ref ua) = user {
|
||||
Some(&ua.settings.muted)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
),
|
||||
Err(e) => return Ok(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
Err(e) => return Ok(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &user).await;
|
||||
|
||||
context.insert("list", &list);
|
||||
context.insert("page", &req.page);
|
||||
Ok(Html(
|
||||
data.1
|
||||
.render("timelines/swiss_army.html", &context)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@ pub fn routes() -> Router {
|
|||
.route("/following", get(misc::following_request))
|
||||
.route("/all", get(misc::all_request))
|
||||
.route("/search", get(misc::search_request))
|
||||
.route(
|
||||
"/_swiss_army_timeline",
|
||||
get(misc::swiss_army_timeline_request),
|
||||
)
|
||||
// question timelines
|
||||
.route("/questions", get(misc::index_questions_request))
|
||||
.route("/popular/questions", get(misc::popular_questions_request))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue