1- import { Component , Input , OnDestroy , OnInit } from "@angular/core" ;
1+ import { Component , Input , OnDestroy , OnInit , SecurityContext } from "@angular/core" ;
22import { DatePipe } from "@angular/common" ;
33import { FileSizePipe } from "../file-size.pipe" ;
44import { MatCardModule } from "@angular/material/card" ;
@@ -12,7 +12,8 @@ import { NotificationService } from "../service/notification.service";
1212import { Clipboard } from "@angular/cdk/clipboard" ;
1313import { PeerService } from "../service/peer.service" ;
1414import { FileMessage , Message , TextMessage } from "../message.model" ;
15- import { download , error } from "../utils" ;
15+ import { download , error , isValidUrl } from "../utils" ;
16+ import { DomSanitizer } from "@angular/platform-browser" ;
1617
1718@Component ( {
1819 selector : "app-message" ,
@@ -34,13 +35,17 @@ export class MessageComponent implements OnInit, OnDestroy {
3435 @Input ( )
3536 message ! : Message ;
3637
38+ isUrl = false ;
39+ url : string | undefined ;
40+
3741 isImage = false ;
3842 imageUrl : string | undefined ;
3943 readonly imagePattern = / ^ i m a g e \/ .+ $ / ;
4044
4145 constructor (
4246 private notificationService : NotificationService ,
4347 private clipboard : Clipboard ,
48+ private sanitizer : DomSanitizer ,
4449 public peerService : PeerService ,
4550 ) { }
4651
@@ -64,6 +69,10 @@ export class MessageComponent implements OnInit, OnDestroy {
6469 this . isImage = true ;
6570 this . imageUrl = URL . createObjectURL ( blob ) ;
6671 }
72+ if ( this . message . type == "Text" && isValidUrl ( this . message . text ) ) {
73+ this . isUrl = true ;
74+ this . url = this . sanitizer . sanitize ( SecurityContext . URL , this . message . text ) || '' ;
75+ }
6776 }
6877
6978 ngOnDestroy ( ) : void {
0 commit comments