107 lines
2.8 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, Input } from '@angular/core';
import { NGXLogger } from 'ngx-logger';
2019-11-06 13:48:06 +09:00
import {
Info,
EventType,
EventJson,
JoinEventJson,
RenameRoomEventJson,
NotificationForTimerRoomEventJson,
GuideForRoomTimerChangedEventJson
} from '@ucap-webmessenger/protocol-event';
2019-10-07 13:49:12 +09:00
@Component({
selector: 'ucap-chat-message-box-information',
templateUrl: './information.component.html',
styleUrls: ['./information.component.scss']
})
export class InformationComponent implements OnInit {
@Input()
2019-11-06 13:48:06 +09:00
message: Info<EventJson>;
@Input()
senderName?: string;
2019-10-07 13:49:12 +09:00
contents: string;
constructor(private logger: NGXLogger) {}
ngOnInit() {
switch (this.message.type) {
case EventType.Join:
2019-11-06 13:48:06 +09:00
{
const m = this.message as Info<JoinEventJson>;
const owner = m.sentMessageJson.owner + '님';
const inviter: string[] = [];
m.sentMessageJson.inviter.forEach((userName, idx) => {
inviter.push(userName + '님');
2019-11-06 13:48:06 +09:00
});
this.contents = `${owner}${inviter.join(',')}을 초대했습니다.`;
}
break;
case EventType.Exit:
2019-11-06 13:48:06 +09:00
{
const m = this.message as Info<JoinEventJson>;
this.contents = `${m.sentMessage}님이 퇴장하셨습니다.`;
}
break;
case EventType.RenameRoom:
2019-11-06 13:48:06 +09:00
{
const m = this.message as Info<RenameRoomEventJson>;
this.contents = `${m.sentMessageJson.requester}님이 대화방명을 '${m.sentMessageJson.roomName}'으로 변경하셨습니다.`;
}
break;
case EventType.NotificationForTimerRoom:
2019-11-06 13:48:06 +09:00
{
const m = this.message as Info<NotificationForTimerRoomEventJson>;
/**
* , .
*/
this.contents = m.sentMessage;
}
break;
case EventType.GuideForRoomTimerChanged:
2019-11-06 13:48:06 +09:00
{
const m = this.message as Info<GuideForRoomTimerChangedEventJson>;
this.contents = `${
this.senderName
} .(${this.getCalcTimer(
2019-11-06 13:48:06 +09:00
m.sentMessageJson.time * 1000
)})`;
}
break;
}
}
getCalcTimer(millisec: number) {
switch (millisec) {
case 5000:
return '5 초';
case 10000:
return '10 초';
case 30000:
return '30 초';
case 60000:
return '1 분';
case 300000:
return '5 분';
case 600000:
return '10 분';
case 1800000:
return '30 분';
case 3600000:
return '1 시간';
case 21600000:
return '6 시간';
case 43200000:
return '12 시간';
case 86400000:
return '24 시간';
default:
return '0 초';
}
}
2019-10-07 13:49:12 +09:00
}