Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/data/blooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class Bloom:
sent_timestamp: datetime.datetime


MAX_BLOOM_LENGTH = 280

def add_bloom(*, sender: User, content: str) -> Bloom:
if len(content) > 280:
raise ValueError("Bloom exceeds 280 characters")

hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")]

now = datetime.datetime.now(tz=datetime.UTC)
Expand Down
4 changes: 4 additions & 0 deletions backend/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def get_bloom(id_str):
return make_response((f"Bloom not found", 404))
return jsonify(bloom)

MAX_BLOOM_LENGTH = 280

@jwt_required()
def home_timeline():
Expand All @@ -198,6 +199,9 @@ def home_timeline():
# Combine own blooms with followed blooms
all_blooms = followed_blooms + own_blooms

# Filter long blooms (over 280 characters)
all_blooms = [bloom for bloom in all_blooms if len(bloom.content) <= MAX_BLOOM_LENGTH]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're filtering blooms that are already in the backend that are over MAX_BLOOM_LENGTH but you're doing nothing to stop new ones being added.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually initially added a length checker inside the add_bloom function to make the logic future-proof. However, I then thought that from the client side users can’t go beyond 280 characters anyway. I know this isn’t the correct way to approach it, since someone could bypass the frontend and send a longer bloom directly to the server. I honestly focused solely on meeting the exact requirements of the quiz, which isn’t best practice. I know should fix not just the stated problem but also any potential loopholes that could cause issues in the future.


# Sort by timestamp (newest first)
sorted_blooms = list(
sorted(all_blooms, key=lambda bloom: bloom.sent_timestamp, reverse=True)
Expand Down
1 change: 1 addition & 0 deletions front-end/components/bloom-form.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async function handleBloomSubmit(event) {
const textarea = form.querySelector("textarea");
const content = textarea.value.trim();


try {
// Make form inert while we call the back end
form.inert = true;
Expand Down