add: reposts/quotes pages
add: repost notification
This commit is contained in:
parent
41250ef7ed
commit
276f25a496
17 changed files with 601 additions and 50 deletions
|
@ -52,7 +52,6 @@ pub const PROFILE_PRIVATE: &str = include_str!("./public/html/profile/private.ht
|
|||
pub const COMMUNITIES_LIST: &str = include_str!("./public/html/communities/list.html");
|
||||
pub const COMMUNITIES_BASE: &str = include_str!("./public/html/communities/base.html");
|
||||
pub const COMMUNITIES_FEED: &str = include_str!("./public/html/communities/feed.html");
|
||||
pub const COMMUNITIES_POST: &str = include_str!("./public/html/communities/post.html");
|
||||
pub const COMMUNITIES_SETTINGS: &str = include_str!("./public/html/communities/settings.html");
|
||||
pub const COMMUNITIES_MEMBERS: &str = include_str!("./public/html/communities/members.html");
|
||||
pub const COMMUNITIES_SEARCH: &str = include_str!("./public/html/communities/search.html");
|
||||
|
@ -61,6 +60,10 @@ pub const COMMUNITIES_CREATE_POST: &str =
|
|||
pub const COMMUNITIES_QUESTION: &str = include_str!("./public/html/communities/question.html");
|
||||
pub const COMMUNITIES_QUESTIONS: &str = include_str!("./public/html/communities/questions.html");
|
||||
|
||||
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 TIMELINES_HOME: &str = include_str!("./public/html/timelines/home.html");
|
||||
pub const TIMELINES_POPULAR: &str = include_str!("./public/html/timelines/popular.html");
|
||||
pub const TIMELINES_FOLLOWING: &str = include_str!("./public/html/timelines/following.html");
|
||||
|
@ -198,7 +201,6 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
|
|||
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);
|
||||
write_template!(html_path->"communities/feed.html"(crate::assets::COMMUNITIES_FEED) --config=config);
|
||||
write_template!(html_path->"communities/post.html"(crate::assets::COMMUNITIES_POST) --config=config);
|
||||
write_template!(html_path->"communities/settings.html"(crate::assets::COMMUNITIES_SETTINGS) --config=config);
|
||||
write_template!(html_path->"communities/members.html"(crate::assets::COMMUNITIES_MEMBERS) --config=config);
|
||||
write_template!(html_path->"communities/search.html"(crate::assets::COMMUNITIES_SEARCH) --config=config);
|
||||
|
@ -206,6 +208,10 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
|
|||
write_template!(html_path->"communities/question.html"(crate::assets::COMMUNITIES_QUESTION) --config=config);
|
||||
write_template!(html_path->"communities/questions.html"(crate::assets::COMMUNITIES_QUESTIONS) --config=config);
|
||||
|
||||
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->"timelines/home.html"(crate::assets::TIMELINES_HOME) -d "timelines" --config=config);
|
||||
write_template!(html_path->"timelines/popular.html"(crate::assets::TIMELINES_POPULAR) --config=config);
|
||||
write_template!(html_path->"timelines/following.html"(crate::assets::TIMELINES_FOLLOWING) --config=config);
|
||||
|
|
|
@ -77,6 +77,8 @@ version = "1.0.0"
|
|||
"communities:label.might_need_to_join" = "You might need to join this community in order to interact with it!"
|
||||
"communities:label.create_reply" = "Create reply"
|
||||
"communities:label.replies" = "Replies"
|
||||
"communities:label.reposts" = "Reposts"
|
||||
"communities:label.quotes" = "Quotes"
|
||||
"communities:action.continue_thread" = "Continue thread"
|
||||
"communities:tab.members" = "Members"
|
||||
"communities:label.select_member" = "Select member"
|
||||
|
|
|
@ -79,6 +79,7 @@ secondary=false) -%}
|
|||
{% endif %}
|
||||
</button>
|
||||
|
||||
{% if not user or not user.settings.hide_dislikes %}
|
||||
<button
|
||||
title="Dislike"
|
||||
class="{% if secondary %}quaternary{% else %}camo{% endif %} small"
|
||||
|
@ -89,8 +90,8 @@ secondary=false) -%}
|
|||
<span>{{ dislikes }}</span>
|
||||
{% endif %}
|
||||
</button>
|
||||
{%- endmacro %} {% macro full_username(user) -%}
|
||||
<div class="flex">
|
||||
{% endif %} {%- endmacro %} {% macro full_username(user) -%}
|
||||
<div class="flex items-center">
|
||||
<a href="/@{{ user.username }}" class="flush" style="font-weight: 600">
|
||||
{{ components::username(user=user) }}
|
||||
</a>
|
||||
|
|
|
@ -48,24 +48,35 @@
|
|||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %} {% if user and user.id == post.owner or can_manage_posts %}
|
||||
{% endif %}
|
||||
<div class="pillmenu">
|
||||
<a href="#/replies" data-tab-button="replies" class="active">
|
||||
{{ icon "newspaper" }}
|
||||
<span>{{ text "communities:label.replies" }}</span>
|
||||
</a>
|
||||
|
||||
{% if user.id == post.owner %}
|
||||
<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>
|
||||
|
||||
{% if user and user.id == post.owner %}
|
||||
<a href="#/edit" data-tab-button="edit">
|
||||
{{ icon "pen" }}
|
||||
<span>{{ text "communities:label.edit_content" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% endif %} {% if (user and user.id == post.owner) or can_manage_posts
|
||||
%}
|
||||
<a href="#/configure" data-tab-button="configure">
|
||||
{{ icon "settings" }}
|
||||
<span>{{ text "communities:action.configure" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2 hidden" data-tab="configure">
|
||||
|
@ -169,7 +180,7 @@
|
|||
</script>
|
||||
</div>
|
||||
|
||||
{% if user.id == post.owner %}
|
||||
{% if user and user.id == post.owner %}
|
||||
<div class="card-nest w-full hidden" data-tab="edit">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "pen" }}
|
||||
|
@ -223,7 +234,7 @@
|
|||
});
|
||||
}
|
||||
</script>
|
||||
{% endif %} {% endif %}
|
||||
{% endif %}
|
||||
|
||||
<div class="card-nest w-full" data-tab="replies">
|
||||
<div class="card small flex items-center gap-2">
|
67
crates/app/src/public/html/post/quotes.html
Normal file
67
crates/app/src/public/html/post/quotes.html
Normal file
|
@ -0,0 +1,67 @@
|
|||
{% 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" class="active">
|
||||
{{ icon "quote" }}
|
||||
<span>{{ text "communities:label.quotes" }}</span>
|
||||
</a>
|
||||
|
||||
{% if user and user.id == post.owner %}
|
||||
<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
|
||||
%}
|
||||
<a href="/post/{{ post.id }}#/configure">
|
||||
{{ icon "settings" }}
|
||||
<span>{{ text "communities:action.configure" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="card-nest w-full">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "quote" }}
|
||||
<span>{{ text "communities:label.quotes" }}</span>
|
||||
</div>
|
||||
|
||||
<div class="card flex flex-col gap-4">
|
||||
<!-- prettier-ignore -->
|
||||
{% for post in list %}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[3], secondary=true, show_community=false) }}
|
||||
{% endfor %}
|
||||
|
||||
{{ components::pagination(page=page, items=list|length, key="quotes", value="true") }}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
86
crates/app/src/public/html/post/reposts.html
Normal file
86
crates/app/src/public/html/post/reposts.html
Normal file
|
@ -0,0 +1,86 @@
|
|||
{% extends "root.html" %} {% block head %}
|
||||
<title>Post reposts - {{ 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" class="active">
|
||||
{{ 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>
|
||||
|
||||
{% if user and user.id == post.owner %}
|
||||
<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
|
||||
%}
|
||||
<a href="/post/{{ post.id }}#/configure">
|
||||
{{ icon "settings" }}
|
||||
<span>{{ text "communities:action.configure" }}</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="card-nest w-full">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "repeat-2" }}
|
||||
<span>{{ text "communities:label.reposts" }}</span>
|
||||
</div>
|
||||
|
||||
<div class="card flex flex-col gap-4">
|
||||
{% for post in list %}
|
||||
<div class="card-nest">
|
||||
<div class="card flex items-center gap-2">
|
||||
<a href="/@{{ post[1].username }}">
|
||||
{{ components::avatar(username=post[1].username,
|
||||
size="24px", selector_type="username") }}
|
||||
</a>
|
||||
|
||||
<div class="name">
|
||||
{{ components::full_username(user=post[1]) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card flex items-center gap-2 flex-wrap secondary">
|
||||
<a
|
||||
href="/post/{{ post[0].id }}"
|
||||
class="quaternary small button"
|
||||
>
|
||||
{{ icon "external-link" }}
|
||||
<span>{{ text "general:action.open" }}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %} {{ components::pagination(page=page, items=list|length,
|
||||
key="quotes", value="false") }}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
|
@ -320,7 +320,9 @@
|
|||
ui_ident="awful_contrast"
|
||||
>
|
||||
<div class="flex gap-2 items-center">
|
||||
{{ icon "contrast" }}
|
||||
<span class="desktop" style="display: contents"
|
||||
>{{ icon "contrast" }}</span
|
||||
>
|
||||
<b>Some of your custom colors fail contrast checks:</b>
|
||||
</div>
|
||||
|
||||
|
@ -830,6 +832,17 @@
|
|||
settings.anonymous_avatar_url,
|
||||
"input",
|
||||
],
|
||||
[[], "Misc", "title"],
|
||||
[
|
||||
["hide_dislikes", "Hide post dislikes"],
|
||||
"{{ profile.settings.hide_dislikes }}",
|
||||
"checkbox",
|
||||
],
|
||||
[
|
||||
[],
|
||||
"Hides dislikes on all posts. Users can still dislike your posts, you just won't be able to see it.",
|
||||
"text",
|
||||
],
|
||||
],
|
||||
settings,
|
||||
);
|
||||
|
@ -852,7 +865,6 @@
|
|||
"Allow the site to build the theme for you given a base hue, saturation, and lightness. Scroll down to the next section to manually build the theme.",
|
||||
"text",
|
||||
],
|
||||
|
||||
[
|
||||
["theme_hue", "Theme hue (integer 0-255)"],
|
||||
"{{ profile.settings.theme_hue }}",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::{render_error, PaginatedQuery, SearchedQuery};
|
||||
use super::{render_error, PaginatedQuery, RepostsQuery, SearchedQuery};
|
||||
use crate::{assets::initial_context, get_lang, get_user_from_token, sanitize::clean_context, State};
|
||||
use axum::{
|
||||
Extension,
|
||||
|
@ -327,12 +327,18 @@ pub async fn feed_request(
|
|||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
|
||||
// ...
|
||||
let ignore_users = if let Some(ref ua) = user {
|
||||
data.0.get_userblocks_receivers(ua.id).await
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let feed = match data
|
||||
.0
|
||||
.get_posts_by_community(community.id, 12, props.page)
|
||||
.await
|
||||
{
|
||||
Ok(p) => match data.0.fill_posts(p).await {
|
||||
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
|
@ -340,7 +346,7 @@ pub async fn feed_request(
|
|||
};
|
||||
|
||||
let pinned = match data.0.get_pinned_posts_by_community(community.id).await {
|
||||
Ok(p) => match data.0.fill_posts(p).await {
|
||||
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
|
@ -423,12 +429,18 @@ pub async fn questions_request(
|
|||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
|
||||
// ...
|
||||
let ignore_users = if let Some(ref ua) = user {
|
||||
data.0.get_userblocks_receivers(ua.id).await
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let feed = match data
|
||||
.0
|
||||
.get_questions_by_community(community.id, 12, props.page)
|
||||
.await
|
||||
{
|
||||
Ok(p) => match data.0.fill_questions(p).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, &user).await)),
|
||||
},
|
||||
|
@ -570,8 +582,14 @@ pub async fn post_request(
|
|||
}
|
||||
|
||||
// ...
|
||||
let ignore_users = if let Some(ref ua) = user {
|
||||
data.0.get_userblocks_receivers(ua.id).await
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let feed = match data.0.get_post_comments(post.id, 12, props.page).await {
|
||||
Ok(p) => match data.0.fill_posts(p).await {
|
||||
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
|
@ -628,9 +646,132 @@ pub async fn post_request(
|
|||
can_manage_questions,
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("post/post.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/post/{id}/reposts`
|
||||
pub async fn reposts_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)),
|
||||
};
|
||||
|
||||
// check repost
|
||||
let reposting = data.0.get_post_reposting(&post).await;
|
||||
|
||||
// check question
|
||||
let question = match data.0.get_post_question(&post).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 = if props.quotes {
|
||||
match data
|
||||
.0
|
||||
.get_quoting_posts_by_quoting(post.id, 12, props.page)
|
||||
.await
|
||||
{
|
||||
Ok(p) => match data.0.fill_posts(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)),
|
||||
}
|
||||
} else {
|
||||
match data.0.get_reposts_by_quoting(post.id, 12, props.page).await {
|
||||
Ok(p) => match data.0.fill_posts(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("reposting", &reposting);
|
||||
context.insert("question", &question);
|
||||
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("communities/post.html", &context).unwrap(),
|
||||
data.1
|
||||
.render(
|
||||
if props.quotes {
|
||||
"post/quotes.html"
|
||||
} else {
|
||||
"post/reposts.html"
|
||||
},
|
||||
&context,
|
||||
)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -761,12 +902,18 @@ pub async fn question_request(
|
|||
}
|
||||
|
||||
// ...
|
||||
let ignore_users = if let Some(ref ua) = user {
|
||||
data.0.get_userblocks_receivers(ua.id).await
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let feed = match data
|
||||
.0
|
||||
.get_posts_by_question(question.id, 12, props.page)
|
||||
.await
|
||||
{
|
||||
Ok(p) => match data.0.fill_posts(p).await {
|
||||
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
|
|
|
@ -42,12 +42,18 @@ pub async fn index_request(
|
|||
}
|
||||
};
|
||||
|
||||
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||
|
||||
let list = match data
|
||||
.0
|
||||
.get_posts_from_user_communities(user.id, 12, req.page)
|
||||
.await
|
||||
{
|
||||
Ok(l) => match data.0.fill_posts_with_community(l, user.id).await {
|
||||
Ok(l) => match data
|
||||
.0
|
||||
.fill_posts_with_community(l, user.id, &ignore_users)
|
||||
.await
|
||||
{
|
||||
Ok(l) => l,
|
||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
||||
},
|
||||
|
@ -71,10 +77,20 @@ pub async fn popular_request(
|
|||
let data = data.read().await;
|
||||
let user = get_user_from_token!(jar, data.0);
|
||||
|
||||
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_popular_posts(12, req.page, 604_800_000).await {
|
||||
Ok(l) => match data
|
||||
.0
|
||||
.fill_posts_with_community(l, if let Some(ref ua) = user { ua.id } else { 0 })
|
||||
.fill_posts_with_community(
|
||||
l,
|
||||
if let Some(ref ua) = user { ua.id } else { 0 },
|
||||
&ignore_users,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(l) => l,
|
||||
|
@ -107,12 +123,18 @@ pub async fn following_request(
|
|||
}
|
||||
};
|
||||
|
||||
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||
|
||||
let list = match data
|
||||
.0
|
||||
.get_posts_from_user_following(user.id, 12, req.page)
|
||||
.await
|
||||
{
|
||||
Ok(l) => match data.0.fill_posts_with_community(l, user.id).await {
|
||||
Ok(l) => match data
|
||||
.0
|
||||
.fill_posts_with_community(l, user.id, &ignore_users)
|
||||
.await
|
||||
{
|
||||
Ok(l) => l,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
},
|
||||
|
@ -138,10 +160,20 @@ pub async fn all_request(
|
|||
let data = data.read().await;
|
||||
let user = get_user_from_token!(jar, data.0);
|
||||
|
||||
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_latest_posts(12, req.page).await {
|
||||
Ok(l) => match data
|
||||
.0
|
||||
.fill_posts_with_community(l, if let Some(ref ua) = user { ua.id } else { 0 })
|
||||
.fill_posts_with_community(
|
||||
l,
|
||||
if let Some(ref ua) = user { ua.id } else { 0 },
|
||||
&ignore_users,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(l) => l,
|
||||
|
@ -172,12 +204,14 @@ pub async fn index_questions_request(
|
|||
}
|
||||
};
|
||||
|
||||
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||
|
||||
let list = match data
|
||||
.0
|
||||
.get_questions_from_user_communities(user.id, 12, req.page)
|
||||
.await
|
||||
{
|
||||
Ok(l) => match data.0.fill_questions(l).await {
|
||||
Ok(l) => match data.0.fill_questions(l, &ignore_users).await {
|
||||
Ok(l) => l,
|
||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
||||
},
|
||||
|
@ -210,12 +244,14 @@ pub async fn popular_questions_request(
|
|||
}
|
||||
};
|
||||
|
||||
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||
|
||||
let list = match data
|
||||
.0
|
||||
.get_popular_global_questions(12, req.page, 604_800_000)
|
||||
.await
|
||||
{
|
||||
Ok(l) => match data.0.fill_questions(l).await {
|
||||
Ok(l) => match data.0.fill_questions(l, &ignore_users).await {
|
||||
Ok(l) => l,
|
||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
||||
},
|
||||
|
@ -250,12 +286,14 @@ pub async fn following_questions_request(
|
|||
}
|
||||
};
|
||||
|
||||
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||
|
||||
let list = match data
|
||||
.0
|
||||
.get_questions_from_user_following(user.id, 12, req.page)
|
||||
.await
|
||||
{
|
||||
Ok(l) => match data.0.fill_questions(l).await {
|
||||
Ok(l) => match data.0.fill_questions(l, &ignore_users).await {
|
||||
Ok(l) => l,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
},
|
||||
|
@ -283,8 +321,14 @@ pub async fn all_questions_request(
|
|||
let data = data.read().await;
|
||||
let user = get_user_from_token!(jar, data.0);
|
||||
|
||||
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_latest_global_questions(12, req.page).await {
|
||||
Ok(l) => match data.0.fill_questions(l).await {
|
||||
Ok(l) => match data.0.fill_questions(l, &ignore_users).await {
|
||||
Ok(l) => l,
|
||||
Err(e) => return Html(render_error(e, &jar, &data, &user).await),
|
||||
},
|
||||
|
@ -353,24 +397,31 @@ pub async fn requests_request(
|
|||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||
|
||||
let questions = match data
|
||||
.0
|
||||
.fill_questions({
|
||||
let mut q = Vec::new();
|
||||
.fill_questions(
|
||||
{
|
||||
let mut q = Vec::new();
|
||||
|
||||
for req in &requests {
|
||||
if req.action_type != ActionType::Answer {
|
||||
continue;
|
||||
for req in &requests {
|
||||
if req.action_type != ActionType::Answer {
|
||||
continue;
|
||||
}
|
||||
|
||||
q.push(match data.0.get_question_by_id(req.linked_asset).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
return Err(Html(render_error(e, &jar, &data, &Some(user)).await));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
q.push(match data.0.get_question_by_id(req.linked_asset).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
});
|
||||
}
|
||||
|
||||
q
|
||||
})
|
||||
q
|
||||
},
|
||||
&ignore_users,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(q) => q,
|
||||
|
|
|
@ -76,6 +76,7 @@ pub fn routes() -> Router {
|
|||
get(communities::members_request),
|
||||
)
|
||||
.route("/post/{id}", get(communities::post_request))
|
||||
.route("/post/{id}/reposts", get(communities::reposts_request))
|
||||
.route("/question/{id}", get(communities::question_request))
|
||||
}
|
||||
|
||||
|
@ -112,3 +113,11 @@ pub struct SearchedQuery {
|
|||
#[serde(default)]
|
||||
pub page: usize,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct RepostsQuery {
|
||||
#[serde(default)]
|
||||
pub quotes: bool,
|
||||
#[serde(default)]
|
||||
pub page: usize,
|
||||
}
|
||||
|
|
|
@ -251,6 +251,12 @@ pub async fn posts_request(
|
|||
}
|
||||
|
||||
// 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_posts_by_user(other_user.id, 12, props.page)
|
||||
|
@ -258,7 +264,11 @@ pub async fn posts_request(
|
|||
{
|
||||
Ok(p) => match data
|
||||
.0
|
||||
.fill_posts_with_community(p, if let Some(ref ua) = user { ua.id } else { 0 })
|
||||
.fill_posts_with_community(
|
||||
p,
|
||||
if let Some(ref ua) = user { ua.id } else { 0 },
|
||||
&ignore_users,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(p) => p,
|
||||
|
@ -270,7 +280,11 @@ pub async fn posts_request(
|
|||
let pinned = match data.0.get_pinned_posts_by_user(other_user.id).await {
|
||||
Ok(p) => match data
|
||||
.0
|
||||
.fill_posts_with_community(p, if let Some(ref ua) = user { ua.id } else { 0 })
|
||||
.fill_posts_with_community(
|
||||
p,
|
||||
if let Some(ref ua) = user { ua.id } else { 0 },
|
||||
&ignore_users,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(p) => p,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue