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
|
@ -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