Skip to content

Commit

Permalink
Cap status text length in notifications and responses
Browse files Browse the repository at this point in the history
  • Loading branch information
hulloitskai committed Jan 17, 2025
1 parent c862b01 commit 28a5d61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion app/components/FriendTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,25 @@ interface RespondAnchorProps
status: Status;
}

const SNIPPED_TEXT_MAX_LENGTH = 240;

const RespondAnchor: FC<RespondAnchorProps> = ({
contactPhone,
status,
className,
...otherProps
}) => {
const href = useMemo(() => {
let snippedText = status.text;
if (snippedText.length > SNIPPED_TEXT_MAX_LENGTH) {
snippedText = snippedText.substring(0, SNIPPED_TEXT_MAX_LENGTH);
if (snippedText.endsWith(" ") || snippedText.endsWith("\n")) {
snippedText = snippedText.slice(0, -1);
}
snippedText += "...";
}
const quotedText =
status.text
snippedText
.split("\n")
.map(line => `> ${line}`)
.join("\n") + "\n\n";
Expand Down
2 changes: 1 addition & 1 deletion app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def notification_title

sig { override.returns(String) }
def notification_body
[emoji, text].compact.join(" ")
[emoji, text].compact.join(" ").truncate(240)
end

# == Notify
Expand Down

0 comments on commit 28a5d61

Please sign in to comment.