add reposts/quotes

fix #2
This commit is contained in:
trisua 2025-04-10 18:16:52 -04:00
parent 15e24b9a61
commit df32b9d65e
43 changed files with 708 additions and 234 deletions

View file

@ -524,6 +524,7 @@ select {
resize: vertical;
width: 100%;
font-family: inherit;
font-size: 16px;
/* personality */
background: transparent;
color: inherit;

View file

@ -42,7 +42,11 @@
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in pinned %}
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{% 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) }}
{% endif %}
{% endfor %}
</div>
</div>
@ -57,7 +61,11 @@
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in feed %}
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{% 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) }}
{% endif %}
{% endfor %}
{{ components::pagination(page=page, items=feed|length) }}

View file

@ -7,9 +7,18 @@
{{ icon "arrow-up" }}
<span>{{ text "communities:action.continue_thread" }}</span>
</a>
{% endif %} {{ components::post(post=post, owner=owner, community=community,
show_community=true, can_manage_post=can_manage_posts) }} {% if user and
post.context.comments_enabled %}
{% 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, community=community, show_community=true, can_manage_post=can_manage_posts) }}
{% endif %}
</div>
{% if user and post.context.comments_enabled %}
<div class="card-nest">
<div class="card small">
<b>{{ text "communities:label.create_reply" }}</b>
@ -116,6 +125,11 @@
"{{ post.context.comments_enabled }}",
"checkbox",
],
[
["reposts_enabled", "Allow people to repost your post"],
"{{ post.context.reposts_enabled }}",
"checkbox",
],
[
["is_nsfw", "Mark as NSFW"],
"{{ community.context.is_nsfw }}",

View file

@ -396,10 +396,15 @@
}, 250);
</script>
<!-- prettier-ignore -->
<script type="application/json" id="settings_json">{{ community_context_serde|safe }}</script>
<script>
setTimeout(() => {
const ui = ns("ui");
const settings = JSON.parse("{{ community_context_serde|safe }}");
const settings = JSON.parse(
document.getElementById("settings_json").innerHTML,
);
globalThis.upload_avatar = (e) => {
e.preventDefault();

View file

@ -104,6 +104,45 @@ community %}
</span>
{% endif %}
</div>
{%- endmacro %} {% macro repost(repost, post, owner, secondary=false,
community=false, show_community=true, can_manage_post=false) -%}
<div style="display: contents">
<!-- prettier-ignore -->
<div style="display: none" id="repost-content:{{ post.id }}">
{% if repost %}
{{ components::post(post=repost[1], owner=repost[0], secondary=not secondary, community=false, show_community=false, can_manage_post=false) }}
{% else %}
<div class="card tertiary red flex items-center gap-2">
{{ icon "frown" }}
<span>Could not find original post...</span>
</div>
{% endif %}
</div>
{{ components::post(post=post, owner=owner, secondary=secondary,
community=community, show_community=show_community,
can_manage_post=can_manage_post) }}
<script>
document.getElementById("post-content:{{ post.id }}").innerHTML +=
document.getElementById("repost-content:{{ post.id }}").innerHTML;
document.getElementById("repost-content:{{ post.id }}").remove();
document
.getElementById("post:{{ post.id }}")
.querySelector(".avatar")
.setAttribute("style", "--size: 24px");
document
.getElementById("post:{{ post.id }}")
.querySelector(".name")
.parentElement.prepend(
document
.getElementById("post:{{ post.id }}")
.querySelector(".avatar"),
);
</script>
</div>
{%- endmacro %} {% macro post(post, owner, secondary=false, community=false,
show_community=true, can_manage_post=false) -%} {% if community and
show_community and post.community != config.town_square %}
@ -130,6 +169,7 @@ show_community and post.community != config.town_square %}
{% 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 }}">
@ -150,13 +190,6 @@ show_community and post.community != config.town_square %}
</div>
{% else %}
<span class="fade date">{{ post.created }}</span>
{% endif %} {% if show_community %}
<a href="/api/v1/communities/find/{{ post.community }}">
<!-- prettier-ignore -->
{% if not community %}
{{ components::community_avatar(id=post.community) }}
{% endif %}
</a>
{% endif %} {% if post.context.is_nsfw %}
<span
title="NSFW post"
@ -165,6 +198,15 @@ show_community and post.community != config.town_square %}
>
{{ icon "square-asterisk" }}
</span>
{% endif %} {% if post.context.repost and
post.context.repost.reposting %}
<span
title="Repost"
class="flex items-center"
style="color: var(--color-primary)"
>
{{ icon "repeat-2" }}
</span>
{% endif %}
</div>
@ -175,7 +217,16 @@ show_community and post.community != config.town_square %}
</div>
<div class="flex justify-between items-center gap-2 w-full">
{% if user %}
{% if user %} {% if post.context.repost and
post.context.repost.reposting %}
<a
href="/post/{{ post.context.repost.reposting }}"
class="button small camo"
>
{{ icon "expand" }}
<span>{{ text "communities:label.expand_original" }}</span>
</a>
{% else %}
<div
class="flex gap-1 reactions_box"
hook="check_reactions"
@ -184,7 +235,7 @@ show_community and post.community != config.town_square %}
{{ components::likes(id=post.id, asset_type="Post",
likes=post.likes, dislikes=post.dislikes) }}
</div>
{% else %}
{% endif %} {% else %}
<div></div>
{% endif %}
@ -213,7 +264,26 @@ show_community and post.community != config.town_square %}
</button>
<div class="inner">
{% if user.id != post.owner %}
{% if config.town_square and
post.context.reposts_enabled %}
<b class="title">{{ text "general:label.share" }}</b>
<button
onclick="trigger('me::repost', ['{{ post.id }}', '', '{{ config.town_square }}'])"
>
{{ icon "repeat-2" }}
<span>{{ text "communities:label.repost" }}</span>
</button>
<button
onclick="window.REPOST_ID = '{{ post.id }}'; document.getElementById('quote_dialog').showModal()"
>
{{ icon "quote" }}
<span
>{{ text "communities:label.quote_post" }}</span
>
</button>
{% endif %} {% if user.id != post.owner %}
<b class="title">{{ text "general:label.safety" }}</b>
<button
class="red"
onclick="trigger('me::report', ['{{ post.id }}', 'post'])"
@ -483,4 +553,46 @@ user.settings.theme_hue %}
match_user_theme();
}, 150);
</script>
{% endif %} {% endif %} {% endif %} {%- endmacro %}
{% endif %} {% endif %} {% endif %} {%- endmacro %} {% macro quote_form() -%} {%
if config.town_square and user %}
<div class="card-nest">
<div class="card small flex flex-col">
<div class="flex items-center gap-2">
{{ icon "quote" }}
<span>{{ text "communities:label.quote_post" }}</span>
</div>
</div>
<form
class="card flex flex-col gap-2"
onsubmit="create_repost_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_repost_from_form(e) {
e.preventDefault();
await trigger("atto::debounce", ["posts::create"]);
await trigger("me::repost", [
window.REPOST_ID,
e.target.content.value,
"{{ config.town_square }}",
]);
}
</script>
{% endif %} {%- endmacro %}

View file

@ -67,7 +67,10 @@
</div>
</div>
<div class="card flex flex-col gap-2" id="social">
<div
class="card flex flex-col items-center gap-2"
id="social"
>
<div class="w-full flex">
<a
href="/@{{ profile.username }}/followers"
@ -84,6 +87,15 @@
<span>{{ text "auth:label.following" }}</span>
</a>
</div>
{% if is_following_you %}
<b
class="notification chip w-content flex items-center gap-2"
>
{{ icon "heart" }}
<span>Follows you</span>
</b>
{% endif %}
</div>
</div>

View file

@ -9,7 +9,11 @@
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in pinned %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true, can_manage_post=is_self) }}
{% 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) }}
{% endif %}
{% endfor %}
</div>
</div>
@ -24,7 +28,11 @@
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in posts %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true, can_manage_post=is_self) }}
{% 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) }}
{% endif %}
{% endfor %}
{{ components::pagination(page=page, items=posts|length) }}

View file

@ -326,10 +326,15 @@
{% endfor %}
</div>
<!-- prettier-ignore -->
<script type="application/json" id="settings_json">{{ user_settings_serde|safe }}</script>
<script>
setTimeout(() => {
const ui = ns("ui");
const settings = JSON.parse("{{ user_settings_serde|safe }}");
const settings = JSON.parse(
document.getElementById("settings_json").innerHTML,
);
let tokens = JSON.parse("{{ user_tokens_serde|safe }}");
globalThis.remove_token = async (id) => {

View file

@ -317,6 +317,26 @@ macros -%}
</div>
</div>
</dialog>
<dialog id="quote_dialog">
<div class="inner flex flex-col gap-2">
{{ components::quote_form() }}
<div class="flex justify-between">
<div></div>
<div class="flex gap-2">
<button
class="bold red quaternary"
onclick="document.getElementById('quote_dialog').close()"
type="button"
>
{{ icon "x" }} {{ text "dialog:action.close" }}
</button>
</div>
</div>
</div>
</dialog>
{% endif %} {% if user and use_user_theme %} {{
components::theme(user=user) }} {% endif %}
</body>

View file

@ -7,7 +7,11 @@
<!-- prettier-ignore -->
<div class="card w-full flex flex-col gap-2">
{% for post in list %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% 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]) }}
{% endif %}
{% endfor %}
{{ components::pagination(page=page, items=list|length) }}

View file

@ -19,7 +19,11 @@
<!-- prettier-ignore -->
<div class="card w-full flex flex-col gap-2">
{% for post in list %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% 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]) }}
{% endif %}
{% endfor %}
{{ components::pagination(page=page, items=list|length) }}

View file

@ -7,7 +7,11 @@
<!-- prettier-ignore -->
<div class="card w-full flex flex-col gap-2">
{% for post in list %}
{{ components::post(post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }}
{% 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]) }}
{% endif %}
{% endfor %}
{{ components::pagination(page=page, items=list|length) }}

View file

@ -149,6 +149,32 @@
});
});
self.define("repost", (_, id, content, community) => {
fetch(`/api/v1/posts/${id}/repost`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
content,
community,
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
if (res.ok) {
setTimeout(() => {
window.location.href = `/post/${res.payload}`;
}, 100);
}
});
});
self.define("report", (_, asset, asset_type) => {
window.open(
`/mod_panel/file_report?asset=${asset}&asset_type=${asset_type}`,