추가 :: 대화방 오픈시 EVENT_READ_REQ 수행.

This commit is contained in:
leejh 2019-10-16 14:52:31 +09:00
parent e4fd26f0b6
commit ac87fcf9c7
4 changed files with 115 additions and 11 deletions

View File

@ -8,7 +8,8 @@ import {
SendNotification, SendNotification,
ReadNotification, ReadNotification,
CancelNotification, CancelNotification,
DelNotification DelNotification,
ReadRequest
} from '@ucap-webmessenger/protocol-event'; } from '@ucap-webmessenger/protocol-event';
export const info = createAction( export const info = createAction(
@ -69,6 +70,24 @@ export const sendFailure = createAction(
props<{ error: any }>() props<{ error: any }>()
); );
export const read = createAction(
'[Messenger::Event] read',
props<ReadRequest>()
);
export const readSuccess = createAction(
'[Messenger::Event] read Success',
props<{
infoList: Info[];
res: InfoResponse;
}>()
);
export const readFailure = createAction(
'[Messenger::Event] read Failure',
props<{ error: any }>()
);
export const sendNotification = createAction( export const sendNotification = createAction(
'[Messenger::Event] Send Notification', '[Messenger::Event] Send Notification',
props<{ noti: SendNotification }>() props<{ noti: SendNotification }>()

View File

@ -22,7 +22,8 @@ import {
EventProtocolService, EventProtocolService,
SSVC_TYPE_EVENT_INFO_DATA, SSVC_TYPE_EVENT_INFO_DATA,
SSVC_TYPE_EVENT_INFO_RES, SSVC_TYPE_EVENT_INFO_RES,
SendResponse SendResponse,
ReadResponse
} 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';
@ -41,12 +42,15 @@ import {
readNotification, readNotification,
cancelNotification, cancelNotification,
delNotification, delNotification,
recallInfoList recallInfoList,
read,
readFailure
} 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 { refreshRoom } from '../sync';
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types'; import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
import { Dictionary } from '@ngrx/entity';
@Injectable() @Injectable()
export class Effects { export class Effects {
@ -80,12 +84,28 @@ export class Effects {
infoList.push(...(res as InfoData).infoList); infoList.push(...(res as InfoData).infoList);
break; break;
case SSVC_TYPE_EVENT_INFO_RES: case SSVC_TYPE_EVENT_INFO_RES:
this.store.dispatch( {
infoSuccess({ this.store.dispatch(
infoList, infoSuccess({
res: res as InfoResponse infoList,
}) res: res as InfoResponse
); })
);
if (req.baseSeq === 0) {
// 최초 이벤트 목록 조회시 SSVC_TYPE_EVENT_READ_REQ 수행.
const maxSeq = Math.max.apply(
Math,
infoList.map(v => v.seq)
);
this.store.dispatch(
read({
roomSeq: req.roomSeq,
lastReadSeq: Number(maxSeq)
})
);
}
}
break; break;
} }
}), }),
@ -97,6 +117,28 @@ export class Effects {
{ dispatch: false } { dispatch: false }
); );
read$ = createEffect(
() => {
return this.actions$.pipe(
ofType(read),
switchMap(req => {
return this.eventProtocolService.read(req).pipe(
map((res: ReadResponse) => {
this.store.dispatch(
SyncStore.updateUnreadCount({
roomSeq: res.roomSeq,
noReadCnt: 0
})
);
}),
catchError(error => of(readFailure({ error })))
);
})
);
},
{ dispatch: false }
);
send$ = createEffect(() => send$ = createEffect(() =>
this.actions$.pipe( this.actions$.pipe(
ofType(send), ofType(send),
@ -169,13 +211,32 @@ export class Effects {
withLatestFrom( withLatestFrom(
this.store.pipe( this.store.pipe(
select((state: any) => state.messenger.room.roomInfo as RoomInfo) select((state: any) => state.messenger.room.roomInfo as RoomInfo)
),
this.store.pipe(
select(
(state: any) =>
state.messenger.sync.room.entities as Dictionary<RoomInfo>
)
) )
), ),
tap(([action, roomInfo]) => { tap(([action, roomInfo, trgtRoomInfos]) => {
// opened room :: event add
if (!!roomInfo && roomInfo.roomSeq === action.roomSeq) { if (!!roomInfo && roomInfo.roomSeq === action.roomSeq) {
this.store.dispatch(appendInfoList({ info: action.info })); this.store.dispatch(appendInfoList({ info: action.info }));
} }
// not opened room :: unread count increased
if (!roomInfo || roomInfo.roomSeq !== action.roomSeq) {
const noReadCnt = trgtRoomInfos[action.roomSeq].noReadCnt;
this.store.dispatch(
SyncStore.updateUnreadCount({
roomSeq: action.roomSeq,
noReadCnt: noReadCnt + 1
})
);
}
// 대화 > 리스트 :: finalEventMessage refresh
this.store.dispatch(ChatStore.newEventMessage(action)); this.store.dispatch(ChatStore.newEventMessage(action));
}) })
); );

View File

@ -93,3 +93,11 @@ export const refreshRoomFailure = createAction(
'[Messenger::Sync] refresh room in sync Failure', '[Messenger::Sync] refresh room in sync Failure',
props<{ error: any }>() props<{ error: any }>()
); );
export const updateUnreadCount = createAction(
'[Messenger::Sync] Update unread count',
props<{
roomSeq: string;
noReadCnt?: number;
}>()
);

View File

@ -12,7 +12,8 @@ import {
group2Success, group2Success,
roomSuccess, roomSuccess,
updateRoomForNewEventMessage, updateRoomForNewEventMessage,
refreshRoomSuccess refreshRoomSuccess,
updateUnreadCount
} from './actions'; } from './actions';
import { import {
RoomUserDetailData, RoomUserDetailData,
@ -145,6 +146,21 @@ export const reducer = createReducer(
}; };
}), }),
on(updateUnreadCount, (state, action) => {
const roomInfo: RoomInfo = {
...state.room.entities[action.roomSeq],
noReadCnt: action.noReadCnt
};
return {
...state,
room: adapterRoom.updateOne(
{ id: action.roomSeq, changes: roomInfo },
{ ...state.room }
)
};
}),
on(AuthenticationStore.logout, (state, action) => { on(AuthenticationStore.logout, (state, action) => {
return { return {
...initialState ...initialState