대화방 > text 내 링크 포인트 분류

This commit is contained in:
leejinho 2019-11-19 19:15:56 +09:00
parent e46d3481b0
commit 79b099c7e4
6 changed files with 63 additions and 8 deletions

View File

@ -69,6 +69,7 @@
"@types/webpack-merge": "^4.1.5", "@types/webpack-merge": "^4.1.5",
"@types/webpack-node-externals": "^1.6.3", "@types/webpack-node-externals": "^1.6.3",
"angular-split": "^3.0.2", "angular-split": "^3.0.2",
"autolinker": "^3.11.1",
"awesome-node-loader": "^1.1.1", "awesome-node-loader": "^1.1.1",
"awesome-typescript-loader": "^5.2.1", "awesome-typescript-loader": "^5.2.1",
"classlist.js": "^1.1.20150312", "classlist.js": "^1.1.20150312",

View File

@ -1,3 +1,3 @@
<div class="bubble-main"> <div class="bubble-main">
<span [innerHTML]="message.sentMessage"></span> <span [innerHTML]="message.sentMessage | linky"></span>
</div> </div>

View File

@ -1,17 +1,46 @@
import { Component, OnInit, Input } from '@angular/core'; import {
Component,
OnInit,
Input,
ElementRef,
AfterViewInit,
Inject
} from '@angular/core';
import { Info, EventJson } from '@ucap-webmessenger/protocol-event'; import { Info, EventJson } from '@ucap-webmessenger/protocol-event';
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
@Component({ @Component({
selector: 'ucap-chat-message-box-text', selector: 'ucap-chat-message-box-text',
templateUrl: './text.component.html', templateUrl: './text.component.html',
styleUrls: ['./text.component.scss'] styleUrls: ['./text.component.scss']
}) })
export class TextComponent implements OnInit { export class TextComponent implements OnInit, AfterViewInit {
@Input() @Input()
message: Info<EventJson>; message: Info<EventJson>;
test = `가<br>나<br >다<br/>라<br />마<br class=""/>바사`; constructor(
constructor() {} private elementRef: ElementRef,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
) {}
ngOnInit() {} ngOnInit() {}
ngAfterViewInit(): void {
if (
!!this.elementRef.nativeElement &&
!!this.elementRef.nativeElement.querySelector('a')
) {
const elements = this.elementRef.nativeElement.querySelectorAll('a');
elements.forEach(element => {
element.addEventListener('click', this.onClickEvent.bind(this));
});
}
}
onClickEvent(event: MouseEvent) {
console.log('component', (event.target as HTMLAnchorElement).text);
// this.nativeService.openDefaultBrowser(
// (event.target as HTMLAnchorElement).text
// );
}
} }

View File

@ -6,6 +6,7 @@ import {
EventEmitter, EventEmitter,
Output, Output,
ViewEncapsulation, ViewEncapsulation,
HostListener
} from '@angular/core'; } from '@angular/core';
import { import {
@ -13,7 +14,7 @@ import {
EventType, EventType,
InfoResponse, InfoResponse,
EventJson, EventJson,
FileEventJson, FileEventJson
} from '@ucap-webmessenger/protocol-event'; } from '@ucap-webmessenger/protocol-event';
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication'; import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
import { UserInfo } from '@ucap-webmessenger/protocol-room'; import { UserInfo } from '@ucap-webmessenger/protocol-room';
@ -26,7 +27,7 @@ import moment from 'moment';
@Component({ @Component({
selector: 'ucap-chat-messages', selector: 'ucap-chat-messages',
templateUrl: './messages.component.html', templateUrl: './messages.component.html',
styleUrls: ['./messages.component.scss'], styleUrls: ['./messages.component.scss']
}) })
export class MessagesComponent implements OnInit { export class MessagesComponent implements OnInit {
@Input() @Input()

View File

@ -0,0 +1,22 @@
import { Pipe, PipeTransform } from '@angular/core';
import { Autolinker, AutolinkerConfig } from 'autolinker';
@Pipe({ name: 'linky' })
export class LinkyPipe implements PipeTransform {
transform(value: string, options?: AutolinkerConfig): string {
options = {
email: false,
phone: false,
stripPrefix: false,
// newWindow: false,
replaceFn: match => {
if (match.getType() === 'url') {
return '<a>' + match.getAnchorHref() + '</a>';
// return true;
}
},
...options
};
return Autolinker.link(value, options);
}
}

View File

@ -46,6 +46,7 @@ import {
DateToStringFormatPipe DateToStringFormatPipe
} from './pipes/dates.pipe'; } from './pipes/dates.pipe';
import { SecondsToMinutesPipe } from './pipes/seconds-to-minutes.pipe'; import { SecondsToMinutesPipe } from './pipes/seconds-to-minutes.pipe';
import { LinkyPipe } from './pipes/linky.pipe';
const COMPONENTS = [ const COMPONENTS = [
FileUploadQueueComponent, FileUploadQueueComponent,
@ -72,7 +73,8 @@ const PIPES = [
HtmlToLinefeedPipe, HtmlToLinefeedPipe,
DateToStringForChatRoomListPipe, DateToStringForChatRoomListPipe,
DateToStringFormatPipe, DateToStringFormatPipe,
SecondsToMinutesPipe SecondsToMinutesPipe,
LinkyPipe
]; ];
const SERVICES = [ const SERVICES = [
BottomSheetService, BottomSheetService,