2019-10-02 18:09:39 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
|
|
|
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2020-03-27 15:01:03 +09:00
|
|
|
import * as RoomStore from '@app/store/messenger/room';
|
2019-10-02 18:09:39 +09:00
|
|
|
import * as SyncStore from '@app/store/messenger/sync';
|
2020-01-20 13:25:59 +09:00
|
|
|
import * as AuthStore from '@app/store/account/authentication';
|
2019-10-11 14:01:43 +09:00
|
|
|
import {
|
|
|
|
bulkInfo,
|
|
|
|
bulkInfoSuccess,
|
|
|
|
bulkInfoFailure,
|
2020-01-10 16:49:53 +09:00
|
|
|
status,
|
|
|
|
statusFailure,
|
2020-01-20 13:25:59 +09:00
|
|
|
statusSuccess,
|
|
|
|
messageUpdate,
|
|
|
|
messageUpdateFailure
|
2019-10-11 14:01:43 +09:00
|
|
|
} from './actions';
|
2020-02-05 14:10:34 +09:00
|
|
|
import {
|
|
|
|
tap,
|
|
|
|
switchMap,
|
|
|
|
map,
|
|
|
|
catchError,
|
|
|
|
exhaustMap,
|
|
|
|
delay
|
|
|
|
} from 'rxjs/operators';
|
2019-10-02 18:09:39 +09:00
|
|
|
import {
|
|
|
|
StatusProtocolService,
|
|
|
|
SSVC_TYPE_STATUS_BULK_INFO_DATA,
|
|
|
|
SSVC_TYPE_STATUS_BULK_INFO_RES,
|
|
|
|
BulkInfoData,
|
2020-01-10 16:49:53 +09:00
|
|
|
StatusBulkInfo,
|
2020-01-20 13:25:59 +09:00
|
|
|
StatusResponse,
|
|
|
|
MessageUpdateResponse
|
2019-10-02 18:09:39 +09:00
|
|
|
} from '@ucap-webmessenger/protocol-status';
|
|
|
|
import { of } from 'rxjs';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
buddy2SuccessPostBulk$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(SyncStore.buddy2Success),
|
|
|
|
map(params => {
|
|
|
|
const userSeqList: number[] = [];
|
|
|
|
for (const buddy of params.buddyList) {
|
|
|
|
userSeqList.push(buddy.seq);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bulkInfo({ divCd: 'bulk', userSeqs: userSeqList });
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
bulkInfo$ = createEffect(
|
|
|
|
() => {
|
|
|
|
let statusBulkInfoList: StatusBulkInfo[];
|
|
|
|
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(bulkInfo),
|
|
|
|
tap(() => {
|
|
|
|
statusBulkInfoList = [];
|
|
|
|
}),
|
|
|
|
switchMap(req => {
|
|
|
|
return this.statusProtocolService.bulkInfo(req).pipe(
|
|
|
|
map(res => {
|
2019-10-10 12:14:01 +09:00
|
|
|
switch (res.SSVC_TYPE) {
|
2019-10-02 18:09:39 +09:00
|
|
|
case SSVC_TYPE_STATUS_BULK_INFO_DATA:
|
|
|
|
statusBulkInfoList.push(
|
|
|
|
...(res as BulkInfoData).statusBulkInfos
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_STATUS_BULK_INFO_RES:
|
|
|
|
this.store.dispatch(
|
|
|
|
bulkInfoSuccess({
|
|
|
|
statusBulkInfoList
|
|
|
|
})
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(bulkInfoFailure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
2019-10-11 16:40:55 +09:00
|
|
|
// statusNotification$ = createEffect(
|
|
|
|
// () => {
|
|
|
|
// return this.actions$.pipe(
|
|
|
|
// ofType(statusNotification),
|
|
|
|
// map(action => action.noti),
|
|
|
|
// tap(noti => {})
|
|
|
|
// );
|
|
|
|
// },
|
|
|
|
// { dispatch: false }
|
|
|
|
// );
|
2019-10-11 14:01:43 +09:00
|
|
|
|
2020-01-10 16:49:53 +09:00
|
|
|
status$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(status),
|
|
|
|
map(action => action.req),
|
|
|
|
exhaustMap(req => {
|
|
|
|
return this.statusProtocolService.status(req).pipe(
|
|
|
|
map((res: StatusResponse) => {
|
|
|
|
return statusSuccess({ res });
|
|
|
|
}),
|
|
|
|
catchError(error => of(statusFailure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-01-20 13:25:59 +09:00
|
|
|
messageUpdate$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(messageUpdate),
|
|
|
|
exhaustMap(action => {
|
|
|
|
return this.statusProtocolService.messageUpdate(action).pipe(
|
|
|
|
map((res: MessageUpdateResponse) => {
|
|
|
|
return AuthStore.updateStatusMessageSuccess({ res });
|
|
|
|
}),
|
|
|
|
catchError(error => of(messageUpdateFailure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-02-05 14:10:34 +09:00
|
|
|
myStatusCheck$ = createEffect(
|
|
|
|
() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(AuthStore.loginSuccess),
|
|
|
|
map(action => action.loginRes),
|
|
|
|
delay(5000),
|
|
|
|
tap(loginRes => {
|
|
|
|
this.store.dispatch(
|
|
|
|
bulkInfo({ divCd: 'mybulk', userSeqs: [loginRes.userSeq] })
|
|
|
|
);
|
|
|
|
// return bulkInfo({ divCd: 'bulk', userSeqs: [loginRes.userSeq] });
|
|
|
|
})
|
|
|
|
),
|
|
|
|
{ dispatch: false }
|
2020-01-31 18:00:18 +09:00
|
|
|
);
|
|
|
|
|
2020-03-27 15:01:03 +09:00
|
|
|
mroomUserStatusCheck$ = createEffect(
|
|
|
|
() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(RoomStore.infoSuccess),
|
|
|
|
map(action => action.userInfoList),
|
|
|
|
tap(userInfoList => {
|
|
|
|
if (!!userInfoList && userInfoList.length > 0) {
|
|
|
|
this.store.dispatch(
|
|
|
|
bulkInfo({
|
|
|
|
divCd: 'roomuserBulk',
|
|
|
|
userSeqs: userInfoList.map(userinfo => userinfo.seq)
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
),
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
2019-10-02 18:09:39 +09:00
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private store: Store<any>,
|
|
|
|
private statusProtocolService: StatusProtocolService,
|
|
|
|
private logger: NGXLogger
|
|
|
|
) {}
|
|
|
|
}
|