add: profile replies tab
add: profile media tab
This commit is contained in:
parent
3e4ee8126a
commit
c74f36b97c
10 changed files with 465 additions and 39 deletions
|
@ -69,6 +69,8 @@ pub fn routes() -> Router {
|
|||
// profile
|
||||
.route("/settings", get(profile::settings_request))
|
||||
.route("/@{username}", get(profile::posts_request))
|
||||
.route("/@{username}/media", get(profile::media_request))
|
||||
.route("/@{username}/replies", get(profile::replies_request))
|
||||
.route("/@{username}/following", get(profile::following_request))
|
||||
.route("/@{username}/followers", get(profile::followers_request))
|
||||
// communities
|
||||
|
|
|
@ -369,6 +369,222 @@ pub async fn posts_request(
|
|||
Ok(Html(data.1.render("profile/posts.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/@{username}/replies`
|
||||
pub async fn replies_request(
|
||||
jar: CookieJar,
|
||||
Path(username): Path<String>,
|
||||
Query(props): Query<PaginatedQuery>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = get_user_from_token!(jar, data.0);
|
||||
|
||||
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, &user).await)),
|
||||
};
|
||||
|
||||
check_user_blocked_or_private!(user, other_user, data, jar);
|
||||
|
||||
// fetch data
|
||||
let ignore_users = if let Some(ref ua) = user {
|
||||
data.0.get_userblocks_receivers(ua.id).await
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let posts = match data
|
||||
.0
|
||||
.get_replies_by_user(other_user.id, 12, props.page, &user)
|
||||
.await
|
||||
{
|
||||
Ok(p) => match data
|
||||
.0
|
||||
.fill_posts_with_community(
|
||||
p,
|
||||
if let Some(ref ua) = user { ua.id } else { 0 },
|
||||
&ignore_users,
|
||||
&user,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &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, &user).await)),
|
||||
},
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
// init context
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &user).await;
|
||||
|
||||
let is_self = if let Some(ref ua) = user {
|
||||
ua.id == other_user.id
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let is_following = if let Some(ref ua) = user {
|
||||
data.0
|
||||
.get_userfollow_by_initiator_receiver(ua.id, other_user.id)
|
||||
.await
|
||||
.is_ok()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let is_following_you = if let Some(ref ua) = user {
|
||||
data.0
|
||||
.get_userfollow_by_receiver_initiator(ua.id, other_user.id)
|
||||
.await
|
||||
.is_ok()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let is_blocking = if let Some(ref ua) = user {
|
||||
data.0
|
||||
.get_userblock_by_initiator_receiver(ua.id, other_user.id)
|
||||
.await
|
||||
.is_ok()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
context.insert("posts", &posts);
|
||||
context.insert("page", &props.page);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&user,
|
||||
&other_user,
|
||||
&communities,
|
||||
is_self,
|
||||
is_following,
|
||||
is_following_you,
|
||||
is_blocking,
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1.render("profile/replies.html", &context).unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// `/@{username}/media`
|
||||
pub async fn media_request(
|
||||
jar: CookieJar,
|
||||
Path(username): Path<String>,
|
||||
Query(props): Query<PaginatedQuery>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = get_user_from_token!(jar, data.0);
|
||||
|
||||
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, &user).await)),
|
||||
};
|
||||
|
||||
check_user_blocked_or_private!(user, other_user, data, jar);
|
||||
|
||||
// fetch data
|
||||
let ignore_users = if let Some(ref ua) = user {
|
||||
data.0.get_userblocks_receivers(ua.id).await
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let posts = match data
|
||||
.0
|
||||
.get_media_posts_by_user(other_user.id, 12, props.page, &user)
|
||||
.await
|
||||
{
|
||||
Ok(p) => match data
|
||||
.0
|
||||
.fill_posts_with_community(
|
||||
p,
|
||||
if let Some(ref ua) = user { ua.id } else { 0 },
|
||||
&ignore_users,
|
||||
&user,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &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, &user).await)),
|
||||
},
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
// init context
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &user).await;
|
||||
|
||||
let is_self = if let Some(ref ua) = user {
|
||||
ua.id == other_user.id
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let is_following = if let Some(ref ua) = user {
|
||||
data.0
|
||||
.get_userfollow_by_initiator_receiver(ua.id, other_user.id)
|
||||
.await
|
||||
.is_ok()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let is_following_you = if let Some(ref ua) = user {
|
||||
data.0
|
||||
.get_userfollow_by_receiver_initiator(ua.id, other_user.id)
|
||||
.await
|
||||
.is_ok()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let is_blocking = if let Some(ref ua) = user {
|
||||
data.0
|
||||
.get_userblock_by_initiator_receiver(ua.id, other_user.id)
|
||||
.await
|
||||
.is_ok()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
context.insert("posts", &posts);
|
||||
context.insert("page", &props.page);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&user,
|
||||
&other_user,
|
||||
&communities,
|
||||
is_self,
|
||||
is_following,
|
||||
is_following_you,
|
||||
is_blocking,
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("profile/media.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/@{username}/following`
|
||||
pub async fn following_request(
|
||||
jar: CookieJar,
|
||||
|
@ -386,27 +602,6 @@ pub async fn following_request(
|
|||
|
||||
check_user_blocked_or_private!(user, other_user, data, jar);
|
||||
|
||||
// check for private profile
|
||||
if other_user.settings.private_profile {
|
||||
if let Some(ref ua) = user {
|
||||
if ua.id != other_user.id
|
||||
&& data
|
||||
.0
|
||||
.get_userfollow_by_initiator_receiver(other_user.id, ua.id)
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// fetch data
|
||||
let list = match data
|
||||
.0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue