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_LIST: &str = include_str!("./public/html/communities/list.html");
|
||||||
pub const COMMUNITIES_BASE: &str = include_str!("./public/html/communities/base.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_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_SETTINGS: &str = include_str!("./public/html/communities/settings.html");
|
||||||
pub const COMMUNITIES_MEMBERS: &str = include_str!("./public/html/communities/members.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");
|
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_QUESTION: &str = include_str!("./public/html/communities/question.html");
|
||||||
pub const COMMUNITIES_QUESTIONS: &str = include_str!("./public/html/communities/questions.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_HOME: &str = include_str!("./public/html/timelines/home.html");
|
||||||
pub const TIMELINES_POPULAR: &str = include_str!("./public/html/timelines/popular.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");
|
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/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/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/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/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/members.html"(crate::assets::COMMUNITIES_MEMBERS) --config=config);
|
||||||
write_template!(html_path->"communities/search.html"(crate::assets::COMMUNITIES_SEARCH) --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/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->"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/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/popular.html"(crate::assets::TIMELINES_POPULAR) --config=config);
|
||||||
write_template!(html_path->"timelines/following.html"(crate::assets::TIMELINES_FOLLOWING) --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.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.create_reply" = "Create reply"
|
||||||
"communities:label.replies" = "Replies"
|
"communities:label.replies" = "Replies"
|
||||||
|
"communities:label.reposts" = "Reposts"
|
||||||
|
"communities:label.quotes" = "Quotes"
|
||||||
"communities:action.continue_thread" = "Continue thread"
|
"communities:action.continue_thread" = "Continue thread"
|
||||||
"communities:tab.members" = "Members"
|
"communities:tab.members" = "Members"
|
||||||
"communities:label.select_member" = "Select member"
|
"communities:label.select_member" = "Select member"
|
||||||
|
|
|
@ -79,6 +79,7 @@ secondary=false) -%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{% if not user or not user.settings.hide_dislikes %}
|
||||||
<button
|
<button
|
||||||
title="Dislike"
|
title="Dislike"
|
||||||
class="{% if secondary %}quaternary{% else %}camo{% endif %} small"
|
class="{% if secondary %}quaternary{% else %}camo{% endif %} small"
|
||||||
|
@ -89,8 +90,8 @@ secondary=false) -%}
|
||||||
<span>{{ dislikes }}</span>
|
<span>{{ dislikes }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</button>
|
</button>
|
||||||
{%- endmacro %} {% macro full_username(user) -%}
|
{% endif %} {%- endmacro %} {% macro full_username(user) -%}
|
||||||
<div class="flex">
|
<div class="flex items-center">
|
||||||
<a href="/@{{ user.username }}" class="flush" style="font-weight: 600">
|
<a href="/@{{ user.username }}" class="flush" style="font-weight: 600">
|
||||||
{{ components::username(user=user) }}
|
{{ components::username(user=user) }}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -48,24 +48,35 @@
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endif %} {% if user and user.id == post.owner or can_manage_posts %}
|
{% endif %}
|
||||||
<div class="pillmenu">
|
<div class="pillmenu">
|
||||||
<a href="#/replies" data-tab-button="replies" class="active">
|
<a href="#/replies" data-tab-button="replies" class="active">
|
||||||
{{ icon "newspaper" }}
|
{{ icon "newspaper" }}
|
||||||
<span>{{ text "communities:label.replies" }}</span>
|
<span>{{ text "communities:label.replies" }}</span>
|
||||||
</a>
|
</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">
|
<a href="#/edit" data-tab-button="edit">
|
||||||
{{ icon "pen" }}
|
{{ icon "pen" }}
|
||||||
<span>{{ text "communities:label.edit_content" }}</span>
|
<span>{{ text "communities:label.edit_content" }}</span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %} {% if (user and user.id == post.owner) or can_manage_posts
|
||||||
|
%}
|
||||||
<a href="#/configure" data-tab-button="configure">
|
<a href="#/configure" data-tab-button="configure">
|
||||||
{{ icon "settings" }}
|
{{ icon "settings" }}
|
||||||
<span>{{ text "communities:action.configure" }}</span>
|
<span>{{ text "communities:action.configure" }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col gap-2 hidden" data-tab="configure">
|
<div class="flex flex-col gap-2 hidden" data-tab="configure">
|
||||||
|
@ -169,7 +180,7 @@
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</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-nest w-full hidden" data-tab="edit">
|
||||||
<div class="card small flex items-center gap-2">
|
<div class="card small flex items-center gap-2">
|
||||||
{{ icon "pen" }}
|
{{ icon "pen" }}
|
||||||
|
@ -223,7 +234,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{% endif %} {% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="card-nest w-full" data-tab="replies">
|
<div class="card-nest w-full" data-tab="replies">
|
||||||
<div class="card small flex items-center gap-2">
|
<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"
|
ui_ident="awful_contrast"
|
||||||
>
|
>
|
||||||
<div class="flex gap-2 items-center">
|
<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>
|
<b>Some of your custom colors fail contrast checks:</b>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -830,6 +832,17 @@
|
||||||
settings.anonymous_avatar_url,
|
settings.anonymous_avatar_url,
|
||||||
"input",
|
"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,
|
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.",
|
"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",
|
"text",
|
||||||
],
|
],
|
||||||
|
|
||||||
[
|
[
|
||||||
["theme_hue", "Theme hue (integer 0-255)"],
|
["theme_hue", "Theme hue (integer 0-255)"],
|
||||||
"{{ profile.settings.theme_hue }}",
|
"{{ 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 crate::{assets::initial_context, get_lang, get_user_from_token, sanitize::clean_context, State};
|
||||||
use axum::{
|
use axum::{
|
||||||
Extension,
|
Extension,
|
||||||
|
@ -327,12 +327,18 @@ pub async fn feed_request(
|
||||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
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
|
let feed = match data
|
||||||
.0
|
.0
|
||||||
.get_posts_by_community(community.id, 12, props.page)
|
.get_posts_by_community(community.id, 12, props.page)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(p) => match data.0.fill_posts(p).await {
|
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
|
||||||
Ok(p) => p,
|
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)),
|
||||||
},
|
},
|
||||||
|
@ -340,7 +346,7 @@ pub async fn feed_request(
|
||||||
};
|
};
|
||||||
|
|
||||||
let pinned = match data.0.get_pinned_posts_by_community(community.id).await {
|
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,
|
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)),
|
||||||
},
|
},
|
||||||
|
@ -423,12 +429,18 @@ pub async fn questions_request(
|
||||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
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
|
let feed = match data
|
||||||
.0
|
.0
|
||||||
.get_questions_by_community(community.id, 12, props.page)
|
.get_questions_by_community(community.id, 12, props.page)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(p) => match data.0.fill_questions(p).await {
|
Ok(p) => match data.0.fill_questions(p, &ignore_users).await {
|
||||||
Ok(p) => p,
|
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)),
|
||||||
},
|
},
|
||||||
|
@ -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 {
|
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,
|
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)),
|
||||||
},
|
},
|
||||||
|
@ -628,9 +646,132 @@ pub async fn post_request(
|
||||||
can_manage_questions,
|
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
|
// return
|
||||||
Ok(Html(
|
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
|
let feed = match data
|
||||||
.0
|
.0
|
||||||
.get_posts_by_question(question.id, 12, props.page)
|
.get_posts_by_question(question.id, 12, props.page)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(p) => match data.0.fill_posts(p).await {
|
Ok(p) => match data.0.fill_posts(p, &ignore_users).await {
|
||||||
Ok(p) => p,
|
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)),
|
||||||
},
|
},
|
||||||
|
|
|
@ -42,12 +42,18 @@ pub async fn index_request(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||||
|
|
||||||
let list = match data
|
let list = match data
|
||||||
.0
|
.0
|
||||||
.get_posts_from_user_communities(user.id, 12, req.page)
|
.get_posts_from_user_communities(user.id, 12, req.page)
|
||||||
.await
|
.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,
|
Ok(l) => l,
|
||||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
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 data = data.read().await;
|
||||||
let user = get_user_from_token!(jar, data.0);
|
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 {
|
let list = match data.0.get_popular_posts(12, req.page, 604_800_000).await {
|
||||||
Ok(l) => match data
|
Ok(l) => match data
|
||||||
.0
|
.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
|
.await
|
||||||
{
|
{
|
||||||
Ok(l) => l,
|
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
|
let list = match data
|
||||||
.0
|
.0
|
||||||
.get_posts_from_user_following(user.id, 12, req.page)
|
.get_posts_from_user_following(user.id, 12, req.page)
|
||||||
.await
|
.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,
|
Ok(l) => l,
|
||||||
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)),
|
||||||
},
|
},
|
||||||
|
@ -138,10 +160,20 @@ pub async fn all_request(
|
||||||
let data = data.read().await;
|
let data = data.read().await;
|
||||||
let user = get_user_from_token!(jar, data.0);
|
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 {
|
let list = match data.0.get_latest_posts(12, req.page).await {
|
||||||
Ok(l) => match data
|
Ok(l) => match data
|
||||||
.0
|
.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
|
.await
|
||||||
{
|
{
|
||||||
Ok(l) => l,
|
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
|
let list = match data
|
||||||
.0
|
.0
|
||||||
.get_questions_from_user_communities(user.id, 12, req.page)
|
.get_questions_from_user_communities(user.id, 12, req.page)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(l) => match data.0.fill_questions(l).await {
|
Ok(l) => match data.0.fill_questions(l, &ignore_users).await {
|
||||||
Ok(l) => l,
|
Ok(l) => l,
|
||||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
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
|
let list = match data
|
||||||
.0
|
.0
|
||||||
.get_popular_global_questions(12, req.page, 604_800_000)
|
.get_popular_global_questions(12, req.page, 604_800_000)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(l) => match data.0.fill_questions(l).await {
|
Ok(l) => match data.0.fill_questions(l, &ignore_users).await {
|
||||||
Ok(l) => l,
|
Ok(l) => l,
|
||||||
Err(e) => return Html(render_error(e, &jar, &data, &Some(user)).await),
|
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
|
let list = match data
|
||||||
.0
|
.0
|
||||||
.get_questions_from_user_following(user.id, 12, req.page)
|
.get_questions_from_user_following(user.id, 12, req.page)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(l) => match data.0.fill_questions(l).await {
|
Ok(l) => match data.0.fill_questions(l, &ignore_users).await {
|
||||||
Ok(l) => l,
|
Ok(l) => l,
|
||||||
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)),
|
||||||
},
|
},
|
||||||
|
@ -283,8 +321,14 @@ pub async fn all_questions_request(
|
||||||
let data = data.read().await;
|
let data = data.read().await;
|
||||||
let user = get_user_from_token!(jar, data.0);
|
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 {
|
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,
|
Ok(l) => l,
|
||||||
Err(e) => return Html(render_error(e, &jar, &data, &user).await),
|
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)),
|
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
|
let questions = match data
|
||||||
.0
|
.0
|
||||||
.fill_questions({
|
.fill_questions(
|
||||||
let mut q = Vec::new();
|
{
|
||||||
|
let mut q = Vec::new();
|
||||||
|
|
||||||
for req in &requests {
|
for req in &requests {
|
||||||
if req.action_type != ActionType::Answer {
|
if req.action_type != ActionType::Answer {
|
||||||
continue;
|
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 {
|
q
|
||||||
Ok(p) => p,
|
},
|
||||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
&ignore_users,
|
||||||
});
|
)
|
||||||
}
|
|
||||||
|
|
||||||
q
|
|
||||||
})
|
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(q) => q,
|
Ok(q) => q,
|
||||||
|
|
|
@ -76,6 +76,7 @@ pub fn routes() -> Router {
|
||||||
get(communities::members_request),
|
get(communities::members_request),
|
||||||
)
|
)
|
||||||
.route("/post/{id}", get(communities::post_request))
|
.route("/post/{id}", get(communities::post_request))
|
||||||
|
.route("/post/{id}/reposts", get(communities::reposts_request))
|
||||||
.route("/question/{id}", get(communities::question_request))
|
.route("/question/{id}", get(communities::question_request))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,3 +113,11 @@ pub struct SearchedQuery {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub page: usize,
|
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
|
// 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
|
let posts = match data
|
||||||
.0
|
.0
|
||||||
.get_posts_by_user(other_user.id, 12, props.page)
|
.get_posts_by_user(other_user.id, 12, props.page)
|
||||||
|
@ -258,7 +264,11 @@ pub async fn posts_request(
|
||||||
{
|
{
|
||||||
Ok(p) => match data
|
Ok(p) => match data
|
||||||
.0
|
.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
|
.await
|
||||||
{
|
{
|
||||||
Ok(p) => p,
|
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 {
|
let pinned = match data.0.get_pinned_posts_by_user(other_user.id).await {
|
||||||
Ok(p) => match data
|
Ok(p) => match data
|
||||||
.0
|
.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
|
.await
|
||||||
{
|
{
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
|
|
|
@ -121,6 +121,7 @@ impl DataManager {
|
||||||
pub async fn fill_posts(
|
pub async fn fill_posts(
|
||||||
&self,
|
&self,
|
||||||
posts: Vec<Post>,
|
posts: Vec<Post>,
|
||||||
|
ignore_users: &Vec<usize>,
|
||||||
) -> Result<Vec<(Post, User, Option<(User, Post)>, Option<(Question, User)>)>> {
|
) -> Result<Vec<(Post, User, Option<(User, Post)>, Option<(Question, User)>)>> {
|
||||||
let mut out: Vec<(Post, User, Option<(User, Post)>, Option<(Question, User)>)> = Vec::new();
|
let mut out: Vec<(Post, User, Option<(User, Post)>, Option<(Question, User)>)> = Vec::new();
|
||||||
|
|
||||||
|
@ -128,6 +129,10 @@ impl DataManager {
|
||||||
for post in posts {
|
for post in posts {
|
||||||
let owner = post.owner;
|
let owner = post.owner;
|
||||||
|
|
||||||
|
if ignore_users.contains(&owner) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(user) = users.get(&owner) {
|
if let Some(user) = users.get(&owner) {
|
||||||
out.push((
|
out.push((
|
||||||
post.clone(),
|
post.clone(),
|
||||||
|
@ -155,6 +160,7 @@ impl DataManager {
|
||||||
&self,
|
&self,
|
||||||
posts: Vec<Post>,
|
posts: Vec<Post>,
|
||||||
user_id: usize,
|
user_id: usize,
|
||||||
|
ignore_users: &Vec<usize>,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
Vec<(
|
Vec<(
|
||||||
Post,
|
Post,
|
||||||
|
@ -177,6 +183,11 @@ impl DataManager {
|
||||||
|
|
||||||
for post in posts {
|
for post in posts {
|
||||||
let owner = post.owner;
|
let owner = post.owner;
|
||||||
|
|
||||||
|
if ignore_users.contains(&owner) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let community = post.community;
|
let community = post.community;
|
||||||
|
|
||||||
if let Some((user, community)) = seen_before.get(&(owner, community)) {
|
if let Some((user, community)) = seen_before.get(&(owner, community)) {
|
||||||
|
@ -402,6 +413,82 @@ impl DataManager {
|
||||||
Ok(res.unwrap())
|
Ok(res.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get all quoting posts by the post their quoting.
|
||||||
|
///
|
||||||
|
/// Requires that the post has content. See [`Self::get_reposts_by_quoting`]
|
||||||
|
/// for the no-content version.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `id` - the ID of the post that is being quoted
|
||||||
|
/// * `batch` - the limit of posts in each page
|
||||||
|
/// * `page` - the page number
|
||||||
|
pub async fn get_quoting_posts_by_quoting(
|
||||||
|
&self,
|
||||||
|
id: usize,
|
||||||
|
batch: usize,
|
||||||
|
page: usize,
|
||||||
|
) -> Result<Vec<Post>> {
|
||||||
|
let conn = match self.connect().await {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = query_rows!(
|
||||||
|
&conn,
|
||||||
|
"SELECT * FROM posts WHERE NOT content = '' AND context LIKE $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||||
|
params![
|
||||||
|
&format!("%\"reposting\":{id}%"),
|
||||||
|
&(batch as i64),
|
||||||
|
&((page * batch) as i64)
|
||||||
|
],
|
||||||
|
|x| { Self::get_post_from_row(x) }
|
||||||
|
);
|
||||||
|
|
||||||
|
if res.is_err() {
|
||||||
|
return Err(Error::GeneralNotFound("post".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(res.unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get all quoting posts by the post their quoting.
|
||||||
|
///
|
||||||
|
/// Requires that the post has no content. See [`Self::get_quoting_posts_by_quoting`]
|
||||||
|
/// for the content-required version.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `id` - the ID of the post that is being quoted
|
||||||
|
/// * `batch` - the limit of posts in each page
|
||||||
|
/// * `page` - the page number
|
||||||
|
pub async fn get_reposts_by_quoting(
|
||||||
|
&self,
|
||||||
|
id: usize,
|
||||||
|
batch: usize,
|
||||||
|
page: usize,
|
||||||
|
) -> Result<Vec<Post>> {
|
||||||
|
let conn = match self.connect().await {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = query_rows!(
|
||||||
|
&conn,
|
||||||
|
"SELECT * FROM posts WHERE content = '' AND context LIKE $1 ORDER BY created DESC LIMIT $2 OFFSET $3",
|
||||||
|
params![
|
||||||
|
&format!("%\"reposting\":{id}%"),
|
||||||
|
&(batch as i64),
|
||||||
|
&((page * batch) as i64)
|
||||||
|
],
|
||||||
|
|x| { Self::get_post_from_row(x) }
|
||||||
|
);
|
||||||
|
|
||||||
|
if res.is_err() {
|
||||||
|
return Err(Error::GeneralNotFound("post".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(res.unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
/// Get posts from all communities, sorted by likes.
|
/// Get posts from all communities, sorted by likes.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -694,6 +781,25 @@ impl DataManager {
|
||||||
{
|
{
|
||||||
return Err(Error::NotAllowed);
|
return Err(Error::NotAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send notification
|
||||||
|
// this would look better if rustfmt didn't give up on this line
|
||||||
|
if owner.id != rt.owner {
|
||||||
|
self.create_notification(
|
||||||
|
Notification::new(
|
||||||
|
format!(
|
||||||
|
"[@{}](/api/v1/auth/user/find/{}) has [quoted](/post/{}) your [post](/post/{})",
|
||||||
|
owner.username,
|
||||||
|
owner.id,
|
||||||
|
data.id,
|
||||||
|
rt.id
|
||||||
|
),
|
||||||
|
format!("\"{}\"", data.content),
|
||||||
|
rt.owner
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the post we're replying to allows commments
|
// check if the post we're replying to allows commments
|
||||||
|
@ -729,8 +835,8 @@ impl DataManager {
|
||||||
self.create_notification(Notification::new(
|
self.create_notification(Notification::new(
|
||||||
"You've been mentioned in a post!".to_string(),
|
"You've been mentioned in a post!".to_string(),
|
||||||
format!(
|
format!(
|
||||||
"[Somebody](/api/v1/auth/user/find/{}) mentioned you in their [post](/post/{}).",
|
"[@{}](/api/v1/auth/user/find/{}) has mentioned you in their [post](/post/{}).",
|
||||||
data.owner, data.id
|
owner.username, owner.id, data.id
|
||||||
),
|
),
|
||||||
user.id,
|
user.id,
|
||||||
))
|
))
|
||||||
|
|
|
@ -46,11 +46,19 @@ impl DataManager {
|
||||||
auto_method!(get_question_by_id()@get_question_from_row -> "SELECT * FROM questions WHERE id = $1" --name="question" --returns=Question --cache-key-tmpl="atto.question:{}");
|
auto_method!(get_question_by_id()@get_question_from_row -> "SELECT * FROM questions WHERE id = $1" --name="question" --returns=Question --cache-key-tmpl="atto.question:{}");
|
||||||
|
|
||||||
/// Fill the given vector of questions with their owner as well.
|
/// Fill the given vector of questions with their owner as well.
|
||||||
pub async fn fill_questions(&self, questions: Vec<Question>) -> Result<Vec<(Question, User)>> {
|
pub async fn fill_questions(
|
||||||
|
&self,
|
||||||
|
questions: Vec<Question>,
|
||||||
|
ignore_users: &Vec<usize>,
|
||||||
|
) -> Result<Vec<(Question, User)>> {
|
||||||
let mut out: Vec<(Question, User)> = Vec::new();
|
let mut out: Vec<(Question, User)> = Vec::new();
|
||||||
|
|
||||||
let mut seen_users: HashMap<usize, User> = HashMap::new();
|
let mut seen_users: HashMap<usize, User> = HashMap::new();
|
||||||
for question in questions {
|
for question in questions {
|
||||||
|
if ignore_users.contains(&question.owner) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ua) = seen_users.get(&question.owner) {
|
if let Some(ua) = seen_users.get(&question.owner) {
|
||||||
out.push((question, ua.to_owned()));
|
out.push((question, ua.to_owned()));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -130,7 +130,8 @@ impl DataManager {
|
||||||
.get_request_by_id_linked_asset(id, linked_asset)
|
.get_request_by_id_linked_asset(id, linked_asset)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !force && user.id != y.owner && !user.permissions.check(FinePermission::MANAGE_REQUESTS) {
|
if !force && user.id != y.owner && !user.permissions.check(FinePermission::MANAGE_REQUESTS)
|
||||||
|
{
|
||||||
return Err(Error::NotAllowed);
|
return Err(Error::NotAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::cache::Cache;
|
use crate::cache::Cache;
|
||||||
use crate::model::{Error, Result, auth::User, auth::UserBlock, permissions::FinePermission};
|
use crate::model::{Error, Result, auth::User, auth::UserBlock, permissions::FinePermission};
|
||||||
use crate::{auto_method, execute, get, query_row, params};
|
use crate::{auto_method, execute, get, params, query_row, query_rows};
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
#[cfg(feature = "sqlite")]
|
||||||
use rusqlite::Row;
|
use rusqlite::Row;
|
||||||
|
@ -75,6 +75,35 @@ impl DataManager {
|
||||||
Ok(res.unwrap())
|
Ok(res.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the receiver of all user blocks for the given `initiator`.
|
||||||
|
pub async fn get_userblocks_receivers(&self, initiator: usize) -> Vec<usize> {
|
||||||
|
let conn = match self.connect().await {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(_) => return Vec::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = query_rows!(
|
||||||
|
&conn,
|
||||||
|
"SELECT * FROM userblocks WHERE receiver = $1",
|
||||||
|
&[&(initiator as i64)],
|
||||||
|
|x| { Self::get_userblock_from_row(x) }
|
||||||
|
);
|
||||||
|
|
||||||
|
if res.is_err() {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get receivers
|
||||||
|
let mut out: Vec<usize> = Vec::new();
|
||||||
|
|
||||||
|
for b in res.unwrap() {
|
||||||
|
out.push(b.receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new user block in the database.
|
/// Create a new user block in the database.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|
|
@ -145,6 +145,9 @@ pub struct UserSettings {
|
||||||
/// The URL of the avatar used for anonymous users.
|
/// The URL of the avatar used for anonymous users.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub anonymous_avatar_url: String,
|
pub anonymous_avatar_url: String,
|
||||||
|
/// If dislikes are hidden for the user.
|
||||||
|
#[serde(default)]
|
||||||
|
pub hide_dislikes: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for User {
|
impl Default for User {
|
||||||
|
|
|
@ -344,10 +344,8 @@ impl Question {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
#[derive(Default)]
|
|
||||||
pub struct QuestionContext {
|
pub struct QuestionContext {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub is_nsfw: bool,
|
pub is_nsfw: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue