5180 fichiers 38.5 Mo 0 téléchargements 246 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / components / mentions / MentionMessageView.tsx
MentionMessageView.tsx 1.1 Ko Télécharger le fichier
import { FC, Fragment } from 'react';
import { segmentMentionText } from '../../api/mentions/mentionSegments';

interface MentionMessageViewProps {
    text: string;
    ownUsername: string;
    className?: string;
}

/**
 * Renders a mention's message text as React nodes, wrapping every @user token
 * in a `.mention-tag` span (with the `.mention-tag--self` modifier when the
 * token targets the local user or a broadcast alias). Pure text segmentation
 * (no innerHTML) → no XSS risk from other users' chat content. Original spacing
 * is preserved verbatim.
 */
export const MentionMessageView: FC<MentionMessageViewProps> = (props) => {
    const { text, ownUsername, className } = props;

    if (!text) return <span className={className} />;

    const nodes = segmentMentionText(text, ownUsername).map((segment, index) =>
        segment.kind ? (
            <span key={index} className={segment.kind === 'self' ? 'mention-tag mention-tag--self' : 'mention-tag'}>
                {segment.text}
            </span>
        ) : (
            <Fragment key={index}>{segment.text}</Fragment>
        )
    );

    return <span className={className}>{nodes}</span>;
};
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser