기능구현 :: 대화방 > 대화 회수, 삭제

This commit is contained in:
leejh 2019-10-24 10:45:28 +09:00
parent 9df7e98778
commit 45892b4991
5 changed files with 178 additions and 59 deletions

View File

@ -10,7 +10,10 @@ import {
ucapAnimations, ucapAnimations,
SnackBarService, SnackBarService,
ClipboardService, ClipboardService,
DialogService DialogService,
ConfirmDialogComponent,
ConfirmDialogData,
ConfirmDialogResult
} from '@ucap-webmessenger/ui'; } from '@ucap-webmessenger/ui';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import { NGXLogger } from 'ngx-logger'; import { NGXLogger } from 'ngx-logger';
@ -336,31 +339,50 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewChecked {
case 'DELETE': case 'DELETE':
{ {
const result = await this.dialogService.open< const result = await this.dialogService.open<
DeleteMessageDialogComponent, ConfirmDialogComponent,
DeleteMessageDialogData, ConfirmDialogData,
DeleteMessageDialogResult ConfirmDialogResult
>(DeleteMessageDialogComponent, { >(ConfirmDialogComponent, {
width: '220px', width: '220px',
data: { data: {
title: 'Logout', title: 'Delete',
message: 'Logout ?' html: `선택한 메시지를 삭제하시겠습니까?<br/>삭제된 메시지는 내 대화방에서만 적용되며 상대방의 대화방에서는 삭제되지 않습니다.`
} }
}); });
if (!!result && !!result.choice && result.choice) {
this.store.dispatch(
EventStore.del({
roomSeq: this.roomInfo.roomSeq,
eventSeq: message.seq
})
);
}
} }
break; break;
case 'RECALL': case 'RECALL':
{ {
const result = await this.dialogService.open< const result = await this.dialogService.open<
RecallMessageDialogComponent, ConfirmDialogComponent,
RecallMessageDialogData, ConfirmDialogData,
RecallMessageDialogResult ConfirmDialogResult
>(RecallMessageDialogComponent, { >(ConfirmDialogComponent, {
width: '220px', width: '220px',
data: { data: {
title: 'Logout', title: 'ReCall',
message: 'Logout ?' html: `해당 대화를 회수하시겠습니까?<br/>상대방 대화창에서도 회수됩니다.`
} }
}); });
if (!!result && !!result.choice && result.choice) {
this.store.dispatch(
EventStore.cancel({
roomSeq: this.roomInfo.roomSeq,
eventSeq: message.seq,
deviceType: this.environmentsInfo.deviceType
})
);
}
} }
break; break;
default: default:

View File

@ -9,7 +9,11 @@ import {
ReadNotification, ReadNotification,
CancelNotification, CancelNotification,
DelNotification, DelNotification,
ReadRequest ReadRequest,
DelRequest,
DelResponse,
CancelRequest,
CancelResponse
} from '@ucap-webmessenger/protocol-event'; } from '@ucap-webmessenger/protocol-event';
export const info = createAction( export const info = createAction(
@ -38,13 +42,6 @@ export const newInfo = createAction(
}>() }>()
); );
export const recallInfoList = createAction(
'[Messenger::Event] recall InfoList',
props<{
eventSeq: number;
}>()
);
export const appendInfoList = createAction( export const appendInfoList = createAction(
'[Messenger::Event] Append InfoList', '[Messenger::Event] Append InfoList',
props<{ props<{
@ -70,6 +67,11 @@ export const sendFailure = createAction(
props<{ error: any }>() props<{ error: any }>()
); );
export const sendNotification = createAction(
'[Messenger::Event] Send Notification',
props<{ noti: SendNotification }>()
);
export const read = createAction( export const read = createAction(
'[Messenger::Event] read', '[Messenger::Event] read',
props<ReadRequest>() props<ReadRequest>()
@ -88,22 +90,49 @@ export const readFailure = createAction(
props<{ error: any }>() props<{ error: any }>()
); );
export const sendNotification = createAction(
'[Messenger::Event] Send Notification',
props<{ noti: SendNotification }>()
);
export const readNotification = createAction( export const readNotification = createAction(
'[Messenger::Event] Read Notification', '[Messenger::Event] Read Notification',
props<{ noti: ReadNotification }>() props<{ noti: ReadNotification }>()
); );
/** 대화 회수 */
export const cancel = createAction(
'[Messenger::Event] Cancel',
props<CancelRequest>()
);
export const cancelFailure = createAction(
'[Messenger::Event] Cancel Failure',
props<{ error: any }>()
);
export const cancelNotification = createAction( export const cancelNotification = createAction(
'[Messenger::Event] Cancel Notification', '[Messenger::Event] Cancel Notification || Response',
props<{ noti: CancelNotification }>() props<{ noti: CancelNotification | CancelResponse }>()
);
/** 대화 회수시 열린 대화방의 대화 내용 갱신 */
export const recallInfoList = createAction(
'[Messenger::Event] Cancel InfoList',
props<{
eventSeq: number;
}>()
); );
export const delNotification = createAction( /** 대화 삭제 */
'[Messenger::Event] Delete Notification', export const del = createAction(
props<{ noti: DelNotification }>() '[Messenger::Event] Delete',
props<DelRequest>()
);
export const delFailure = createAction(
'[Messenger::Event] Delete Failure',
props<{ error: any }>()
);
export const delNotification = createAction(
'[Messenger::Event] Delete Notification || Response',
props<{ noti: DelNotification | DelResponse }>()
);
/** 대화 삭제시 열린 대화방의 대화 내용 갱신 */
export const delInfoList = createAction(
'[Messenger::Event] Delete InfoList',
props<{
eventSeq: number;
}>()
); );

View File

@ -23,7 +23,9 @@ import {
SSVC_TYPE_EVENT_INFO_DATA, SSVC_TYPE_EVENT_INFO_DATA,
SSVC_TYPE_EVENT_INFO_RES, SSVC_TYPE_EVENT_INFO_RES,
SendResponse, SendResponse,
ReadResponse ReadResponse,
DelResponse,
CancelResponse
} from '@ucap-webmessenger/protocol-event'; } from '@ucap-webmessenger/protocol-event';
import * as ChatStore from '@app/store/messenger/chat'; import * as ChatStore from '@app/store/messenger/chat';
@ -44,11 +46,15 @@ import {
delNotification, delNotification,
recallInfoList, recallInfoList,
read, read,
readFailure readFailure,
del,
delFailure,
delInfoList,
cancel,
cancelFailure
} from './actions'; } from './actions';
import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import { RoomInfo } from '@ucap-webmessenger/protocol-room'; import { RoomInfo } from '@ucap-webmessenger/protocol-room';
import { refreshRoom } from '../sync';
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types'; import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
import { Dictionary } from '@ngrx/entity'; import { Dictionary } from '@ngrx/entity';
@ -124,12 +130,7 @@ export class Effects {
switchMap(req => { switchMap(req => {
return this.eventProtocolService.read(req).pipe( return this.eventProtocolService.read(req).pipe(
map((res: ReadResponse) => { map((res: ReadResponse) => {
this.store.dispatch( readNotification({ noti: res });
SyncStore.updateUnreadCount({
roomSeq: res.roomSeq,
noReadCnt: 0
})
);
}), }),
catchError(error => of(readFailure({ error }))) catchError(error => of(readFailure({ error })))
); );
@ -139,6 +140,24 @@ export class Effects {
{ dispatch: false } { dispatch: false }
); );
readNotification$ = createEffect(
() => {
return this.actions$.pipe(
ofType(readNotification),
map(action => action.noti),
tap(noti => {
this.store.dispatch(
SyncStore.updateUnreadCount({
roomSeq: noti.roomSeq,
noReadCnt: 0
})
);
})
);
},
{ dispatch: false }
);
send$ = createEffect(() => send$ = createEffect(() =>
this.actions$.pipe( this.actions$.pipe(
ofType(send), ofType(send),
@ -246,15 +265,18 @@ export class Effects {
{ dispatch: false } { dispatch: false }
); );
readNotification$ = createEffect( cancel$ = createEffect(() =>
() => { this.actions$.pipe(
return this.actions$.pipe( ofType(cancel),
ofType(readNotification), exhaustMap(req =>
map(action => action.noti), this.eventProtocolService.cancel(req).pipe(
tap(noti => {}) map((res: CancelResponse) => {
); return cancelNotification({ noti: res });
}, }),
{ dispatch: false } catchError(error => of(cancelFailure({ error })))
)
)
)
); );
cancelNotification$ = createEffect( cancelNotification$ = createEffect(
@ -269,7 +291,6 @@ export class Effects {
tap(([action, roomInfo]) => { tap(([action, roomInfo]) => {
// 현재 방이 오픈되어 있으면 방내용 갱신 // 현재 방이 오픈되어 있으면 방내용 갱신
if (!!roomInfo && roomInfo.roomSeq === action.noti.roomSeq) { if (!!roomInfo && roomInfo.roomSeq === action.noti.roomSeq) {
this.logger.debug('cancelNotification$', action, roomInfo);
this.store.dispatch( this.store.dispatch(
recallInfoList({ eventSeq: action.noti.eventSeq }) recallInfoList({ eventSeq: action.noti.eventSeq })
); );
@ -291,12 +312,48 @@ export class Effects {
{ dispatch: false } { dispatch: false }
); );
del$ = createEffect(() =>
this.actions$.pipe(
ofType(del),
exhaustMap(req =>
this.eventProtocolService.del(req).pipe(
map((res: DelResponse) => {
return delNotification({ noti: res });
}),
catchError(error => of(delFailure({ error })))
)
)
)
);
delNotification$ = createEffect( delNotification$ = createEffect(
() => { () => {
return this.actions$.pipe( return this.actions$.pipe(
ofType(delNotification), ofType(delNotification),
map(action => action.noti), map(action => action.noti),
tap(noti => {}) withLatestFrom(
this.store.pipe(
select((state: any) => state.messenger.room.roomInfo as RoomInfo)
)
),
tap(([noti, roomInfo]) => {
// 현재 방이 오픈되어 있으면 방내용 갱신
if (!!roomInfo && roomInfo.roomSeq === noti.roomSeq) {
this.store.dispatch(delInfoList({ eventSeq: noti.eventSeq }));
}
// 대화 > 리스트의 항목 갱신
const loginInfo = this.sessionStorageService.get<LoginInfo>(
KEY_LOGIN_INFO
);
this.store.dispatch(
SyncStore.refreshRoom({
roomSeq: noti.roomSeq,
isDetail: true,
localeCode: loginInfo.localeCode
})
);
})
); );
}, },
{ dispatch: false } { dispatch: false }

View File

@ -5,7 +5,8 @@ import {
appendInfoList, appendInfoList,
info, info,
infoFailure, infoFailure,
recallInfoList recallInfoList,
delInfoList
} from './actions'; } from './actions';
import * as AuthenticationStore from '@app/store/account/authentication'; import * as AuthenticationStore from '@app/store/account/authentication';
import { Info, EventType } from '@ucap-webmessenger/protocol-event'; import { Info, EventType } from '@ucap-webmessenger/protocol-event';
@ -73,6 +74,15 @@ export const reducer = createReducer(
}; };
}), }),
on(delInfoList, (state, action) => {
const eventSeq = action.eventSeq;
return {
...state,
infoList: adapterInfoList.removeOne(eventSeq, { ...state.infoList })
};
}),
on(AuthenticationStore.logout, (state, action) => { on(AuthenticationStore.logout, (state, action) => {
return { return {
...initialState ...initialState

View File

@ -53,12 +53,6 @@ import {
decodeReadNotification, decodeReadNotification,
ReadNotification ReadNotification
} from '../protocols/read'; } from '../protocols/read';
import {
DelRequest,
DelResponse,
encodeDel,
decodeDel
} from '@ucap-webmessenger/protocol-buddy';
import { import {
CancelRequest, CancelRequest,
CancelResponse, CancelResponse,
@ -67,7 +61,14 @@ import {
CancelNotification, CancelNotification,
decodeCancelNotification decodeCancelNotification
} from '../protocols/cancel'; } from '../protocols/cancel';
import { decodeDelNotification, DelNotification } from '../protocols/del'; import {
decodeDelNotification,
DelNotification,
DelRequest,
DelResponse,
encodeDel,
decodeDel
} from '../protocols/del';
type Notifications = type Notifications =
| SendNotification | SendNotification