2019-10-08 11:19:47 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
|
|
|
|
2019-10-11 15:55:27 +09:00
|
|
|
import { Store, select } from '@ngrx/store';
|
2019-10-08 11:19:47 +09:00
|
|
|
|
|
|
|
import { NGXLogger } from 'ngx-logger';
|
|
|
|
|
|
|
|
import { of } from 'rxjs';
|
2019-10-11 15:55:27 +09:00
|
|
|
import {
|
|
|
|
tap,
|
|
|
|
switchMap,
|
|
|
|
map,
|
|
|
|
catchError,
|
|
|
|
exhaustMap,
|
|
|
|
withLatestFrom
|
|
|
|
} from 'rxjs/operators';
|
2019-10-08 11:19:47 +09:00
|
|
|
import {
|
|
|
|
RoomInfo,
|
|
|
|
UserInfoShort,
|
|
|
|
UserInfo,
|
|
|
|
RoomProtocolService,
|
|
|
|
SSVC_TYPE_ROOM_INFO_ROOM,
|
|
|
|
InfoData,
|
|
|
|
SSVC_TYPE_ROOM_INFO_USER,
|
|
|
|
SSVC_TYPE_ROOM_INFO_USER2,
|
|
|
|
SSVC_TYPE_ROOM_INFO_RES,
|
|
|
|
UserShortData,
|
2019-10-11 15:55:27 +09:00
|
|
|
UserData,
|
2019-10-16 14:53:53 +09:00
|
|
|
UpdateResponse,
|
2019-10-23 17:03:34 +09:00
|
|
|
OpenResponse,
|
|
|
|
ExitResponse
|
2019-10-08 11:19:47 +09:00
|
|
|
} from '@ucap-webmessenger/protocol-room';
|
|
|
|
|
|
|
|
import * as ChatStore from '@app/store/messenger/chat';
|
|
|
|
|
2019-10-11 14:01:43 +09:00
|
|
|
import {
|
|
|
|
info,
|
|
|
|
infoSuccess,
|
|
|
|
infoFailure,
|
|
|
|
inviteNotification,
|
|
|
|
exitNotification,
|
|
|
|
exitForcingNotification,
|
2019-10-11 15:55:27 +09:00
|
|
|
updateFontNotification,
|
|
|
|
updateOnlyAlarm,
|
|
|
|
update,
|
|
|
|
updateSuccess,
|
2019-10-16 14:53:53 +09:00
|
|
|
updateFailure,
|
|
|
|
open,
|
|
|
|
openSuccess,
|
2019-10-23 17:03:34 +09:00
|
|
|
openFailure,
|
|
|
|
exit,
|
|
|
|
exitSuccess,
|
|
|
|
exitFailure
|
2019-10-11 14:01:43 +09:00
|
|
|
} from './actions';
|
2019-10-08 11:19:47 +09:00
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
|
|
|
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
selectedRoomForInfo$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(ChatStore.selectedRoom),
|
|
|
|
map(action => {
|
|
|
|
const loginInfo = this.sessionStorageService.get<LoginInfo>(
|
|
|
|
KEY_LOGIN_INFO
|
|
|
|
);
|
|
|
|
return info({
|
|
|
|
roomSeq: action.roomSeq,
|
|
|
|
isDetail: true,
|
|
|
|
localeCode: loginInfo.localeCode
|
|
|
|
});
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
info$ = createEffect(
|
|
|
|
() => {
|
|
|
|
let roomInfo: RoomInfo;
|
|
|
|
let userInfoShortList: UserInfoShort[];
|
|
|
|
let userInfoList: UserInfo[];
|
|
|
|
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(info),
|
|
|
|
tap(() => {
|
|
|
|
roomInfo = null;
|
|
|
|
userInfoShortList = [];
|
|
|
|
userInfoList = [];
|
|
|
|
}),
|
|
|
|
switchMap(req => {
|
|
|
|
return this.roomProtocolService.info(req).pipe(
|
|
|
|
map(res => {
|
2019-10-10 12:14:01 +09:00
|
|
|
switch (res.SSVC_TYPE) {
|
2019-10-08 11:19:47 +09:00
|
|
|
case SSVC_TYPE_ROOM_INFO_ROOM:
|
|
|
|
roomInfo = (res as InfoData).roomInfo;
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_ROOM_INFO_USER:
|
|
|
|
userInfoShortList.push(...(res as UserShortData).userInfos);
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_ROOM_INFO_USER2:
|
|
|
|
userInfoList.push(...(res as UserData).userInfos);
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_ROOM_INFO_RES:
|
|
|
|
this.store.dispatch(
|
|
|
|
infoSuccess({
|
|
|
|
roomInfo,
|
|
|
|
userInfoShortList,
|
|
|
|
userInfoList
|
|
|
|
})
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(infoFailure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
2019-10-11 15:55:27 +09:00
|
|
|
update$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(update),
|
|
|
|
map(action => action.req),
|
|
|
|
exhaustMap(req => {
|
|
|
|
return this.roomProtocolService.update(req).pipe(
|
|
|
|
map((res: UpdateResponse) => {
|
|
|
|
return updateSuccess({ res });
|
|
|
|
}),
|
|
|
|
catchError(error => of(updateFailure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
updateOnlyAlarm$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(updateOnlyAlarm),
|
|
|
|
map(action => action.roomInfo),
|
|
|
|
map(roomInfo =>
|
|
|
|
update({
|
|
|
|
req: {
|
|
|
|
roomSeq: roomInfo.roomSeq,
|
2019-10-23 17:26:04 +09:00
|
|
|
roomName:
|
|
|
|
roomInfo.roomName.trim().length === 0
|
|
|
|
? ' '
|
|
|
|
: roomInfo.roomName.trim(),
|
2019-10-11 15:55:27 +09:00
|
|
|
receiveAlarm: !roomInfo.receiveAlarm,
|
|
|
|
syncAll: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-10-16 14:53:53 +09:00
|
|
|
open$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(open),
|
|
|
|
map(action => action.req),
|
|
|
|
exhaustMap(req => {
|
|
|
|
return this.roomProtocolService.open(req).pipe(
|
|
|
|
map((res: OpenResponse) => {
|
|
|
|
return openSuccess({ res });
|
|
|
|
}),
|
|
|
|
catchError(error => of(openFailure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
openSuccess$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(openSuccess),
|
|
|
|
map(action => {
|
|
|
|
return ChatStore.selectedRoom({ roomSeq: action.res.roomSeq });
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-10-23 17:03:34 +09:00
|
|
|
exit$ = createEffect(() =>
|
|
|
|
this.actions$.pipe(
|
|
|
|
ofType(exit),
|
2019-10-24 16:53:21 +09:00
|
|
|
withLatestFrom(
|
|
|
|
this.store.pipe(
|
|
|
|
select((state: any) => state.messenger.room.roomInfo as RoomInfo)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
exhaustMap(([req, roomInfo]) => {
|
2019-10-23 17:03:34 +09:00
|
|
|
return this.roomProtocolService.exit(req).pipe(
|
|
|
|
map((res: ExitResponse) => {
|
2019-10-24 16:53:21 +09:00
|
|
|
if (!!roomInfo && roomInfo.roomSeq === res.roomSeq) {
|
|
|
|
this.store.dispatch(ChatStore.clearSelectedRoom());
|
|
|
|
}
|
2019-10-23 17:03:34 +09:00
|
|
|
return exitSuccess({ res });
|
|
|
|
}),
|
|
|
|
catchError(error => of(exitFailure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-10-11 14:01:43 +09:00
|
|
|
inviteNotification$ = createEffect(
|
|
|
|
() => {
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(inviteNotification),
|
|
|
|
map(action => action.noti),
|
|
|
|
tap(noti => {})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
exitNotification$ = createEffect(
|
|
|
|
() => {
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(exitNotification),
|
|
|
|
map(action => action.noti),
|
|
|
|
tap(noti => {})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
exitForcingNotification$ = createEffect(
|
|
|
|
() => {
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(exitForcingNotification),
|
|
|
|
map(action => action.noti),
|
|
|
|
tap(noti => {})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
updateFontNotification$ = createEffect(
|
|
|
|
() => {
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(updateFontNotification),
|
|
|
|
map(action => action.noti),
|
|
|
|
tap(noti => {})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
2019-10-08 11:19:47 +09:00
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private store: Store<any>,
|
|
|
|
private roomProtocolService: RoomProtocolService,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
|
|
|
private logger: NGXLogger
|
|
|
|
) {}
|
|
|
|
}
|