From 86cf986a9115510a2390f1e1d9f8703949301550 Mon Sep 17 00:00:00 2001 From: shaden-pr Date: Wed, 8 Oct 2025 21:41:12 +0100 Subject: [PATCH 1/4] Added frontend check to alert user if message exceeds maxlength --- front-end/components/bloom-form.mjs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/front-end/components/bloom-form.mjs b/front-end/components/bloom-form.mjs index e047f9a..13e8a55 100644 --- a/front-end/components/bloom-form.mjs +++ b/front-end/components/bloom-form.mjs @@ -27,6 +27,14 @@ async function handleBloomSubmit(event) { const textarea = form.querySelector("textarea"); const content = textarea.value.trim(); + const maxLength = parseInt(textarea.getAttribute("maxlength"), 10); + + if(Number.isFinite(maxLength) && content.length > maxLength){ + alert(`your message is too long! Limit is ${maxLength}`); + textarea.focus(); + return; + } + try { // Make form inert while we call the back end form.inert = true; From 7a374942dda41167a0e5b7b95668c41dcc23eddd Mon Sep 17 00:00:00 2001 From: shaden-pr Date: Wed, 8 Oct 2025 21:41:51 +0100 Subject: [PATCH 2/4] Shortened bloom text in populate.py to fit within 280 chars --- backend/populate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/populate.py b/backend/populate.py index 414218b..07087da 100644 --- a/backend/populate.py +++ b/backend/populate.py @@ -64,7 +64,7 @@ def main(): writer_access_token = create_user("AS", "neverSt0pTalking") send_bloom( writer_access_token, - "In this essay I will convince you that my views are correct in ways you have never imagined. If it doesn't change your life, read it again. Marshmallows are magnificent. They have great squish, tasty good, and you can even toast them over a fire. Toast them just right until they have a tiny bit of crunch when you bite into them, and have just started melting in the middle.", + "Marshmallows are magnificent. They have great squish, tasty good, and you can even toast them over a fire. Toast them just right until they have a tiny bit of crunch when you bite into them, and have just started melting in the middle.", ) justsomeguy_access_token = create_user("JustSomeGuy", "mysterious") From 35013b11605e9613c2d8b4059240d2107062f28f Mon Sep 17 00:00:00 2001 From: shaden-pr Date: Wed, 8 Oct 2025 21:42:15 +0100 Subject: [PATCH 3/4] Added backend validation to raise error if content > 280 --- backend/data/blooms.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/data/blooms.py b/backend/data/blooms.py index 7e280cf..9c2d7ac 100644 --- a/backend/data/blooms.py +++ b/backend/data/blooms.py @@ -16,6 +16,9 @@ class Bloom: def add_bloom(*, sender: User, content: str) -> Bloom: + if len(content) > 280: + raise ValueError("Blooms are limited to 280 characters!") + hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")] now = datetime.datetime.now(tz=datetime.UTC) From 9beeaa013d6c3df7a47825cc932c329e82ac5573 Mon Sep 17 00:00:00 2001 From: shaden-pr Date: Wed, 8 Oct 2025 21:42:48 +0100 Subject: [PATCH 4/4] Add database character limits for blooms --- db/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.sql b/db/schema.sql index 61e7580..64b98a0 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -9,7 +9,7 @@ CREATE TABLE users ( CREATE TABLE blooms ( id BIGSERIAL NOT NULL PRIMARY KEY, sender_id INT NOT NULL REFERENCES users(id), - content TEXT NOT NULL, + content TEXT NOT NULL CHECK (CHAR_LENGTH(content) <= 280), send_timestamp TIMESTAMP NOT NULL );