Skip to content

Commit c5dc9aa

Browse files
authored
Merge pull request #559 from frozenfrank/open-links-in-new-tab
Open links in new tab
2 parents bd401c1 + 36d8624 commit c5dc9aa

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

projects/stream-chat-angular/src/lib/message/message.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ describe('MessageComponent', () => {
922922
expect(component.messageTextParts).toEqual([
923923
{
924924
content:
925-
'<a href="https://getstream.io/" rel="nofollow">https://getstream.io/</a> this is the link ',
925+
'<a href="https://getstream.io/" target="_blank" rel="nofollow">https://getstream.io/</a> this is the link ',
926926
type: 'text',
927927
},
928928
{ content: '@sara', type: 'mention', user: { id: 'sara' } },
@@ -989,14 +989,14 @@ describe('MessageComponent', () => {
989989
component.ngOnChanges({ message: {} as SimpleChange });
990990

991991
expect(component.messageTextParts![0].content).toContain(
992-
' <a href="https://getstream.io/" rel="nofollow">https://getstream.io/</a>'
992+
' <a href="https://getstream.io/" target="_blank" rel="nofollow">https://getstream.io/</a>'
993993
);
994994

995995
component.message.html = undefined;
996996
component.ngOnChanges({ message: {} as SimpleChange });
997997

998998
expect(component.messageTextParts![0].content).toContain(
999-
'<a href="https://getstream.io/" rel="nofollow">https://getstream.io/</a>'
999+
'<a href="https://getstream.io/" target="_blank" rel="nofollow">https://getstream.io/</a>'
10001000
);
10011001
});
10021002

projects/stream-chat-angular/src/lib/message/message.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export class MessageComponent
426426
this.message!.mentioned_users.length === 0
427427
) {
428428
content = this.fixEmojiDisplay(content);
429-
content = this.wrapLinskWithAnchorTag(content);
429+
content = this.wrapLinksWithAnchorTag(content);
430430
this.messageTextParts = [{ content, type: 'text' }];
431431
} else {
432432
this.messageTextParts = [];
@@ -435,7 +435,7 @@ export class MessageComponent
435435
const mention = `@${user.name || user.id}`;
436436
const precedingText = text.substring(0, text.indexOf(mention));
437437
let formattedPrecedingText = this.fixEmojiDisplay(precedingText);
438-
formattedPrecedingText = this.wrapLinskWithAnchorTag(
438+
formattedPrecedingText = this.wrapLinksWithAnchorTag(
439439
formattedPrecedingText
440440
);
441441
this.messageTextParts!.push({
@@ -451,7 +451,7 @@ export class MessageComponent
451451
});
452452
if (text) {
453453
text = this.fixEmojiDisplay(text);
454-
text = this.wrapLinskWithAnchorTag(text);
454+
text = this.wrapLinksWithAnchorTag(text);
455455
this.messageTextParts.push({ content: text, type: 'text' });
456456
}
457457
}
@@ -490,13 +490,14 @@ export class MessageComponent
490490
return content;
491491
}
492492

493-
private wrapLinskWithAnchorTag(content: string) {
493+
private wrapLinksWithAnchorTag(content: string) {
494494
if (this.displayAs === 'html') {
495495
return content;
496496
}
497497
content = content.replace(
498498
this.urlRegexp,
499-
(match) => `<a href="${match}" rel="nofollow">${match}</a>`
499+
(match) =>
500+
`<a href="${match}" target="_blank" rel="nofollow">${match}</a>`
500501
);
501502

502503
return content;

0 commit comments

Comments
 (0)