add: better user settings page
This commit is contained in:
parent
e8cc541f45
commit
4735832cef
16 changed files with 2398 additions and 2241 deletions
|
@ -217,21 +217,24 @@ pub async fn add_user_request(
|
|||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
};
|
||||
|
||||
// check block status
|
||||
if data
|
||||
.get_userblock_by_initiator_receiver(other_user.id, user.id)
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
// add user
|
||||
// get stack
|
||||
let mut stack = match data.get_stack_by_id(id).await {
|
||||
Ok(s) => s,
|
||||
Err(e) => return Json(e.into()),
|
||||
};
|
||||
|
||||
// check block status
|
||||
if stack.mode != StackMode::BlockList {
|
||||
if data
|
||||
.get_userblock_by_initiator_receiver(other_user.id, user.id)
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
}
|
||||
|
||||
// add user
|
||||
if stack.users.contains(&other_user.id) {
|
||||
return Json(Error::MiscError("This user is already in this stack".to_string()).into());
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use axum::{
|
|||
Extension,
|
||||
};
|
||||
use crate::cookie::CookieJar;
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tetratto_core::{
|
||||
database::FullPost,
|
||||
model::{
|
||||
|
@ -670,6 +670,20 @@ pub async fn search_request(
|
|||
))
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum TimelineOrderMode {
|
||||
/// Ordered by creation date.
|
||||
Recent,
|
||||
/// Ordered by likes - dislikes.
|
||||
Popular,
|
||||
}
|
||||
|
||||
impl Default for TimelineOrderMode {
|
||||
fn default() -> Self {
|
||||
Self::Recent
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TimelineQuery {
|
||||
#[serde(default)]
|
||||
|
@ -688,6 +702,8 @@ pub struct TimelineQuery {
|
|||
pub before: usize,
|
||||
#[serde(default)]
|
||||
pub responses_only: bool,
|
||||
#[serde(default)]
|
||||
pub order: TimelineOrderMode,
|
||||
}
|
||||
|
||||
async fn swiss_army_timeline(
|
||||
|
@ -737,7 +753,13 @@ async fn swiss_army_timeline(
|
|||
.get_responses_by_user(req.user_id, 12, req.page)
|
||||
.await
|
||||
} else {
|
||||
data.0.get_posts_by_user(req.user_id, 12, req.page).await
|
||||
if req.order == TimelineOrderMode::Recent {
|
||||
data.0.get_posts_by_user(req.user_id, 12, req.page).await
|
||||
} else {
|
||||
data.0
|
||||
.get_popular_posts_by_user(req.user_id, 12, req.page)
|
||||
.await
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if req.responses_only {
|
||||
|
|
|
@ -16,7 +16,7 @@ use axum::{
|
|||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
use crate::cookie::CookieJar;
|
||||
use crate::{cookie::CookieJar, routes::pages::misc::TimelineOrderMode};
|
||||
use serde::Deserialize;
|
||||
use tetratto_core::model::{Error, auth::User};
|
||||
use crate::{assets::initial_context, get_lang, InnerState};
|
||||
|
@ -222,6 +222,8 @@ pub struct ProfileQuery {
|
|||
pub responses_only: bool,
|
||||
#[serde(default, alias = "f")]
|
||||
pub force: bool,
|
||||
#[serde(default, alias = "o")]
|
||||
pub order: TimelineOrderMode,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
|
@ -380,6 +380,7 @@ pub async fn posts_request(
|
|||
context.insert("pinned", &pinned);
|
||||
context.insert("page", &props.page);
|
||||
context.insert("tag", &props.tag);
|
||||
context.insert("order", &props.order);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&user,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue