add: profile replies tab

add: profile media tab
This commit is contained in:
trisua 2025-05-18 20:51:55 -04:00
parent 3e4ee8126a
commit c74f36b97c
10 changed files with 465 additions and 39 deletions

View file

@ -58,6 +58,8 @@ pub const PROFILE_WARNING: &str = include_str!("./public/html/profile/warning.ht
pub const PROFILE_PRIVATE: &str = include_str!("./public/html/profile/private.html");
pub const PROFILE_BLOCKED: &str = include_str!("./public/html/profile/blocked.html");
pub const PROFILE_BANNED: &str = include_str!("./public/html/profile/banned.html");
pub const PROFILE_REPLIES: &str = include_str!("./public/html/profile/replies.html");
pub const PROFILE_MEDIA: &str = include_str!("./public/html/profile/media.html");
pub const COMMUNITIES_LIST: &str = include_str!("./public/html/communities/list.html");
pub const COMMUNITIES_BASE: &str = include_str!("./public/html/communities/base.html");
@ -260,6 +262,8 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
write_template!(html_path->"profile/private.html"(crate::assets::PROFILE_PRIVATE) --config=config);
write_template!(html_path->"profile/blocked.html"(crate::assets::PROFILE_BLOCKED) --config=config);
write_template!(html_path->"profile/banned.html"(crate::assets::PROFILE_BANNED) --config=config);
write_template!(html_path->"profile/replies.html"(crate::assets::PROFILE_REPLIES) --config=config);
write_template!(html_path->"profile/media.html"(crate::assets::PROFILE_MEDIA) --config=config);
write_template!(html_path->"communities/list.html"(crate::assets::COMMUNITIES_LIST) -d "communities" --config=config);
write_template!(html_path->"communities/base.html"(crate::assets::COMMUNITIES_BASE) --config=config);

View file

@ -65,6 +65,11 @@ version = "1.0.0"
"auth:label.joined_communities" = "Joined communities"
"auth:label.recent_posts" = "Recent posts"
"auth:label.recent_with_tag" = "Recent posts (with tag)"
"auth:label.recent_replies" = "Recent replies"
"auth:label.recent_posts_with_media" = "Recent posts (with media)"
"auth:label.posts" = "Posts"
"auth:label.replies" = "Replies"
"auth:label.media" = "Media"
"auth:label.before_you_view" = "Before you view"
"auth:label.private_profile" = "Private profile"
"auth:label.private_profile_message" = "This profile is private, meaning you can only view it if they follow you."

View file

@ -212,4 +212,27 @@ selected="posts") -%} {% if user -%}
<span>{{ text "communities:tab.questions" }}</span>
</a>
</div>
{%- endif %} {%- endmacro %}
{%- endif %} {%- endmacro %} {% macro profile_nav(selected="") -%}
<div class="pillmenu">
<a
href="/@{{ profile.username }}"
class="{% if selected == 'posts' -%}active{%- endif %}"
>
{{ text "auth:label.posts" }}
</a>
<a
href="/@{{ profile.username }}/replies"
class="{% if selected == 'replies' -%}active{%- endif %}"
>
{{ text "auth:label.replies" }}
</a>
<a
href="/@{{ profile.username }}/media"
class="{% if selected == 'media' -%}active{%- endif %}"
>
{{ text "auth:label.media" }}
</a>
</div>
{%- endmacro %}

View file

@ -0,0 +1,42 @@
{% extends "profile/base.html" %} {% block content %} {% if
profile.settings.enable_questions and (user or
profile.settings.allow_anonymous_questions) %}
<div style="display: contents">
{{ components::create_question_form(receiver=profile.id,
header=profile.settings.motivational_header) }}
</div>
{%- endif %} {{ macros::profile_nav(selected="media") }}
<div class="card-nest">
<div class="card small flex gap-2 justify-between items-center">
<div class="flex gap-2 items-center">
{{ icon "clock" }}
<span>{{ text "auth:label.recent_posts_with_media" }}</span>
</div>
{% if user -%}
<a
href="/search?profile={{ profile.id }}"
class="button quaternary small"
>
{{ icon "search" }}
<span>{{ text "general:link.search" }}</span>
</a>
{%- endif %}
</div>
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in posts %}
{% if post[2].read_access == "Everybody" -%}
{% if post[0].context.repost and post[0].context.repost.reposting -%}
{{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true, can_manage_post=is_self) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], can_manage_post=is_self) }}
{%- endif %}
{%- endif %}
{% endfor %}
{{ components::pagination(page=page, items=posts|length) }}
</div>
</div>
{% endblock %}

View file

@ -25,8 +25,7 @@ profile.settings.allow_anonymous_questions) %}
{% endfor %}
</div>
</div>
{%- endif %}
{%- endif %} {{ macros::profile_nav(selected="posts") }}
<div class="card-nest">
<div class="card small flex gap-2 justify-between items-center">
<div class="flex gap-2 items-center">

View file

@ -0,0 +1,42 @@
{% extends "profile/base.html" %} {% block content %} {% if
profile.settings.enable_questions and (user or
profile.settings.allow_anonymous_questions) %}
<div style="display: contents">
{{ components::create_question_form(receiver=profile.id,
header=profile.settings.motivational_header) }}
</div>
{%- endif %} {{ macros::profile_nav(selected="replies") }}
<div class="card-nest">
<div class="card small flex gap-2 justify-between items-center">
<div class="flex gap-2 items-center">
{{ icon "clock" }}
<span>{{ text "auth:label.recent_replies" }}</span>
</div>
{% if user -%}
<a
href="/search?profile={{ profile.id }}"
class="button quaternary small"
>
{{ icon "search" }}
<span>{{ text "general:link.search" }}</span>
</a>
{%- endif %}
</div>
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in posts %}
{% if post[2].read_access == "Everybody" -%}
{% if post[0].context.repost and post[0].context.repost.reposting -%}
{{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true, can_manage_post=is_self) }}
{% else %}
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], can_manage_post=is_self) }}
{%- endif %}
{%- endif %}
{% endfor %}
{{ components::pagination(page=page, items=posts|length) }}
</div>
</div>
{% endblock %}

View file

@ -40,16 +40,24 @@
/>
{%- endif %}
<button class="small square">{{ icon "search" }}</button>
<div class="flex gap-2 flex-row">
<button class="small square">
{{ icon "search" }}
</button>
{% if config.manuals.search_help -%}
<a
class="button small square secondary"
title="Search help"
href="{{ config.manuals.search_help }}"
>
{{ icon "circle-help" }}
</a>
{%- endif %}
</div>
</div>
{% if config.manuals.search_help -%}
<span
><a href="{{ config.manuals.search_help }}">
Search help
</a></span
>
{%- endif %}
<span><a> Search help </a></span>
</form>
{%- endif %}

View file

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

View file

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