수정 :: event info state 를 entity 처리 하도록 수정.

기능 구현 :: 대화 회수시 현재 대화방의 event 회수 처리 할 수 있도록 수정.
This commit is contained in:
leejh 2019-10-15 19:09:26 +09:00
parent 43f937e74c
commit 7ec9d2356b
5 changed files with 105 additions and 11 deletions

View File

@ -83,7 +83,7 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewChecked {
);
this.eventList$ = this.store.pipe(
select(AppStore.MessengerSelector.EventSelector.infoList)
select(AppStore.MessengerSelector.EventSelector.selectAllInfoList)
);
this.scrollToBottomForMessageBoxContainer();

View File

@ -37,6 +37,13 @@ export const newInfo = createAction(
}>()
);
export const recallInfoList = createAction(
'[Messenger::Event] recall InfoList',
props<{
eventSeq: number;
}>()
);
export const appendInfoList = createAction(
'[Messenger::Event] Append InfoList',
props<{

View File

@ -39,7 +39,8 @@ import {
sendNotification,
readNotification,
cancelNotification,
delNotification
delNotification,
recallInfoList
} from './actions';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import { RoomInfo } from '@ucap-webmessenger/protocol-room';
@ -194,8 +195,20 @@ export class Effects {
() => {
return this.actions$.pipe(
ofType(cancelNotification),
map(action => action.noti),
tap(noti => {})
withLatestFrom(
this.store.pipe(
select((state: any) => state.messenger.room.roomInfo as RoomInfo)
)
),
tap(([action, roomInfo]) => {
if (!!roomInfo && roomInfo.roomSeq === action.noti.roomSeq) {
this.logger.debug('cancelNotification$', action, roomInfo);
this.store.dispatch(
recallInfoList({ eventSeq: action.noti.eventSeq })
);
// this.store.dispatch(ChatStore.newEventMessage(action));
}
})
);
},
{ dispatch: false }

View File

@ -1,7 +1,14 @@
import { createReducer, on } from '@ngrx/store';
import { initialState } from './state';
import { infoSuccess, appendInfoList, info, infoFailure } from './actions';
import { initialState, adapterInfoList } from './state';
import {
infoSuccess,
appendInfoList,
info,
infoFailure,
recallInfoList
} from './actions';
import * as AuthenticationStore from '@app/store/account/authentication';
import { Info, EventType } from '@ucap-webmessenger/protocol-event';
export const reducer = createReducer(
initialState,
@ -15,7 +22,9 @@ export const reducer = createReducer(
on(infoSuccess, (state, action) => {
return {
...state,
infoList: action.infoList,
infoList: adapterInfoList.addAll(action.infoList, {
...state.infoList
}),
infoStatus: action.res,
infoListProcessing: false
};
@ -29,9 +38,38 @@ export const reducer = createReducer(
}),
on(appendInfoList, (state, action) => {
const eventinfo = action.info;
const statusEventInfo: Info = {
...state.infoList.entities[eventinfo.seq],
type: eventinfo.type,
senderSeq: eventinfo.senderSeq,
sendDate: eventinfo.sendDate,
sentMessage: eventinfo.sentMessage,
receiverCount: eventinfo.receiverCount
};
return {
...state,
infoList: [...state.infoList, action.info]
infoList: adapterInfoList.upsertOne(eventinfo, { ...state.infoList })
};
}),
on(recallInfoList, (state, action) => {
const eventSeq = action.eventSeq;
const statusEventInfo: Info = {
...state.infoList.entities[eventSeq],
type: EventType.RecalledMessage,
sentMessage: '회수된 메시지'
};
return {
...state,
infoList: adapterInfoList.updateOne(
{ id: eventSeq, changes: statusEventInfo },
{ ...state.infoList }
)
};
}),

View File

@ -1,19 +1,40 @@
import { Selector, createSelector } from '@ngrx/store';
import { InfoResponse, Info } from '@ucap-webmessenger/protocol-event';
import { EntityState, createEntityAdapter } from '@ngrx/entity';
export interface InfoListState extends EntityState<Info> {}
export interface State {
infoListProcessing: boolean;
infoList: Info[] | null;
infoList: InfoListState;
infoStatus: InfoResponse | null;
}
export const adapterInfoList = createEntityAdapter<Info>({
selectId: info => info.seq
});
const infoListInitialState: InfoListState = adapterInfoList.getInitialState({});
export const initialState: State = {
infoListProcessing: false,
infoList: null,
infoList: infoListInitialState,
infoStatus: null
};
const {
selectAll: ngeSelectAllInfoList,
selectEntities: ngeSelectEntitiesInfoList,
selectIds: ngeSelectIdsInfoList,
selectTotal: ngeSelectTotalInfoList
} = adapterInfoList.getSelectors();
export function selectors<S>(selector: Selector<any, State>) {
const selectInfoList = createSelector(
selector,
(state: State) => state.infoList
);
return {
infoListProcessing: createSelector(
selector,
@ -26,6 +47,21 @@ export function selectors<S>(selector: Selector<any, State>) {
infoStatus: createSelector(
selector,
(state: State) => state.infoStatus
),
selectAllInfoList: createSelector(
selectInfoList,
ngeSelectAllInfoList
),
selectEntitiesInfoList: createSelector(
selectInfoList,
ngeSelectEntitiesInfoList
),
selectInfoList: (seq: number) =>
createSelector(
selectInfoList,
ngeSelectEntitiesInfoList,
(_, entities) => (!!entities ? entities[seq] : undefined)
)
};
}