feat: sanitize notification descriptions to display link types instead of raw URLs

This commit is contained in:
pradeepkumar
2026-03-28 16:10:58 +05:30
parent 2070e4d9b7
commit 391d717987
2 changed files with 24 additions and 2 deletions

View File

@@ -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}
</p>
<p className="font-serif text-[14px] text-[#00293D]/60 mt-1">
{notification.description}
{formatDescription(notification.description)}
</p>
</div>
<span className="font-serif text-[12px] text-[#00293D]/50 flex-shrink-0">

View File

@@ -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}
</p>
<p className="font-serif text-[14px] text-[#00293D]/60 mt-1">
{notification.description}
{formatDescription(notification.description)}
</p>
</div>
<span className="font-serif text-[12px] text-[#00293D]/50 flex-shrink-0">