2019-09-25 17:26:19 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
import { Actions, ofType, createEffect } from '@ngrx/effects';
|
|
|
|
|
|
|
|
import { of } from 'rxjs';
|
2019-10-02 14:34:17 +09:00
|
|
|
import {
|
|
|
|
catchError,
|
|
|
|
exhaustMap,
|
|
|
|
map,
|
|
|
|
withLatestFrom,
|
|
|
|
switchMap,
|
|
|
|
tap
|
|
|
|
} from 'rxjs/operators';
|
2019-09-25 17:26:19 +09:00
|
|
|
|
2019-09-25 18:08:50 +09:00
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
|
2019-09-26 11:11:22 +09:00
|
|
|
import { NGXLogger } from 'ngx-logger';
|
|
|
|
|
2019-09-25 18:08:50 +09:00
|
|
|
import {
|
|
|
|
buddy2,
|
|
|
|
buddy2Success,
|
|
|
|
buddy2Failure,
|
|
|
|
group2,
|
|
|
|
group2Success,
|
2019-10-02 14:34:17 +09:00
|
|
|
group2Failure
|
2019-09-25 18:08:50 +09:00
|
|
|
} from './actions';
|
2019-09-25 17:26:19 +09:00
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
|
|
|
|
import {
|
|
|
|
SyncProtocolService,
|
|
|
|
SSVC_TYPE_SYNC_BUDDY2_DATA,
|
|
|
|
BuddyResponse,
|
2019-09-25 18:08:50 +09:00
|
|
|
BuddyDetailData,
|
|
|
|
SSVC_TYPE_SYNC_GROUP_DATA2,
|
|
|
|
GroupDetailData,
|
2019-10-02 14:34:17 +09:00
|
|
|
GroupResponse,
|
|
|
|
UserInfo,
|
|
|
|
SSVC_TYPE_SYNC_BUDDY2_RES,
|
|
|
|
SSVC_TYPE_SYNC_GROUP_RES2
|
2019-09-25 17:26:19 +09:00
|
|
|
} from '@ucap-webmessenger/protocol-sync';
|
|
|
|
import { regViewSuccess } from '@app/store/setting/option';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
2019-10-02 14:34:17 +09:00
|
|
|
buddy2$ = createEffect(
|
|
|
|
() => {
|
|
|
|
let buddyList: UserInfo[];
|
2019-09-25 17:26:19 +09:00
|
|
|
|
2019-10-02 14:34:17 +09:00
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(buddy2),
|
|
|
|
tap(() => {
|
|
|
|
buddyList = [];
|
|
|
|
}),
|
|
|
|
switchMap(req => {
|
|
|
|
return this.syncProtocolService.buddy2(req).pipe(
|
|
|
|
map(res => {
|
|
|
|
switch (res.Type) {
|
|
|
|
case SSVC_TYPE_SYNC_BUDDY2_DATA:
|
|
|
|
buddyList.push(...(res as BuddyDetailData).buddyInfos);
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_SYNC_BUDDY2_RES:
|
|
|
|
this.store.dispatch(
|
|
|
|
buddy2Success({
|
|
|
|
buddyList,
|
|
|
|
syncDate: (res as BuddyResponse).syncDate
|
|
|
|
})
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(buddy2Failure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
2019-09-25 18:08:50 +09:00
|
|
|
);
|
|
|
|
|
2019-10-02 14:34:17 +09:00
|
|
|
group2$ = createEffect(
|
|
|
|
() => {
|
|
|
|
let groupList: GroupDetailData[];
|
2019-09-25 18:08:50 +09:00
|
|
|
|
2019-10-02 14:34:17 +09:00
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(group2),
|
|
|
|
tap(() => {
|
|
|
|
groupList = [];
|
|
|
|
}),
|
|
|
|
switchMap(req => {
|
|
|
|
return this.syncProtocolService.group2(req).pipe(
|
|
|
|
map(res => {
|
|
|
|
switch (res.Type) {
|
|
|
|
case SSVC_TYPE_SYNC_GROUP_DATA2:
|
|
|
|
groupList.push(res as GroupDetailData);
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_SYNC_GROUP_RES2:
|
|
|
|
this.store.dispatch(
|
|
|
|
group2Success({
|
|
|
|
groupList,
|
|
|
|
syncDate: (res as GroupResponse).syncDate
|
|
|
|
})
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(group2Failure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
2019-09-25 18:08:50 +09:00
|
|
|
);
|
|
|
|
|
2019-09-25 17:26:19 +09:00
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
2019-09-25 18:08:50 +09:00
|
|
|
private store: Store<any>,
|
2019-09-25 17:26:19 +09:00
|
|
|
private syncProtocolService: SyncProtocolService,
|
2019-09-26 11:11:22 +09:00
|
|
|
private sessionStorageService: SessionStorageService,
|
|
|
|
private logger: NGXLogger
|
2019-09-25 17:26:19 +09:00
|
|
|
) {}
|
|
|
|
}
|