From 2b91422d183f96f2f60f101e89cea8809b551365 Mon Sep 17 00:00:00 2001 From: trisua Date: Wed, 21 May 2025 00:04:18 -0400 Subject: [PATCH] add: better quote post ui --- crates/app/src/macros.rs | 27 ++++++--- crates/app/src/main.rs | 8 +++ .../public/html/communities/create_post.html | 47 +++++++++++++-- crates/app/src/public/html/components.html | 58 ++++--------------- crates/app/src/public/html/profile/base.html | 6 ++ crates/app/src/public/html/root.html | 20 ------- crates/app/src/public/js/me.js | 55 ++++++++++-------- crates/app/src/routes/pages/communities.rs | 19 ++++++ 8 files changed, 138 insertions(+), 102 deletions(-) diff --git a/crates/app/src/macros.rs b/crates/app/src/macros.rs index 2d92375..41ce0c4 100644 --- a/crates/app/src/macros.rs +++ b/crates/app/src/macros.rs @@ -95,6 +95,19 @@ macro_rules! get_lang { }}; } +#[macro_export] +macro_rules! user_banned { + ($user:expr, $other_user:ident, $data:ident, $jar:ident) => { + let lang = get_lang!($jar, $data.0); + let mut context = initial_context(&$data.0.0, lang, &$user).await; + context.insert("profile", &$other_user); + + return Ok(Html( + $data.1.render("profile/banned.html", &context).unwrap(), + )); + }; +} + #[macro_export] macro_rules! check_user_blocked_or_private { ($user:expr, $other_user:ident, $data:ident, $jar:ident) => { @@ -115,13 +128,13 @@ macro_rules! check_user_blocked_or_private { // check if other user is banned if $other_user.permissions.check_banned() { - let lang = get_lang!($jar, $data.0); - let mut context = initial_context(&$data.0.0, lang, &$user).await; - context.insert("profile", &$other_user); - - return Ok(Html( - $data.1.render("profile/banned.html", &context).unwrap(), - )); + if let Some(ref ua) = $user { + if !ua.permissions.check(FinePermission::MANAGE_USERS) { + $crate::user_banned!($user, $other_user, $data, $jar); + } + } else { + $crate::user_banned!($user, $other_user, $data, $jar); + } } // check if we're blocked diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 50c7701..b523347 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -49,6 +49,13 @@ fn check_staff_badge(value: &Value, _: &HashMap) -> tera::Result< .into()) } +fn check_banned(value: &Value, _: &HashMap) -> tera::Result { + Ok(FinePermission::from_bits(value.as_u64().unwrap() as u32) + .unwrap() + .check_banned() + .into()) +} + #[tokio::main(flavor = "multi_thread")] async fn main() { tracing_subscriber::fmt() @@ -78,6 +85,7 @@ async fn main() { tera.register_filter("color", color_escape); tera.register_filter("has_supporter", check_supporter); tera.register_filter("has_staff_badge", check_staff_badge); + tera.register_filter("has_banned", check_banned); let client = Client::new(); diff --git a/crates/app/src/public/html/communities/create_post.html b/crates/app/src/public/html/communities/create_post.html index 55e44bc..74a442c 100644 --- a/crates/app/src/public/html/communities/create_post.html +++ b/crates/app/src/public/html/communities/create_post.html @@ -54,6 +54,23 @@ + {%- endif %} {% if quoting -%} + {%- endif %}
@@ -91,7 +108,7 @@
+ {% if not quoting -%} + {% else %} + + {%- endif %}
diff --git a/crates/app/src/public/html/components.html b/crates/app/src/public/html/components.html index 7f6b71d..05ffe89 100644 --- a/crates/app/src/public/html/components.html +++ b/crates/app/src/public/html/components.html @@ -349,14 +349,15 @@ config.town_square or question %} {{ text "communities:label.repost" }} - + {%- endif %} {% if user.id != post.owner -%} {{ text "general:label.safety" }} - - - - {%- endif %} {%- endmacro %} {% macro question(question, owner, show_community=true, secondary=false) -%}
@@ -1398,10 +1357,13 @@ is_supporter %}
{%- endif %} {%- endmacro %} {% macro create_post_options() -%} +
- {{ components::emoji_picker(element_id="content", render_dialog=true) }} {% - if is_supporter -%} {{ components::file_picker(files_list_id="files_list") - }} {%- endif %} + {{ components::emoji_picker(element_id="content", render_dialog=true) }} + + {% if not quoting -%} {% if is_supporter -%} + {{ components::file_picker(files_list_id="files_list") }} + {%- endif %} {%- endif %}
- - -
- {{ components::quote_form() }} - -
-
- -
- -
-
-
-
{%- endif %} {% if user and use_user_theme -%} {{ components::theme(user=user, theme_preference=user.settings.theme_preference) }} diff --git a/crates/app/src/public/js/me.js b/crates/app/src/public/js/me.js index 12b06e7..0778587 100644 --- a/crates/app/src/public/js/me.js +++ b/crates/app/src/public/js/me.js @@ -201,31 +201,40 @@ }); }); - 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, - ]); + self.define( + "repost", + (_, id, content, community, do_not_redirect = false) => { + return new Promise((resolve, _) => { + 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); - } + if (res.ok) { + if (!do_not_redirect) { + setTimeout(() => { + window.location.href = `/post/${res.payload}`; + }, 100); + } + + resolve(res.payload); + } + }); }); - }); + }, + ); self.define("report", (_, asset, asset_type) => { window.open( diff --git a/crates/app/src/routes/pages/communities.rs b/crates/app/src/routes/pages/communities.rs index c1b2c6d..637500c 100644 --- a/crates/app/src/routes/pages/communities.rs +++ b/crates/app/src/routes/pages/communities.rs @@ -243,6 +243,8 @@ pub struct CreatePostProps { pub community: usize, #[serde(default)] pub from_draft: usize, + #[serde(default)] + pub quote: usize, } /// `/communities/intents/post` @@ -299,12 +301,29 @@ pub async fn create_post_request( Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)), }; + // get quoting + let quoting = if props.quote != 0 { + match data.0.get_post_by_id(props.quote).await { + Ok(q) => Some(( + match data.0.get_user_by_id(q.owner).await { + Ok(ua) => ua, + Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)), + }, + q, + )), + Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)), + } + } else { + None + }; + // ... let lang = get_lang!(jar, data.0); let mut context = initial_context(&data.0.0, lang, &Some(user)).await; context.insert("draft", &draft); context.insert("drafts", &drafts); + context.insert("quoting", "ing); context.insert("communities", &communities); context.insert("selected_community", &props.community);