From 28a5d6143979973ea66892c1702b9c8207cf1498 Mon Sep 17 00:00:00 2001 From: kai Date: Fri, 17 Jan 2025 08:55:19 -0500 Subject: [PATCH] Cap status text length in notifications and responses --- app/components/FriendTimeline.tsx | 12 +++++++++++- app/models/status.rb | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/components/FriendTimeline.tsx b/app/components/FriendTimeline.tsx index b4989057..cb45e4a4 100644 --- a/app/components/FriendTimeline.tsx +++ b/app/components/FriendTimeline.tsx @@ -134,6 +134,8 @@ interface RespondAnchorProps status: Status; } +const SNIPPED_TEXT_MAX_LENGTH = 240; + const RespondAnchor: FC = ({ contactPhone, status, @@ -141,8 +143,16 @@ const RespondAnchor: FC = ({ ...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"; diff --git a/app/models/status.rb b/app/models/status.rb index 097acda9..5e3732d8 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -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