add: post likes page
fix: requests pkey
This commit is contained in:
parent
bbb629336f
commit
b63df2cb31
11 changed files with 274 additions and 14 deletions
|
@ -72,6 +72,7 @@ pub const COMMUNITIES_QUESTIONS: &str = include_str!("./public/html/communities/
|
|||
pub const POST_POST: &str = include_str!("./public/html/post/post.html");
|
||||
pub const POST_REPOSTS: &str = include_str!("./public/html/post/reposts.html");
|
||||
pub const POST_QUOTES: &str = include_str!("./public/html/post/quotes.html");
|
||||
pub const POST_LIKES: &str = include_str!("./public/html/post/likes.html");
|
||||
|
||||
pub const TIMELINES_HOME: &str = include_str!("./public/html/timelines/home.html");
|
||||
pub const TIMELINES_POPULAR: &str = include_str!("./public/html/timelines/popular.html");
|
||||
|
@ -270,6 +271,7 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
|
|||
write_template!(html_path->"post/post.html"(crate::assets::POST_POST) -d "post" --config=config);
|
||||
write_template!(html_path->"post/reposts.html"(crate::assets::POST_REPOSTS) --config=config);
|
||||
write_template!(html_path->"post/quotes.html"(crate::assets::POST_QUOTES) --config=config);
|
||||
write_template!(html_path->"post/likes.html"(crate::assets::POST_LIKES) --config=config);
|
||||
|
||||
write_template!(html_path->"timelines/home.html"(crate::assets::TIMELINES_HOME) -d "timelines" --config=config);
|
||||
write_template!(html_path->"timelines/popular.html"(crate::assets::TIMELINES_POPULAR) --config=config);
|
||||
|
|
|
@ -90,6 +90,7 @@ version = "1.0.0"
|
|||
"communities:label.replies" = "Replies"
|
||||
"communities:label.reposts" = "Reposts"
|
||||
"communities:label.quotes" = "Quotes"
|
||||
"communities:label.likes" = "Likes"
|
||||
"communities:action.continue_thread" = "Continue thread"
|
||||
"communities:tab.members" = "Members"
|
||||
"communities:label.select_member" = "Select member"
|
||||
|
|
74
crates/app/src/public/html/post/likes.html
Normal file
74
crates/app/src/public/html/post/likes.html
Normal file
|
@ -0,0 +1,74 @@
|
|||
{% extends "root.html" %} {% block head %}
|
||||
<title>Post quotes - {{ config.name }}</title>
|
||||
{% endblock %} {% block body %} {{ macros::nav() }}
|
||||
<main class="flex flex-col gap-2">
|
||||
{% if post.replying_to %}
|
||||
<a href="/post/{{ post.replying_to }}" class="button">
|
||||
{{ icon "arrow-up" }}
|
||||
<span>{{ text "communities:action.continue_thread" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
<div style="display: contents;">
|
||||
{% if post.context.repost and post.context.repost.reposting %}
|
||||
{{ components::repost(repost=reposting, post=post, owner=owner, community=community, show_community=true, can_manage_post=can_manage_posts) }}
|
||||
{% else %}
|
||||
{{ components::post(post=post, owner=owner, question=question, community=community, show_community=true, can_manage_post=can_manage_posts) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="pillmenu">
|
||||
<a href="/post/{{ post.id }}#/replies">
|
||||
{{ icon "newspaper" }}
|
||||
<span>{{ text "communities:label.replies" }}</span>
|
||||
</a>
|
||||
|
||||
<a href="/post/{{ post.id }}/reposts">
|
||||
{{ icon "repeat-2" }}
|
||||
<span>{{ text "communities:label.reposts" }}</span>
|
||||
</a>
|
||||
|
||||
<a href="/post/{{ post.id }}/reposts?quotes=true">
|
||||
{{ icon "quote" }}
|
||||
<span>{{ text "communities:label.quotes" }}</span>
|
||||
</a>
|
||||
|
||||
<a href="/post/{{ post.id }}/likes" class="active">
|
||||
{{ icon "heart" }}
|
||||
<span>{{ text "communities:label.likes" }}</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if (user and user.id == post.owner) or can_manage_posts %} {% if user and
|
||||
user.id == post.owner %}
|
||||
<div class="pillmenu">
|
||||
<a href="/post/{{ post.id }}#/edit">
|
||||
{{ icon "pen" }}
|
||||
<span>{{ text "communities:label.edit_content" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="/post/{{ post.id }}#/configure">
|
||||
{{ icon "settings" }}
|
||||
<span>{{ text "communities:action.configure" }}</span>
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card-nest w-full">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "heart" }}
|
||||
<span>{{ text "communities:label.likes" }}</span>
|
||||
</div>
|
||||
|
||||
<div class="card flex flex-col gap-4">
|
||||
<!-- prettier-ignore -->
|
||||
{% for user in list %}
|
||||
{{ components::user_plate(user=user, secondary=true) }}
|
||||
{% endfor %}
|
||||
|
||||
{{ components::pagination(page=page, items=list|length) }}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
|
@ -74,19 +74,26 @@
|
|||
<span>{{ text "communities:label.quotes" }}</span>
|
||||
</a>
|
||||
|
||||
{% if user and user.id == post.owner %}
|
||||
<a href="/post/{{ post.id }}/likes">
|
||||
{{ icon "heart" }}
|
||||
<span>{{ text "communities:label.likes" }}</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if (user and user.id == post.owner) or can_manage_posts %} {% if user and
|
||||
user.id == post.owner %}
|
||||
<div class="pillmenu">
|
||||
<a href="#/edit" data-tab-button="edit">
|
||||
{{ icon "pen" }}
|
||||
<span>{{ text "communities:label.edit_content" }}</span>
|
||||
</a>
|
||||
{% endif %} {% if (user and user.id == post.owner) or can_manage_posts
|
||||
%}
|
||||
{% endif %}
|
||||
<a href="#/configure" data-tab-button="configure">
|
||||
{{ icon "settings" }}
|
||||
<span>{{ text "communities:action.configure" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="flex flex-col gap-2 hidden" data-tab="configure">
|
||||
<div class="card-nest w-full">
|
||||
|
|
|
@ -34,19 +34,26 @@
|
|||
<span>{{ text "communities:label.quotes" }}</span>
|
||||
</a>
|
||||
|
||||
{% if user and user.id == post.owner %}
|
||||
<a href="/post/{{ post.id }}/likes">
|
||||
{{ icon "heart" }}
|
||||
<span>{{ text "communities:label.likes" }}</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if (user and user.id == post.owner) or can_manage_posts %} {% if user and
|
||||
user.id == post.owner %}
|
||||
<div class="pillmenu">
|
||||
<a href="/post/{{ post.id }}#/edit">
|
||||
{{ icon "pen" }}
|
||||
<span>{{ text "communities:label.edit_content" }}</span>
|
||||
</a>
|
||||
{% endif %} {% if (user and user.id == post.owner) or can_manage_posts
|
||||
%}
|
||||
{% endif %}
|
||||
<a href="/post/{{ post.id }}#/configure">
|
||||
{{ icon "settings" }}
|
||||
<span>{{ text "communities:action.configure" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card-nest w-full">
|
||||
<div class="card small flex items-center gap-2">
|
||||
|
|
|
@ -34,19 +34,26 @@
|
|||
<span>{{ text "communities:label.quotes" }}</span>
|
||||
</a>
|
||||
|
||||
{% if user and user.id == post.owner %}
|
||||
<a href="/post/{{ post.id }}/likes">
|
||||
{{ icon "heart" }}
|
||||
<span>{{ text "communities:label.likes" }}</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if (user and user.id == post.owner) or can_manage_posts %} {% if user and
|
||||
user.id == post.owner %}
|
||||
<div class="pillmenu">
|
||||
<a href="/post/{{ post.id }}#/edit">
|
||||
{{ icon "pen" }}
|
||||
<span>{{ text "communities:label.edit_content" }}</span>
|
||||
</a>
|
||||
{% endif %} {% if (user and user.id == post.owner) or can_manage_posts
|
||||
%}
|
||||
{% endif %}
|
||||
<a href="/post/{{ post.id }}#/configure">
|
||||
{{ icon "settings" }}
|
||||
<span>{{ text "communities:action.configure" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card-nest w-full">
|
||||
<div class="card small flex items-center gap-2">
|
||||
|
|
|
@ -834,6 +834,120 @@ pub async fn reposts_request(
|
|||
))
|
||||
}
|
||||
|
||||
/// `/post/{id}/likes`
|
||||
pub async fn likes_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Query(props): Query<RepostsQuery>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = get_user_from_token!(jar, data.0);
|
||||
|
||||
let post = match data.0.get_post_by_id(id).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
let community = match data.0.get_community_by_id(post.community).await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
let ignore_users = if let Some(ref ua) = user {
|
||||
data.0.get_userblocks_receivers(ua.id).await
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
// ...
|
||||
let owner = match data.0.get_user_by_id(post.owner).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
check_user_blocked_or_private!(user, owner, data, jar);
|
||||
|
||||
// check repost
|
||||
let reposting = data.0.get_post_reposting(&post, &ignore_users).await;
|
||||
|
||||
// check question
|
||||
let question = match data.0.get_post_question(&post, &ignore_users).await {
|
||||
Ok(q) => q,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
|
||||
if !can_read {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
||||
));
|
||||
}
|
||||
|
||||
// ...
|
||||
let ignore_users = if let Some(ref ua) = user {
|
||||
data.0.get_userblocks_receivers(ua.id).await
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let list = match data.0.get_reactions_by_asset(post.id, 12, props.page).await {
|
||||
Ok(p) => match data.0.fill_reactions(&p, ignore_users).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)),
|
||||
};
|
||||
|
||||
// init context
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &user).await;
|
||||
|
||||
let (
|
||||
is_owner,
|
||||
is_joined,
|
||||
is_pending,
|
||||
can_post,
|
||||
can_manage_posts,
|
||||
can_manage_community,
|
||||
can_manage_roles,
|
||||
can_manage_questions,
|
||||
) = community_context_bools!(data, user, community);
|
||||
|
||||
context.insert("post", &post);
|
||||
context.insert("question", &question);
|
||||
context.insert("reposting", &reposting);
|
||||
context.insert("list", &list);
|
||||
context.insert("page", &props.page);
|
||||
context.insert(
|
||||
"owner",
|
||||
&data
|
||||
.0
|
||||
.get_user_by_id(post.owner)
|
||||
.await
|
||||
.unwrap_or(User::deleted()),
|
||||
);
|
||||
|
||||
community_context(
|
||||
&mut context,
|
||||
&community,
|
||||
is_owner,
|
||||
is_joined,
|
||||
is_pending,
|
||||
can_post,
|
||||
can_read,
|
||||
can_manage_posts,
|
||||
can_manage_community,
|
||||
can_manage_roles,
|
||||
can_manage_questions,
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("post/likes.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/community/{title}/members`
|
||||
pub async fn members_request(
|
||||
jar: CookieJar,
|
||||
|
|
|
@ -89,6 +89,7 @@ pub fn routes() -> Router {
|
|||
)
|
||||
.route("/post/{id}", get(communities::post_request))
|
||||
.route("/post/{id}/reposts", get(communities::reposts_request))
|
||||
.route("/post/{id}/likes", get(communities::likes_request))
|
||||
.route("/question/{id}", get(communities::question_request))
|
||||
// chats
|
||||
.route("/chats", get(chats::redirect_request))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue