add: questions, requests
This commit is contained in:
parent
24f67221ca
commit
7960484bf9
52 changed files with 1698 additions and 100 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "tetratto"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
|
|
|
@ -35,6 +35,7 @@ pub const MISC_INDEX: &str = include_str!("./public/html/misc/index.html");
|
|||
pub const MISC_ERROR: &str = include_str!("./public/html/misc/error.html");
|
||||
pub const MISC_NOTIFICATIONS: &str = include_str!("./public/html/misc/notifications.html");
|
||||
pub const MISC_MARKDOWN: &str = include_str!("./public/html/misc/markdown.html");
|
||||
pub const MISC_REQUESTS: &str = include_str!("./public/html/misc/requests.html");
|
||||
|
||||
pub const AUTH_BASE: &str = include_str!("./public/html/auth/base.html");
|
||||
pub const AUTH_LOGIN: &str = include_str!("./public/html/auth/login.html");
|
||||
|
@ -56,6 +57,8 @@ pub const COMMUNITIES_MEMBERS: &str = include_str!("./public/html/communities/me
|
|||
pub const COMMUNITIES_SEARCH: &str = include_str!("./public/html/communities/search.html");
|
||||
pub const COMMUNITIES_CREATE_POST: &str =
|
||||
include_str!("./public/html/communities/create_post.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 TIMELINES_HOME: &str = include_str!("./public/html/timelines/home.html");
|
||||
pub const TIMELINES_POPULAR: &str = include_str!("./public/html/timelines/popular.html");
|
||||
|
@ -169,6 +172,7 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
|
|||
write_template!(html_path->"misc/error.html"(crate::assets::MISC_ERROR) --config=config);
|
||||
write_template!(html_path->"misc/notifications.html"(crate::assets::MISC_NOTIFICATIONS) --config=config);
|
||||
write_template!(html_path->"misc/markdown.html"(crate::assets::MISC_MARKDOWN) --config=config);
|
||||
write_template!(html_path->"misc/requests.html"(crate::assets::MISC_REQUESTS) --config=config);
|
||||
|
||||
write_template!(html_path->"auth/base.html"(crate::assets::AUTH_BASE) -d "auth" --config=config);
|
||||
write_template!(html_path->"auth/login.html"(crate::assets::AUTH_LOGIN) --config=config);
|
||||
|
@ -189,6 +193,8 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
|
|||
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/create_post.html"(crate::assets::COMMUNITIES_CREATE_POST) --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->"timelines/home.html"(crate::assets::TIMELINES_HOME) -d "timelines" --config=config);
|
||||
write_template!(html_path->"timelines/popular.html"(crate::assets::TIMELINES_POPULAR) --config=config);
|
||||
|
|
|
@ -19,6 +19,7 @@ version = "1.0.0"
|
|||
"general:action.back" = "Back"
|
||||
"general:action.report" = "Report"
|
||||
"general:action.manage" = "Manage"
|
||||
"general:action.open" = "Open"
|
||||
"general:label.safety" = "Safety"
|
||||
"general:label.share" = "Share"
|
||||
"general:action.add_account" = "Add account"
|
||||
|
@ -65,6 +66,7 @@ version = "1.0.0"
|
|||
"communities:label.create_post" = "Create post"
|
||||
"communities:label.content" = "Content"
|
||||
"communities:label.posts" = "Posts"
|
||||
"communities:label.questions" = "Questions"
|
||||
"communities:label.not_allowed_to_read" = "You're not allowed to view this community's posts"
|
||||
"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"
|
||||
|
@ -86,6 +88,8 @@ version = "1.0.0"
|
|||
"communities:label.search_results" = "Search results"
|
||||
"communities:label.query" = "Query"
|
||||
"communities:label.join_new" = "Join new"
|
||||
"communities:tab.posts" = "Posts"
|
||||
"communities:tab.questions" = "Questions"
|
||||
|
||||
"notifs:action.mark_as_read" = "Mark as read"
|
||||
"notifs:action.mark_as_unread" = "Mark as unread"
|
||||
|
@ -116,3 +120,9 @@ version = "1.0.0"
|
|||
"mod_panel:label.permissions_level_builder" = "Permission level builder"
|
||||
"mod_panel:label.warnings" = "Warnings"
|
||||
"mod_panel:label.create_warning" = "Create warning"
|
||||
|
||||
"requests:label.requests" = "Requests"
|
||||
"requests:label.community_join_request" = "Community join request"
|
||||
"requests:label.review" = "Review"
|
||||
"requests:label.ask_question" = "Ask question"
|
||||
"requests:label.answer" = "Answer"
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
{% import "components.html" as components %} {% extends "communities/base.html"
|
||||
%} {% block content %}
|
||||
<div class="flex flex-col gap-4 w-full">
|
||||
{% if user and can_post %}
|
||||
{{ macros::community_nav(community=community, selected="posts") }} {% if
|
||||
user and can_post %}
|
||||
<div class="card-nest">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "pencil" }}
|
||||
|
@ -45,7 +46,7 @@
|
|||
{% if post[0].context.repost and post[0].context.repost.reposting %}
|
||||
{{ components::repost(repost=post[2], post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
|
||||
{% else %}
|
||||
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[3], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
@ -64,7 +65,7 @@
|
|||
{% if post[0].context.repost and post[0].context.repost.reposting %}
|
||||
{{ components::repost(repost=post[2], post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
|
||||
{% else %}
|
||||
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[3], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
{% 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, community=community, show_community=true, can_manage_post=can_manage_posts) }}
|
||||
{{ components::post(post=post, owner=owner, question=question, community=community, show_community=true, can_manage_post=can_manage_posts) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
@ -231,7 +231,7 @@
|
|||
<div class="card flex flex-col gap-4">
|
||||
<!-- prettier-ignore -->
|
||||
{% for post in replies %}
|
||||
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false) }}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, show_community=false) }}
|
||||
{% endfor %}
|
||||
|
||||
{{ components::pagination(page=page, items=replies|length) }}
|
||||
|
|
88
crates/app/src/public/html/communities/question.html
Normal file
88
crates/app/src/public/html/communities/question.html
Normal file
|
@ -0,0 +1,88 @@
|
|||
{% extends "root.html" %} {% block head %}
|
||||
<title>Question - {{ config.name }}</title>
|
||||
{% endblock %} {% block body %} {{ macros::nav() }}
|
||||
<main class="flex flex-col gap-2">
|
||||
<div style="display: contents">
|
||||
{{ components::question(question=question, owner=owner) }}
|
||||
</div>
|
||||
|
||||
{% if user and (user.id == question.receiver or question.is_global) and not
|
||||
has_answered %}
|
||||
<div class="card-nest">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "square-pen" }}
|
||||
<b>{{ text "requests:label.answer" }}</b>
|
||||
</div>
|
||||
|
||||
<form
|
||||
class="card flex flex-col gap-2"
|
||||
onsubmit="answer_question_from_form(event, '{{ question.id }}')"
|
||||
>
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="content"
|
||||
>{{ text "communities:label.content" }}</label
|
||||
>
|
||||
<textarea
|
||||
type="text"
|
||||
name="content"
|
||||
id="content"
|
||||
placeholder="content"
|
||||
required
|
||||
minlength="2"
|
||||
maxlength="4096"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<button class="primary">
|
||||
{{ text "communities:action.create" }}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card-nest w-full" data-tab="replies">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "newspaper" }}
|
||||
<span>{{ text "communities:label.replies" }}</span>
|
||||
</div>
|
||||
|
||||
<div class="card flex flex-col gap-4">
|
||||
<!-- prettier-ignore -->
|
||||
{% for post in replies %}
|
||||
{{ components::post(post=post[0], owner=post[1], question=false, secondary=true, show_community=false) }}
|
||||
{% endfor %}
|
||||
|
||||
{{ components::pagination(page=page, items=replies|length) }}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
async function answer_question_from_form(e, answering) {
|
||||
e.preventDefault();
|
||||
await trigger("atto::debounce", ["posts::create"]);
|
||||
fetch("/api/v1/posts", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content: e.target.content.value,
|
||||
community: "{{ config.town_square }}",
|
||||
answering,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
|
||||
if (res.ok) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
45
crates/app/src/public/html/communities/questions.html
Normal file
45
crates/app/src/public/html/communities/questions.html
Normal file
|
@ -0,0 +1,45 @@
|
|||
{% import "components.html" as components %} {% extends "communities/base.html"
|
||||
%} {% block content %}
|
||||
<div class="flex flex-col gap-4 w-full">
|
||||
{{ macros::community_nav(community=community, selected="questions") }}
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
{% if user and can_post %}
|
||||
<div style="display: contents">
|
||||
{{ components::create_question_form(community=community.id,
|
||||
is_global=true) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card-nest">
|
||||
<div class="card small flex gap-2 items-center">
|
||||
{{ icon "newspaper" }}
|
||||
<span>{{ text "communities:label.questions" }}</span>
|
||||
</div>
|
||||
|
||||
<div class="card tertiary flex flex-col gap-4">
|
||||
<!-- prettier-ignore -->
|
||||
{% for question in feed %}
|
||||
<div class="card-nest">
|
||||
{{ components::question(question=question[0], owner=question[1],
|
||||
show_community=false) }}
|
||||
|
||||
<div class="card flex flex-wrap gap-2">
|
||||
<a
|
||||
href="/question/{{ question[0].id }}"
|
||||
class="button quaternary small"
|
||||
>
|
||||
{{ icon "external-link" }} {% if user %}
|
||||
<span>{{ text "requests:label.answer" }}</span>
|
||||
{% else %}
|
||||
<span>{{ text "general:action.open" }}</span>
|
||||
{% endif %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %} {{ components::pagination(page=page, items=feed|length)
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -567,6 +567,14 @@
|
|||
"{{ community.context.is_nsfw }}",
|
||||
"checkbox",
|
||||
],
|
||||
[
|
||||
[
|
||||
"enable_questions",
|
||||
"Allow users to ask questions in this community",
|
||||
],
|
||||
"{{ community.context.enable_questions }}",
|
||||
"checkbox",
|
||||
],
|
||||
],
|
||||
settings,
|
||||
);
|
||||
|
|
|
@ -143,10 +143,12 @@ community=false, show_community=true, can_manage_post=false) -%}
|
|||
);
|
||||
</script>
|
||||
</div>
|
||||
{%- endmacro %} {% macro post(post, owner, secondary=false, community=false,
|
||||
show_community=true, can_manage_post=false) -%} {% if community and
|
||||
show_community and community.id != config.town_square %}
|
||||
{%- endmacro %} {% macro post(post, owner, question=false, secondary=false,
|
||||
community=false, show_community=true, can_manage_post=false) -%} {% if community
|
||||
and show_community and community.id != config.town_square or question %}
|
||||
<div class="card-nest">
|
||||
{% if question %} {{ components::question(question=question[0],
|
||||
owner=question[1]) }} {% else %}
|
||||
<div class="card small">
|
||||
<a
|
||||
href="/api/v1/communities/find/{{ post.community }}"
|
||||
|
@ -167,15 +169,15 @@ show_community and community.id != config.town_square %}
|
|||
icon "pin" }} {% endif %}
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %} {% endif %}
|
||||
<div
|
||||
class="card flex flex-col gap-2 {% if secondary %}secondary{% endif %}"
|
||||
id="post:{{ post.id }}"
|
||||
>
|
||||
<div class="w-full flex gap-2">
|
||||
<a href="/@{{ owner.username }}">
|
||||
{{ components::avatar(username=post.owner, size="52px",
|
||||
selector_type="id") }}
|
||||
{{ components::avatar(username=owner.username, size="52px",
|
||||
selector_type="username") }}
|
||||
</a>
|
||||
|
||||
<div class="flex flex-col w-full gap-1">
|
||||
|
@ -337,7 +339,8 @@ show_community and community.id != config.town_square %}
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if community and show_community and community.id != config.town_square %}
|
||||
{% if community and show_community and community.id != config.town_square or
|
||||
question %}
|
||||
</div>
|
||||
{% endif %} {%- endmacro %} {% macro notification(notification) -%}
|
||||
<div class="w-full card-nest">
|
||||
|
@ -364,7 +367,7 @@ show_community and community.id != config.town_square %}
|
|||
{% if notification.read %}
|
||||
<button
|
||||
class="tertiary"
|
||||
onclick="trigger('me::update_notification_read_statsu', ['{{ notification.id }}', false])"
|
||||
onclick="trigger('me::update_notification_read_status', ['{{ notification.id }}', false])"
|
||||
>
|
||||
{{ icon "undo" }}
|
||||
<span>{{ text "notifs:action.mark_as_unread" }}</span>
|
||||
|
@ -372,7 +375,7 @@ show_community and community.id != config.town_square %}
|
|||
{% else %}
|
||||
<button
|
||||
class="green tertiary"
|
||||
onclick="trigger('me::update_notification_read_statsu', ['{{ notification.id }}', true])"
|
||||
onclick="trigger('me::update_notification_read_status', ['{{ notification.id }}', true])"
|
||||
>
|
||||
{{ icon "check" }}
|
||||
<span>{{ text "notifs:action.mark_as_read" }}</span>
|
||||
|
@ -589,4 +592,105 @@ and user %}
|
|||
]);
|
||||
}
|
||||
</script>
|
||||
{% endif %} {%- endmacro %}
|
||||
{% endif %} {%- endmacro %} {% macro question(question, owner,
|
||||
show_community=true, secondary=false) -%}
|
||||
<div class="card{% if secondary %} secondary{% endif %} flex gap-2">
|
||||
<a href="/@{{ owner.username }}">
|
||||
{{ components::avatar(username=owner.username, selector_type="username",
|
||||
size="52px") }}
|
||||
</a>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex items-center gap-2 flex-wrap">
|
||||
<span class="name"
|
||||
>{{ components::full_username(user=owner) }}</span
|
||||
>
|
||||
|
||||
<span class="date">{{ question.created }}</span>
|
||||
|
||||
<span
|
||||
title="Question"
|
||||
class="flex items-center"
|
||||
style="color: var(--color-primary)"
|
||||
>
|
||||
{{ icon "message-circle-heart" }}
|
||||
</span>
|
||||
|
||||
{% if question.community > 0 and show_community %}
|
||||
<a href="/api/v1/communities/find/{{ question.community }}">
|
||||
{{ components::community_avatar(id=question.community,
|
||||
size="24px") }}
|
||||
</a>
|
||||
{% endif %} {% if question.is_global %}
|
||||
<a class="notification chip" href="/question/{{ question.id }}"
|
||||
>{{ question.answer_count }} answers</a
|
||||
>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<span class="no_p_margin" style="font-weight: 500"
|
||||
>{{ question.content|markdown|safe }}</span
|
||||
>
|
||||
|
||||
<div class="flex gap-2 items-center justify-between"></div>
|
||||
</div>
|
||||
</div>
|
||||
{%- endmacro %} {% macro create_question_form(receiver="0", community="",
|
||||
is_global=false) -%}
|
||||
<div class="card-nest">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "message-circle-heart" }}
|
||||
<span>{{ text "requests:label.ask_question" }}</span>
|
||||
</div>
|
||||
|
||||
<form
|
||||
class="card flex flex-col gap-2"
|
||||
onsubmit="create_question_from_form(event)"
|
||||
>
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="content">{{ text "communities:label.content" }}</label>
|
||||
<textarea
|
||||
type="text"
|
||||
name="content"
|
||||
id="content"
|
||||
placeholder="content"
|
||||
required
|
||||
minlength="2"
|
||||
maxlength="4096"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<button class="primary">{{ text "communities:action.create" }}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
async function create_question_from_form(e) {
|
||||
e.preventDefault();
|
||||
await trigger("atto::debounce", ["questions::create"]);
|
||||
fetch("/api/v1/questions", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content: e.target.content.value,
|
||||
receiver: "{{ receiver }}",
|
||||
community: "{{ community }}",
|
||||
is_global: "{{ is_global }}" == "true",
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
|
||||
if (res.ok) {
|
||||
e.target.reset();
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{%- endmacro %}
|
||||
|
|
|
@ -15,14 +15,6 @@
|
|||
<span class="desktop">{{ text "general:link.home" }}</span>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="/popular"
|
||||
class="button {% if selected == 'popular' %}active{% endif %}"
|
||||
>
|
||||
{{ icon "trending-up" }}
|
||||
<span class="desktop">{{ text "general:link.popular" }}</span>
|
||||
</a>
|
||||
|
||||
{% if user %}
|
||||
<a
|
||||
href="/communities"
|
||||
|
@ -46,6 +38,16 @@
|
|||
{{ icon "square-pen" }}
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="/requests"
|
||||
class="button {% if selected == 'requests' %}active{% endif %}"
|
||||
title="Requests"
|
||||
>
|
||||
{{ icon "inbox" }} {% if user.request_count > 0 %}
|
||||
<span class="notification tr">{{ user.request_count }}</span>
|
||||
{% endif %}
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="/notifs"
|
||||
class="button {% if selected == 'notifications' %}active{% endif %}"
|
||||
|
@ -183,4 +185,23 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- endmacro %}
|
||||
{%- endmacro %} {% macro community_nav(community, selected="") -%} {% if
|
||||
community.context.enable_questions %}
|
||||
<div class="pillmenu">
|
||||
<a
|
||||
href="/community/{{ community.title }}"
|
||||
class="{% if selected == 'posts' %}active{% endif %}"
|
||||
>
|
||||
{{ icon "newspaper" }}
|
||||
<span>{{ text "communities:tab.posts" }}</span>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="/community/{{ community.title }}/questions"
|
||||
class="{% if selected == 'questions' %}active{% endif %}"
|
||||
>
|
||||
{{ icon "message-circle-heart" }}
|
||||
<span>{{ text "communities:tab.questions" }}</span>
|
||||
</a>
|
||||
</div>
|
||||
{% endif %} {%- endmacro %}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<button
|
||||
onclick="trigger('me::clear_notifs')"
|
||||
class="small quaternary"
|
||||
class="small red quaternary"
|
||||
>
|
||||
{{ icon "bomb" }}
|
||||
<span>{{ text "notifs:action.clear" }}</span>
|
||||
|
|
172
crates/app/src/public/html/misc/requests.html
Normal file
172
crates/app/src/public/html/misc/requests.html
Normal file
|
@ -0,0 +1,172 @@
|
|||
{% extends "root.html" %} {% block head %}
|
||||
<title>Requests - {{ config.name }}</title>
|
||||
{% endblock %} {% block body %} {{ macros::nav(selected="requests") }}
|
||||
<main class="flex flex-col gap-2">
|
||||
<div class="card-nest">
|
||||
<div class="card small flex items-center justify-between gap-2">
|
||||
<span class="flex items-center gap-2">
|
||||
{{ icon "inbox" }}
|
||||
<span>{{ text "requests:label.requests" }}</span>
|
||||
</span>
|
||||
|
||||
<button onclick="clear_requests()" class="small red quaternary">
|
||||
{{ icon "bomb" }}
|
||||
<span>{{ text "notifs:action.clear" }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="card tertiary flex flex-col gap-4">
|
||||
{% for request in requests %} {% if request.action_type ==
|
||||
"CommunityJoin" %}
|
||||
<div class="card-nest">
|
||||
<div class="card small flex items-center gap-2">
|
||||
{{ icon "user-plus" }}
|
||||
<span
|
||||
>{{ text "requests:label.community_join_request"
|
||||
}}</span
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="card flex flex-wrap gap-2">
|
||||
<a
|
||||
href="/community/{{ request.linked_asset }}/manage?uid={{ request.id }}#/members"
|
||||
class="button"
|
||||
>
|
||||
{{ icon "external-link" }}
|
||||
<span>{{ text "requests:label.review" }}</span>
|
||||
</a>
|
||||
|
||||
<button
|
||||
class="quaternary red"
|
||||
onclick="remove_request('{{ request.id }}', '{{ request.linked_asset }}')"
|
||||
>
|
||||
{{ icon "trash" }}
|
||||
<span>{{ text "general:action.delete" }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %} {% endfor %} {% for question in questions %}
|
||||
<!-- prettier-ignore -->
|
||||
<div class="card-nest">
|
||||
{{ components::question(question=question[0], owner=question[1]) }}
|
||||
|
||||
<form
|
||||
class="card flex flex-col gap-2"
|
||||
onsubmit="answer_question_from_form(event, '{{ question[0].id }}')"
|
||||
>
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="content">{{ text "communities:label.content" }}</label>
|
||||
<textarea
|
||||
type="text"
|
||||
name="content"
|
||||
id="content"
|
||||
placeholder="content"
|
||||
required
|
||||
minlength="2"
|
||||
maxlength="4096"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<button class="primary">{{ text "requests:label.answer" }}</button>
|
||||
<button class="red quaternary" onclick="remove_question('{{ question[0].id }}')">{{ text "general:action.delete" }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
async function remove_request(id, linked_asset) {
|
||||
if (
|
||||
!(await trigger("atto::confirm", [
|
||||
"Are you sure you want to do this?",
|
||||
]))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/api/v1/requests/${id}/${linked_asset}`, {
|
||||
method: "DELETE",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
async function clear_requests() {
|
||||
if (
|
||||
!(await trigger("atto::confirm", [
|
||||
"Are you sure you want to do this?",
|
||||
]))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch("/api/v1/requests/my", {
|
||||
method: "DELETE",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
async function remove_question(id) {
|
||||
if (
|
||||
!(await trigger("atto::confirm", [
|
||||
"Are you sure you want to do this?",
|
||||
]))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/api/v1/questions/${id}`, {
|
||||
method: "DELETE",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
async function answer_question_from_form(e, answering) {
|
||||
e.preventDefault();
|
||||
await trigger("atto::debounce", ["posts::create"]);
|
||||
fetch("/api/v1/posts", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
content: e.target.content.value,
|
||||
community: "{{ config.town_square }}",
|
||||
answering,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
|
||||
if (res.ok) {
|
||||
e.target.parentElement.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -121,6 +121,11 @@
|
|||
<span class="date">{{ profile.created }}</span>
|
||||
</div>
|
||||
|
||||
<div class="w-full flex justify-between items-center">
|
||||
<span class="notification chip">Posts</span>
|
||||
<span>{{ profile.post_count }}</span>
|
||||
</div>
|
||||
|
||||
{% if not profile.settings.private_last_seen or is_self
|
||||
or is_helper %}
|
||||
<div class="w-full flex justify-between items-center">
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
{% extends "profile/base.html" %} {% block content %} {% if pinned|length != 0
|
||||
%}
|
||||
{% extends "profile/base.html" %} {% block content %} {% if
|
||||
profile.settings.enable_questions and user %}
|
||||
<div style="display: contents">
|
||||
{{ components::create_question_form(receiver=profile.id) }}
|
||||
</div>
|
||||
{% endif %} {% if pinned|length != 0 %}
|
||||
<div class="card-nest">
|
||||
<div class="card small flex gap-2 items-center">
|
||||
{{ icon "pin" }}
|
||||
|
@ -12,7 +16,7 @@
|
|||
{% 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], secondary=true, community=post[2], can_manage_post=is_self) }}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], can_manage_post=is_self) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
@ -31,7 +35,7 @@
|
|||
{% 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], secondary=true, community=post[2], can_manage_post=is_self) }}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], can_manage_post=is_self) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -740,6 +740,14 @@
|
|||
profile_settings,
|
||||
[
|
||||
[[], "Privacy", "title"],
|
||||
[
|
||||
[
|
||||
"enable_questions",
|
||||
"Allow users to ask you questions",
|
||||
],
|
||||
"{{ profile.settings.enable_questions }}",
|
||||
"checkbox",
|
||||
],
|
||||
[
|
||||
[
|
||||
"private_profile",
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{% 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) }}
|
||||
{% else %}
|
||||
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2]) }}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2]) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{% 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) }}
|
||||
{% else %}
|
||||
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2]) }}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2]) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
{% 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) }}
|
||||
{% else %}
|
||||
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2]) }}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2]) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{% 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) }}
|
||||
{% else %}
|
||||
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2]) }}
|
||||
{{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2]) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@
|
|||
});
|
||||
});
|
||||
|
||||
self.define("update_notification_read_statsu", (_, id, read) => {
|
||||
self.define("update_notification_read_status", (_, id, read) => {
|
||||
fetch(`/api/v1/notifications/${id}/read_status`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
pub mod communities;
|
||||
pub mod images;
|
||||
pub mod posts;
|
||||
pub mod questions;
|
||||
|
|
|
@ -19,25 +19,32 @@ pub async fn create_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data
|
||||
.create_post(Post::new(
|
||||
req.content,
|
||||
match req.community.parse::<usize>() {
|
||||
Ok(x) => x,
|
||||
let mut props = Post::new(
|
||||
req.content,
|
||||
match req.community.parse::<usize>() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
},
|
||||
if let Some(rt) = req.replying_to {
|
||||
match rt.parse::<usize>() {
|
||||
Ok(x) => Some(x),
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
},
|
||||
if let Some(rt) = req.replying_to {
|
||||
match rt.parse::<usize>() {
|
||||
Ok(x) => Some(x),
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
}
|
||||
} else {
|
||||
None
|
||||
},
|
||||
user.id,
|
||||
))
|
||||
.await
|
||||
{
|
||||
}
|
||||
} else {
|
||||
None
|
||||
},
|
||||
user.id,
|
||||
);
|
||||
|
||||
if !req.answering.is_empty() {
|
||||
// we're answering a question!
|
||||
props.context.answering = match req.answering.parse::<usize>() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
};
|
||||
}
|
||||
|
||||
match data.create_post(props).await {
|
||||
Ok(id) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Post created".to_string(),
|
||||
|
|
65
crates/app/src/routes/api/v1/communities/questions.rs
Normal file
65
crates/app/src/routes/api/v1/communities/questions.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{communities::Question, ApiReturn, Error};
|
||||
use crate::{get_user_from_token, routes::api::v1::CreateQuestion, State};
|
||||
|
||||
pub async fn create_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<CreateQuestion>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
let mut props = Question::new(
|
||||
user.id,
|
||||
match req.receiver.parse::<usize>() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
},
|
||||
req.content,
|
||||
req.is_global,
|
||||
);
|
||||
|
||||
if !req.community.is_empty() {
|
||||
props.is_global = true;
|
||||
props.receiver = 0;
|
||||
props.community = match req.community.parse::<usize>() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
match data.create_question(props).await {
|
||||
Ok(id) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Question created".to_string(),
|
||||
payload: Some(id.to_string()),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.delete_question(id, &user).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Question deleted".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ pub mod communities;
|
|||
pub mod notifications;
|
||||
pub mod reactions;
|
||||
pub mod reports;
|
||||
pub mod requests;
|
||||
pub mod util;
|
||||
|
||||
use axum::{
|
||||
|
@ -93,6 +94,12 @@ pub fn routes() -> Router {
|
|||
"/posts/{id}/context",
|
||||
post(communities::posts::update_context_request),
|
||||
)
|
||||
// questions
|
||||
.route("/questions", post(communities::questions::create_request))
|
||||
.route(
|
||||
"/questions/{id}",
|
||||
delete(communities::questions::delete_request),
|
||||
)
|
||||
// auth
|
||||
// global
|
||||
.route("/auth/register", post(auth::register_request))
|
||||
|
@ -201,6 +208,12 @@ pub fn routes() -> Router {
|
|||
// reports
|
||||
.route("/reports", post(reports::create_request))
|
||||
.route("/reports/{id}", delete(reports::delete_request))
|
||||
// requests
|
||||
.route(
|
||||
"/requests/{id}/{linked_asset}",
|
||||
delete(requests::delete_request),
|
||||
)
|
||||
.route("/requests/my", delete(requests::delete_all_request))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -255,6 +268,8 @@ pub struct CreatePost {
|
|||
pub community: String,
|
||||
#[serde(default)]
|
||||
pub replying_to: Option<String>,
|
||||
#[serde(default)]
|
||||
pub answering: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -337,3 +352,13 @@ pub struct DisableTotp {
|
|||
pub struct CreateUserWarning {
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CreateQuestion {
|
||||
pub content: String,
|
||||
pub is_global: bool,
|
||||
#[serde(default)]
|
||||
pub receiver: String,
|
||||
#[serde(default)]
|
||||
pub community: String,
|
||||
}
|
||||
|
|
45
crates/app/src/routes/api/v1/requests.rs
Normal file
45
crates/app/src/routes/api/v1/requests.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use crate::{State, get_user_from_token};
|
||||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{ApiReturn, Error};
|
||||
|
||||
pub async fn delete_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path((id, linked_asset)): Path<(usize, usize)>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.delete_request(id, linked_asset, &user).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Request deleted".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete_all_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.delete_all_requests(&user).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Requests cleared".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
|
@ -362,6 +362,93 @@ pub async fn feed_request(
|
|||
))
|
||||
}
|
||||
|
||||
/// `/community/{title}/questions`
|
||||
pub async fn questions_request(
|
||||
jar: CookieJar,
|
||||
Path(title): 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 community = match data.0.get_community_by_title(&title.to_lowercase()).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
if community.id == 0 {
|
||||
// don't show page for void community
|
||||
return Err(Html(
|
||||
render_error(
|
||||
Error::GeneralNotFound("community".to_string()),
|
||||
&jar,
|
||||
&data,
|
||||
&user,
|
||||
)
|
||||
.await,
|
||||
));
|
||||
}
|
||||
|
||||
if !community.context.enable_questions {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
||||
));
|
||||
}
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
|
||||
// ...
|
||||
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) => 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,
|
||||
) = community_context_bools!(data, user, community);
|
||||
|
||||
context.insert("feed", &feed);
|
||||
context.insert("page", &props.page);
|
||||
community_context(
|
||||
&mut context,
|
||||
&community,
|
||||
is_owner,
|
||||
is_joined,
|
||||
is_pending,
|
||||
can_post,
|
||||
can_read,
|
||||
can_manage_posts,
|
||||
can_manage_community,
|
||||
can_manage_roles,
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1
|
||||
.render("communities/questions.html", &context)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// `/community/{id}/manage`
|
||||
pub async fn settings_request(
|
||||
jar: CookieJar,
|
||||
|
@ -440,26 +527,12 @@ pub async fn post_request(
|
|||
};
|
||||
|
||||
// check repost
|
||||
let reposting = if let Some(ref repost) = post.context.repost {
|
||||
if let Some(reposting) = repost.reposting {
|
||||
let mut x = match data.0.get_post_by_id(reposting).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
let reposting = data.0.get_post_reposting(&post).await;
|
||||
|
||||
x.mark_as_repost();
|
||||
Some((
|
||||
match data.0.get_user_by_id(x.owner).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
x,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
// 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
|
||||
|
@ -490,6 +563,7 @@ pub async fn post_request(
|
|||
|
||||
context.insert("post", &post);
|
||||
context.insert("reposting", &reposting);
|
||||
context.insert("question", &question);
|
||||
context.insert("replies", &feed);
|
||||
context.insert("page", &props.page);
|
||||
context.insert(
|
||||
|
@ -612,3 +686,96 @@ pub async fn members_request(
|
|||
data.1.render("communities/members.html", &context).unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// `/question/{id}`
|
||||
pub async fn question_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
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 question = match data.0.get_question_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(question.community).await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
let has_answered = if let Some(ref ua) = user {
|
||||
data.0
|
||||
.get_post_by_owner_question(ua.id, question.id)
|
||||
.await
|
||||
.is_ok()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
// check permissions
|
||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
||||
|
||||
// ...
|
||||
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) => 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,
|
||||
) = community_context_bools!(data, user, community);
|
||||
|
||||
context.insert("question", &question);
|
||||
context.insert("replies", &feed);
|
||||
context.insert("page", &props.page);
|
||||
context.insert(
|
||||
"owner",
|
||||
&data
|
||||
.0
|
||||
.get_user_by_id(question.owner)
|
||||
.await
|
||||
.unwrap_or(User::deleted()),
|
||||
);
|
||||
context.insert("has_answered", &has_answered);
|
||||
|
||||
community_context(
|
||||
&mut context,
|
||||
&community,
|
||||
is_owner,
|
||||
is_joined,
|
||||
is_pending,
|
||||
can_post,
|
||||
can_read,
|
||||
can_manage_posts,
|
||||
can_manage_community,
|
||||
can_manage_roles,
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1
|
||||
.render("communities/question.html", &context)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use axum::{
|
|||
Extension,
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::Error;
|
||||
use tetratto_core::model::{requests::ActionType, Error};
|
||||
use std::fs::read_to_string;
|
||||
use pathbufd::PathBufD;
|
||||
|
||||
|
@ -188,6 +188,59 @@ pub async fn notifications_request(
|
|||
))
|
||||
}
|
||||
|
||||
/// `/requests`
|
||||
pub async fn requests_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let requests = match data.0.get_requests_by_owner(user.id).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let questions = match data
|
||||
.0
|
||||
.fill_questions({
|
||||
let mut q = Vec::new();
|
||||
|
||||
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
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(q) => q,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||
context.insert("requests", &requests);
|
||||
context.insert("questions", &questions);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("misc/requests.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/doc/{file_name}`
|
||||
pub async fn markdown_document_request(
|
||||
jar: CookieJar,
|
||||
|
|
|
@ -22,6 +22,7 @@ pub fn routes() -> Router {
|
|||
.route("/following", get(misc::following_request))
|
||||
.route("/all", get(misc::all_request))
|
||||
.route("/notifs", get(misc::notifications_request))
|
||||
.route("/requests", get(misc::requests_request))
|
||||
.route("/doc/{*file_name}", get(misc::markdown_document_request))
|
||||
.fallback_service(get(misc::not_found))
|
||||
// mod
|
||||
|
@ -56,12 +57,17 @@ pub fn routes() -> Router {
|
|||
get(communities::create_post_request),
|
||||
)
|
||||
.route("/community/{title}", get(communities::feed_request))
|
||||
.route(
|
||||
"/community/{title}/questions",
|
||||
get(communities::questions_request),
|
||||
)
|
||||
.route("/community/{id}/manage", get(communities::settings_request))
|
||||
.route(
|
||||
"/community/{title}/members",
|
||||
get(communities::members_request),
|
||||
)
|
||||
.route("/post/{id}", get(communities::post_request))
|
||||
.route("/question/{id}", get(communities::question_request))
|
||||
}
|
||||
|
||||
pub async fn render_error(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue