Skip to content

Commit

Permalink
Merge pull request #44 from veytu/dev/personalFive
Browse files Browse the repository at this point in the history
fix: replace dangerouslySetInnerHTML into map
  • Loading branch information
FocusOnWrittingBug authored Oct 15, 2024
2 parents 72feaa7 + 3d1e046 commit 98c491b
Showing 1 changed file with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,6 @@ const TextMessage = observer(({ message, lastMsg }: { message: AgoraIMMessageBas

const isPrivate = checkIsPrivateMessage(textMessage);

//替换内容中的超链接
const replaceContentToLink = (text: string | null): string => {
const urlRegex = /((https?:\/\/|www\.)[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))/g;
return text ? text.replace(urlRegex, (match, url) => {
return `<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`;
}) : "";
}

const isHidden = lastMsg?.from == textMessage?.from && (
(checkIsPrivateMessage(textMessage) && (lastMsg?.ext && lastMsg?.ext?.receiverList?.length > 0)) && (lastMsg?.type != 'custom') && (typeof lastMsg !== 'string') || (!checkIsPrivateMessage(textMessage) && ((lastMsg?.ext && lastMsg?.ext?.receiverList?.length == 0) || (message.ext?.role === lastMsg?.ext?.role)) && (lastMsg?.type != 'custom') && (typeof lastMsg !== 'string')));

Expand Down Expand Up @@ -294,7 +286,18 @@ const TextMessage = observer(({ message, lastMsg }: { message: AgoraIMMessageBas
</div>
)}
</div>}
<div className='fcr-chatroom-mobile-message-content' dangerouslySetInnerHTML={{ __html: replaceContentToLink(textMessage.msg) }}></div>
<div className='fcr-chatroom-mobile-message-content'>
{splitTextAndUrls(textMessage.msg).map((text) => {
const isUrl = urlRegex.test(text);
return isUrl ? (
<a href={text} target="_blank" rel="noopener noreferrer">
{text}
</a>
) : (
text
);
})}
</div>
</div>
{/* {messageFromAlias}: */}
</div>}
Expand All @@ -316,7 +319,18 @@ const TextMessage = observer(({ message, lastMsg }: { message: AgoraIMMessageBas
</div>
)}
</div>}
<div className='fcr-chatroom-mobile-message-content' dangerouslySetInnerHTML={{ __html: replaceContentToLink(textMessage.msg) }}></div>
<div className='fcr-chatroom-mobile-message-content'>
{splitTextAndUrls(textMessage.msg).map((text) => {
const isUrl = urlRegex.test(text);
return isUrl ? (
<a href={text} target="_blank" rel="noopener noreferrer">
{text}
</a>
) : (
text
);
})}
</div>
</div>
)}
{!isSelfMessage && (isPrivate || (!isPrivate && isBreakOutRoomEnabled && isBreakOutRoomIn)) && (
Expand All @@ -341,7 +355,18 @@ const TextMessage = observer(({ message, lastMsg }: { message: AgoraIMMessageBas
</div>
)}
</div>}
<div className='fcr-chatroom-mobile-message-content' dangerouslySetInnerHTML={{ __html: replaceContentToLink(textMessage.msg) }}></div>
<div className='fcr-chatroom-mobile-message-content'>
{splitTextAndUrls(textMessage.msg).map((text) => {
const isUrl = urlRegex.test(text);
return isUrl ? (
<a href={text} target="_blank" rel="noopener noreferrer">
{text}
</a>
) : (
text
);
})}
</div>
</div>
</div>
)}
Expand Down

0 comments on commit 98c491b

Please sign in to comment.