From 70bd26526b6b69a57ba8f3484f69d9444f6981cd Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 1 Sep 2020 00:23:40 -0500 Subject: [PATCH] Chats: make links open in a new tab, fixes #371 --- .../features/chats/components/chat_message_list.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/soapbox/features/chats/components/chat_message_list.js b/app/soapbox/features/chats/components/chat_message_list.js index 3f5dce8eb..05869c74e 100644 --- a/app/soapbox/features/chats/components/chat_message_list.js +++ b/app/soapbox/features/chats/components/chat_message_list.js @@ -56,6 +56,16 @@ class ChatMessageList extends ImmutablePureComponent { ); }; + setRef = (c) => { + const links = c.querySelectorAll('a[rel="ugc"]'); + + links.forEach(link => { + link.classList.add('chat-link'); + link.setAttribute('rel', 'ugc nofollow noopener'); + link.setAttribute('target', '_blank'); + }); + } + componentDidUpdate(prevProps) { if (prevProps.chatMessages !== this.props.chatMessages) this.scrollToBottom(); @@ -78,6 +88,7 @@ class ChatMessageList extends ImmutablePureComponent { title={this.getFormattedTimestamp(chatMessage)} className='chat-message__bubble' dangerouslySetInnerHTML={{ __html: emojify(chatMessage.get('content') || '') }} + ref={this.setRef} /> ))}