From 391d717987b0150ede691ac63ec2605fc6556e0f Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Sat, 28 Mar 2026 16:10:58 +0530 Subject: [PATCH] feat: sanitize notification descriptions to display link types instead of raw URLs --- src/app/(agent)/agent/notifications/page.tsx | 13 ++++++++++++- src/app/(user)/user/notifications/page.tsx | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/app/(agent)/agent/notifications/page.tsx b/src/app/(agent)/agent/notifications/page.tsx index 65bf5cb..c34cd50 100644 --- a/src/app/(agent)/agent/notifications/page.tsx +++ b/src/app/(agent)/agent/notifications/page.tsx @@ -5,6 +5,17 @@ import Image from 'next/image'; import Link from 'next/link'; import { notificationsApiService, type AppNotification } from '@/services/notifications-api.service'; +function formatDescription(description: string): string { + const trimmed = description.trim(); + if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) { + const lower = trimmed.toLowerCase(); + if (lower.includes('.gif')) return 'Sent a GIF'; + if (lower.includes('.png') || lower.includes('.jpg') || lower.includes('.jpeg') || lower.includes('.webp')) return 'Sent an image'; + return 'Sent a link'; + } + return description; +} + function getNotificationIcon(type: AppNotification['type']) { switch (type) { case 'connection': @@ -221,7 +232,7 @@ export default function AgentNotificationsPage() { {notification.title}

- {notification.description} + {formatDescription(notification.description)}

diff --git a/src/app/(user)/user/notifications/page.tsx b/src/app/(user)/user/notifications/page.tsx index ed92f7d..5b6a139 100644 --- a/src/app/(user)/user/notifications/page.tsx +++ b/src/app/(user)/user/notifications/page.tsx @@ -5,6 +5,17 @@ import Image from 'next/image'; import Link from 'next/link'; import { notificationsApiService, type AppNotification } from '@/services/notifications-api.service'; +function formatDescription(description: string): string { + const trimmed = description.trim(); + if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) { + const lower = trimmed.toLowerCase(); + if (lower.includes('.gif')) return 'Sent a GIF'; + if (lower.includes('.png') || lower.includes('.jpg') || lower.includes('.jpeg') || lower.includes('.webp')) return 'Sent an image'; + return 'Sent a link'; + } + return description; +} + function getNotificationIcon(type: AppNotification['type']) { switch (type) { case 'connection': @@ -213,7 +224,7 @@ export default function UserNotificationsPage() { {notification.title}

- {notification.description} + {formatDescription(notification.description)}