timer room 기능 추가.

This commit is contained in:
leejh 2019-10-31 15:05:59 +09:00
parent 9d0f6bdd8a
commit 4bfb41adf0
9 changed files with 151 additions and 29 deletions

View File

@ -59,7 +59,7 @@ export class LeftSideComponent implements OnInit {
]; ];
} }
async onClickNewChat() { async onClickNewChat(type: string = 'NORMAL') {
const result = await this.dialogService.open< const result = await this.dialogService.open<
CreateChatDialogComponent, CreateChatDialogComponent,
CreateChatDialogData, CreateChatDialogData,
@ -69,7 +69,7 @@ export class LeftSideComponent implements OnInit {
height: '500px', height: '500px',
data: { data: {
type: UserSelectDialogType.NewChat, type: UserSelectDialogType.NewChat,
title: 'New Chat' title: type === 'TIMER' ? 'New Timer Chat' : 'New Chat'
} }
}); });
@ -78,7 +78,13 @@ export class LeftSideComponent implements OnInit {
const userSeqs: number[] = []; const userSeqs: number[] = [];
result.selectedUserList.map(user => userSeqs.push(user.seq)); result.selectedUserList.map(user => userSeqs.push(user.seq));
this.store.dispatch(ChatStore.openRoom({ userSeqList: userSeqs })); if (type === 'NORMAL') {
this.store.dispatch(ChatStore.openRoom({ userSeqList: userSeqs }));
} else if (type === 'TIMER') {
this.store.dispatch(
ChatStore.openRoom({ userSeqList: userSeqs, isTimeRoom: true })
);
}
} }
} }
} }
@ -134,11 +140,12 @@ export class LeftSideComponent implements OnInit {
switch (btn.divisionType) { switch (btn.divisionType) {
case 'NEW_CHAT': case 'NEW_CHAT':
{ {
this.onClickNewChat(); this.onClickNewChat('NORMAL');
} }
break; break;
case 'NEW_TIMER_CHAT': case 'NEW_TIMER_CHAT':
{ {
this.onClickNewChat('TIMER');
} }
break; break;
} }

View File

@ -18,6 +18,9 @@
<div class="room-name"> <div class="room-name">
{{ getRoomName() }} {{ getRoomName() }}
</div> </div>
<div *ngIf="!!roomInfo && roomInfo.isTimeRoom">
<mat-icon>timer</mat-icon> {{ getConvertTimer(roomInfo.timeRoomInterval) }}
</div>
<div class="room-option"> <div class="room-option">
<button <button
*ngIf="!!roomInfo" *ngIf="!!roomInfo"

View File

@ -199,6 +199,18 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewChecked {
} }
} }
getConvertTimer(timerInterval: number, unit: number = 1) {
if (timerInterval >= 0 && timerInterval < 60 * unit) {
return Math.floor((timerInterval / 1) * unit) + ' 초';
} else if (timerInterval >= 60 * unit && timerInterval < 3600 * unit) {
return Math.floor(((timerInterval / 1) * unit) / 60) + ' 분';
} else if (timerInterval >= 3600 * unit && timerInterval <= 86400 * unit) {
return Math.floor(((timerInterval / 1) * unit) / 60 / 60) + ' 시간';
} else {
return '';
}
}
selectContact() {} selectContact() {}
async onSendMessage(message: string) { async onSendMessage(message: string) {

View File

@ -41,5 +41,5 @@ export const massTalkDownloadFailure = createAction(
export const openRoom = createAction( export const openRoom = createAction(
'[Messenger::Chat] Open Room', '[Messenger::Chat] Open Room',
props<{ userSeqList: number[] }>() props<{ userSeqList: number[]; isTimeRoom?: boolean }>()
); );

View File

@ -13,7 +13,9 @@ import {
OpenRequest, OpenRequest,
OpenResponse, OpenResponse,
ExitRequest, ExitRequest,
ExitResponse ExitResponse,
Open3Request,
Open3Response
} from '@ucap-webmessenger/protocol-room'; } from '@ucap-webmessenger/protocol-room';
import { ReadNotification } from '@ucap-webmessenger/protocol-event'; import { ReadNotification } from '@ucap-webmessenger/protocol-event';
@ -87,19 +89,32 @@ export const open = createAction(
'[Messenger::Room] Open', '[Messenger::Room] Open',
props<{ req: OpenRequest }>() props<{ req: OpenRequest }>()
); );
export const openSuccess = createAction( export const openSuccess = createAction(
'[Messenger::Room] Open Success', '[Messenger::Room] Open Success',
props<{ props<{
res: OpenResponse; res: OpenResponse;
}>() }>()
); );
export const openFailure = createAction( export const openFailure = createAction(
'[Messenger::Room] Open Failure', '[Messenger::Room] Open Failure',
props<{ error: any }>() props<{ error: any }>()
); );
export const openTimer = createAction(
'[Messenger::Room] Open Timer',
props<{ req: Open3Request }>()
);
export const openTimerSuccess = createAction(
'[Messenger::Room] Open Timer Success',
props<{
res: Open3Response;
}>()
);
export const openTimerFailure = createAction(
'[Messenger::Room] Open Timer Failure',
props<{ error: any }>()
);
export const exit = createAction( export const exit = createAction(
'[Messenger::Room] Exit', '[Messenger::Room] Exit',
props<ExitRequest>() props<ExitRequest>()

View File

@ -29,7 +29,8 @@ import {
UserData, UserData,
UpdateResponse, UpdateResponse,
OpenResponse, OpenResponse,
ExitResponse ExitResponse,
Open3Response
} from '@ucap-webmessenger/protocol-room'; } from '@ucap-webmessenger/protocol-room';
import * as ChatStore from '@app/store/messenger/chat'; import * as ChatStore from '@app/store/messenger/chat';
@ -51,7 +52,10 @@ import {
openFailure, openFailure,
exit, exit,
exitSuccess, exitSuccess,
exitFailure exitFailure,
openTimer,
openTimerSuccess,
openTimerFailure
} from './actions'; } from './actions';
import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types'; import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
@ -168,7 +172,6 @@ export class Effects {
}) })
) )
); );
openSuccess$ = createEffect(() => openSuccess$ = createEffect(() =>
this.actions$.pipe( this.actions$.pipe(
ofType(openSuccess), ofType(openSuccess),
@ -178,6 +181,29 @@ export class Effects {
) )
); );
openTimer$ = createEffect(() =>
this.actions$.pipe(
ofType(openTimer),
map(action => action.req),
exhaustMap(req => {
return this.roomProtocolService.open3(req).pipe(
map((res: Open3Response) => {
return openTimerSuccess({ res });
}),
catchError(error => of(openTimerFailure({ error })))
);
})
)
);
openTimerSuccess$ = createEffect(() =>
this.actions$.pipe(
ofType(openTimerSuccess),
map(action => {
return ChatStore.selectedRoom({ roomSeq: action.res.roomSeq });
})
)
);
exit$ = createEffect(() => exit$ = createEffect(() =>
this.actions$.pipe( this.actions$.pipe(
ofType(exit), ofType(exit),

View File

@ -1,4 +1,4 @@
import { GroupProtocolService } from './../../../../../../ucap-webmessenger-protocol-group/src/lib/services/group-protocol.service'; import { openTimer } from './../room/actions';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects'; import { Actions, ofType, createEffect } from '@ngrx/effects';
@ -87,6 +87,7 @@ import {
} from '@ucap-webmessenger/protocol-room'; } from '@ucap-webmessenger/protocol-room';
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication'; import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
import { import {
GroupProtocolService,
AddResponse as GroupAddResponse, AddResponse as GroupAddResponse,
UpdateResponse as GroupUpdateResponse, UpdateResponse as GroupUpdateResponse,
DelResponse as GroupDelResponse DelResponse as GroupDelResponse
@ -299,6 +300,12 @@ export class Effects {
state.account.authentication.loginRes as LoginResponse state.account.authentication.loginRes as LoginResponse
) )
), ),
this.store.pipe(
select(
(state: any) =>
state.messenger.sync.room.entities as Dictionary<RoomInfo>
)
),
this.store.pipe( this.store.pipe(
select( select(
(state: any) => (state: any) =>
@ -316,7 +323,7 @@ export class Effects {
) )
) )
), ),
tap(([action, loginRes, roomUsers, roomUserShorts]) => { tap(([action, loginRes, roomInfos, roomUsers, roomUserShorts]) => {
const userSeqList = [...action.userSeqList, loginRes.userSeq]; const userSeqList = [...action.userSeqList, loginRes.userSeq];
let roomSeq = null; let roomSeq = null;
@ -325,6 +332,20 @@ export class Effects {
const element = roomUsers[key]; const element = roomUsers[key];
if (userSeqList.length === element.userInfos.length) { if (userSeqList.length === element.userInfos.length) {
roomSeq = key; roomSeq = key;
if (!!action.isTimeRoom && action.isTimeRoom) {
// 타이머 방
if (!roomInfos[key].isTimeRoom) {
roomSeq = null;
continue;
}
} else {
// 일반 방
if (roomInfos[key].isTimeRoom) {
roomSeq = null;
continue;
}
}
// user check
for (const roomUserInfo of element.userInfos) { for (const roomUserInfo of element.userInfos) {
if (-1 === userSeqList.indexOf(roomUserInfo.seq)) { if (-1 === userSeqList.indexOf(roomUserInfo.seq)) {
roomSeq = null; roomSeq = null;
@ -340,6 +361,20 @@ export class Effects {
const element = roomUserShorts[key]; const element = roomUserShorts[key];
if (userSeqList.length === element.userInfos.length) { if (userSeqList.length === element.userInfos.length) {
roomSeq = key; roomSeq = key;
if (!!action.isTimeRoom && action.isTimeRoom) {
// 타이머 방
if (!roomInfos[key].isTimeRoom) {
roomSeq = null;
continue;
}
} else {
// 일반 방
if (roomInfos[key].isTimeRoom) {
roomSeq = null;
continue;
}
}
// user check
for (const roomUserDetailData of element.userInfos) { for (const roomUserDetailData of element.userInfos) {
if (-1 === userSeqList.indexOf(roomUserDetailData.seq)) { if (-1 === userSeqList.indexOf(roomUserDetailData.seq)) {
roomSeq = null; roomSeq = null;
@ -362,11 +397,27 @@ export class Effects {
return; return;
} }
this.store.dispatch( if (!!action.isTimeRoom && action.isTimeRoom) {
RoomStore.open({ // 타이머 방
req: { divCd: 'DivCode', userSeqs: userSeqList } this.store.dispatch(
}) RoomStore.openTimer({
); req: {
divCd: 'DivCodeT',
roomName: '',
isTimerRoom: true,
timerRoomInterval: 24 * 60 * 60, // 24h default
userSeqs: userSeqList
}
})
);
} else {
// 일반 방
this.store.dispatch(
RoomStore.open({
req: { divCd: 'DivCode', userSeqs: userSeqList }
})
);
}
}) })
), ),
{ dispatch: false } { dispatch: false }

View File

@ -123,17 +123,23 @@ export const encodeOpen3: ProtocolEncoder<Open3Request> = (
req: Open3Request req: Open3Request
) => { ) => {
const bodyList: PacketBody[] = []; const bodyList: PacketBody[] = [];
let roomName: string = req.roomName.trim();
if (!!roomName && roomName.length === 0) {
roomName = ' ';
}
bodyList.push({ type: PacketBodyValue.String, value: req.divCd }); bodyList.push(
bodyList.push({ type: PacketBodyValue.String, value: req.roomName.trim() }); { type: PacketBodyValue.String, value: req.divCd },
bodyList.push({ { type: PacketBodyValue.String, value: roomName },
type: PacketBodyValue.String, {
value: req.isTimerRoom === true ? 'Y' : 'N' type: PacketBodyValue.String,
}); value: req.isTimerRoom === true ? 'Y' : 'N'
bodyList.push({ },
type: PacketBodyValue.Integer, {
value: req.isTimerRoom !== true ? 0 : req.timerRoomInterval type: PacketBodyValue.Integer,
}); value: req.isTimerRoom !== true ? 0 : req.timerRoomInterval
}
);
for (const userSeq of req.userSeqs) { for (const userSeq of req.userSeqs) {
bodyList.push({ type: PacketBodyValue.Integer, value: userSeq }); bodyList.push({ type: PacketBodyValue.Integer, value: userSeq });
} }

View File

@ -44,7 +44,9 @@
</mat-checkbox> </mat-checkbox>
</dd> </dd>
</dl> </dl>
<!-- <span class="noti">1</span> --> <span *ngIf="roomInfo.isTimeRoom">
<mat-icon>timer</mat-icon>
</span>
<span <span
class="notiBadge" class="notiBadge"
*ngIf="roomInfo.noReadCnt > 0" *ngIf="roomInfo.noReadCnt > 0"