add: allow users to block users who have blocked them/private users

fix: anonymous post page panic
add: allow users to select home timeline
This commit is contained in:
trisua 2025-04-24 16:40:03 -04:00
parent 2460e2f8c5
commit d42375441f
15 changed files with 313 additions and 122 deletions

View file

@ -0,0 +1,65 @@
{% extends "root.html" %} {% block head %}
<title>{{ profile.username }} (blocked) - {{ config.name }}</title>
{% endblock %} {% block body %} {{ macros::nav() }}
<main class="flex flex-col gap-2">
<div class="card-nest">
<div class="card small flex items-center justify-between gap-2">
<div class="flex items-center gap-2">
{{ components::avatar(username=profile.username, size="24px") }}
<span>{{ profile.username }}</span>
</div>
<b class="notification chip"
>{{ text "auth:label.blocked_profile" }}</b
>
</div>
<div class="card flex flex-col gap-2">
<span>{{ text "auth:label.blocked_profile_message" }}</span>
<div class="card w-full secondary flex gap-2">
{% if user %} {% if not is_blocking %}
<button onclick="toggle_block_user()" class="quaternary red">
{{ icon "shield" }}
<span>{{ text "auth:action.block" }}</span>
</button>
{% else %}
<button onclick="toggle_block_user()" class="quaternary red">
{{ icon "shield-off" }}
<span>{{ text "auth:action.unblock" }}</span>
</button>
{% endif %}
<script>
globalThis.toggle_block_user = async () => {
if (
!(await trigger("atto::confirm", [
"Are you sure you would like to do this?",
]))
) {
return;
}
fetch("/api/v1/auth/user/{{ profile.id }}/block", {
method: "POST",
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
};
</script>
{% endif %}
<a href="/" class="button red quaternary">
{{ icon "x" }}
<span>{{ text "general:action.back" }}</span>
</a>
</div>
</div>
</div>
</main>
{% endblock %}

View file

@ -45,6 +45,16 @@
{{ icon "user-minus" }}
<span>{{ text "auth:action.unfollow" }}</span>
</button>
{% endif %} {% if not is_blocking %}
<button onclick="toggle_block_user()" class="quaternary red">
{{ icon "shield" }}
<span>{{ text "auth:action.block" }}</span>
</button>
{% else %}
<button onclick="toggle_block_user()" class="quaternary red">
{{ icon "shield-off" }}
<span>{{ text "auth:action.unblock" }}</span>
</button>
{% endif %}
<script>
@ -117,6 +127,27 @@
.classList.remove("hidden");
});
};
globalThis.toggle_block_user = async () => {
if (
!(await trigger("atto::confirm", [
"Are you sure you would like to do this?",
]))
) {
return;
}
fetch("/api/v1/auth/user/{{ profile.id }}/block", {
method: "POST",
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
};
</script>
{% endif %}

View file

@ -33,6 +33,75 @@
<div class="w-full flex flex-col gap-2" data-tab="account">
<div class="card tertiary flex flex-col gap-2" id="account_settings">
<div class="card-nest" ui_ident="home_timeline">
<div class="card small">
<b>Home timeline</b>
</div>
<div class="card">
<select
onchange="set_setting_field('default_timeline', event.target.selectedOptions[0].value)"
>
<option
value="MyCommunities"
selected="{% if home == '/' %}true{% else %}false{% endif %}"
>
My communities
</option>
<option
value="MyCommunitiesQuestions"
selected="{% if home == '/questions' %}true{% else %}false{% endif %}"
>
My communities (questions)
</option>
<option
value="PopularPosts"
selected="{% if home == '/popular' %}true{% else %}false{% endif %}"
>
Popular
</option>
<option
value="PopularQuestions"
selected="{% if home == '/popular/questions' %}true{% else %}false{% endif %}"
>
Popular (questions)
</option>
<option
value="FollowingPosts"
selected="{% if home == '/following' %}true{% else %}false{% endif %}"
>
Following
</option>
<option
value="FollowingQuestions"
selected="{% if home == '/following/questions' %}true{% else %}false{% endif %}"
>
Following (questions)
</option>
<option
value="AllPosts"
selected="{% if home == '/all' %}true{% else %}false{% endif %}"
>
All
</option>
<option
value="AllQuestions"
selected="{% if home == '/all/questions' %}true{% else %}false{% endif %}"
>
All (questions)
</option>
</select>
<span class="fade"
>This represents the timeline the home button takes you
to.</span
>
</div>
</div>
<div class="card-nest" ui_ident="change_password">
<div class="card small">
<b>{{ text "settings:label.change_password" }}</b>
@ -737,6 +806,7 @@
const theme_settings = document.getElementById("theme_settings");
ui.refresh_container(account_settings, [
"home_timeline",
"change_password",
"change_username",
"two_factor_authentication",