add: outbox tab on profile
tab is only visible to profile owner and mods
This commit is contained in:
parent
5dec98d698
commit
7bda718082
12 changed files with 264 additions and 9 deletions
|
@ -387,10 +387,17 @@ pub async fn notifications_request(
|
|||
))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct RequestsProps {
|
||||
#[serde(default)]
|
||||
pub id: usize,
|
||||
}
|
||||
|
||||
/// `/requests`
|
||||
pub async fn requests_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Query(props): Query<RequestsProps>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
|
@ -402,7 +409,20 @@ pub async fn requests_request(
|
|||
}
|
||||
};
|
||||
|
||||
let requests = match data.0.get_requests_by_owner(user.id).await {
|
||||
let profile = if props.id != 0 {
|
||||
match data.0.get_user_by_id(props.id).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &None).await)),
|
||||
}
|
||||
} else {
|
||||
user.clone()
|
||||
};
|
||||
|
||||
let requests = match data
|
||||
.0
|
||||
.get_requests_by_owner(if props.id != 0 { props.id } else { user.id })
|
||||
.await
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
@ -448,6 +468,8 @@ pub async fn requests_request(
|
|||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||
|
||||
context.insert("profile", &profile);
|
||||
context.insert("requests", &requests);
|
||||
context.insert("questions", &questions);
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ pub fn routes() -> Router {
|
|||
.route("/settings", get(profile::settings_request))
|
||||
.route("/@{username}", get(profile::posts_request))
|
||||
.route("/@{username}/media", get(profile::media_request))
|
||||
.route("/@{username}/outbox", get(profile::outbox_request))
|
||||
.route("/@{username}/replies", get(profile::replies_request))
|
||||
.route("/@{username}/following", get(profile::following_request))
|
||||
.route("/@{username}/followers", get(profile::followers_request))
|
||||
|
|
|
@ -573,6 +573,102 @@ pub async fn media_request(
|
|||
Ok(Html(data.1.render("profile/media.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/@{username}/outbox`
|
||||
pub async fn outbox_request(
|
||||
jar: CookieJar,
|
||||
Path(username): Path<String>,
|
||||
Query(props): Query<PaginatedQuery>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let other_user = match data.0.get_user_by_username(&username).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
if user.id != other_user.id && !user.permissions.check(FinePermission::MANAGE_QUESTIONS) {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &Some(user)).await,
|
||||
));
|
||||
}
|
||||
|
||||
check_user_blocked_or_private!(Some(user.clone()), other_user, data, jar);
|
||||
|
||||
// fetch data
|
||||
let ignore_users = crate::ignore_users_gen!(user!, data);
|
||||
|
||||
let questions = match data
|
||||
.0
|
||||
.get_questions_by_owner_paginated(other_user.id, 12, props.page)
|
||||
.await
|
||||
{
|
||||
Ok(p) => match data.0.fill_questions(p, &ignore_users).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
},
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let communities = match data.0.get_memberships_by_owner(other_user.id).await {
|
||||
Ok(m) => match data.0.fill_communities(m).await {
|
||||
Ok(m) => m,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
},
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
// init context
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user.clone())).await;
|
||||
|
||||
let is_self = user.id == other_user.id;
|
||||
|
||||
let is_following = data
|
||||
.0
|
||||
.get_userfollow_by_initiator_receiver(user.id, other_user.id)
|
||||
.await
|
||||
.is_ok();
|
||||
|
||||
let is_following_you = data
|
||||
.0
|
||||
.get_userfollow_by_receiver_initiator(user.id, other_user.id)
|
||||
.await
|
||||
.is_ok();
|
||||
|
||||
let is_blocking = data
|
||||
.0
|
||||
.get_userblock_by_initiator_receiver(user.id, other_user.id)
|
||||
.await
|
||||
.is_ok();
|
||||
|
||||
context.insert("questions", &questions);
|
||||
context.insert("page", &props.page);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&Some(user),
|
||||
&other_user,
|
||||
&communities,
|
||||
is_self,
|
||||
is_following,
|
||||
is_following_you,
|
||||
is_blocking,
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1.render("profile/outbox.html", &context).unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// `/@{username}/following`
|
||||
pub async fn following_request(
|
||||
jar: CookieJar,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue