diff --git a/package-lock.json b/package-lock.json index 12eb79f..5bbe8a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2378,13 +2378,13 @@ "dev": true }, "@ucap/ng-store-chat": { - "version": "file:pack/ucap-ng-store-chat-0.0.3.tgz", - "integrity": "sha512-T2MfjHqvP4J1fHJHVE3Mq/CYUnXZh+Uge8hUqDlX5V+KoaH5LUxz56/jX4OCpbwis1Uez+LxeG15IwuYMKZdvg==", - "dev": true + "version": "file:pack/ucap-ng-store-chat-0.0.4.tgz", + "integrity": "sha512-rSZirwFUMv9zXllqBWpdSUbUuRz9j1O8BVIfselp9sZHdKl7Xcx9irqNnHHkF2bJpxeWzugGrgG02tdt/xrIuQ==" }, "@ucap/ng-store-group": { "version": "file:pack/ucap-ng-store-group-0.0.5.tgz", - "integrity": "sha512-NNqnSiyQWbBIWLjXsBBxkdCHlRkMPRF8+IXq7scUgG7aNlUA0SGuntUbghRPxAJLQNuMe/csQziOlqHn98sJfw==" + "integrity": "sha512-NNqnSiyQWbBIWLjXsBBxkdCHlRkMPRF8+IXq7scUgG7aNlUA0SGuntUbghRPxAJLQNuMe/csQziOlqHn98sJfw==", + "dev": true }, "@ucap/ng-store-organization": { "version": "file:pack/ucap-ng-store-organization-0.0.3.tgz", diff --git a/package.json b/package.json index 3f0909f..2ee3d9c 100644 --- a/package.json +++ b/package.json @@ -166,7 +166,7 @@ "@ucap/ng-protocol-sync": "file:pack/ucap-ng-protocol-sync-0.0.1.tgz", "@ucap/ng-protocol-umg": "file:pack/ucap-ng-protocol-umg-0.0.1.tgz", "@ucap/ng-store-authentication": "file:pack/ucap-ng-store-authentication-0.0.4.tgz", - "@ucap/ng-store-chat": "file:pack/ucap-ng-store-chat-0.0.3.tgz", + "@ucap/ng-store-chat": "file:pack/ucap-ng-store-chat-0.0.4.tgz", "@ucap/ng-store-group": "file:pack/ucap-ng-store-group-0.0.5.tgz", "@ucap/ng-store-organization": "file:pack/ucap-ng-store-organization-0.0.3.tgz", "@ucap/ng-ui": "file:pack/ucap-ng-ui-0.0.3.tgz", diff --git a/projects/store-chat/ng-package.json b/projects/store-chat/ng-package.json index 4b5b5a0..9b1f32c 100644 --- a/projects/store-chat/ng-package.json +++ b/projects/store-chat/ng-package.json @@ -14,7 +14,8 @@ "@ucap/protocol-room": "@ucap/protocol-room", "@ucap/protocol-sync": "@ucap/protocol-sync", "@ucap/ng-protocol-room": "@ucap/ng-protocol-room", - "@ucap/ng-protocol-sync": "@ucap/ng-protocol-sync" + "@ucap/ng-protocol-sync": "@ucap/ng-protocol-sync", + "@ucap/ng-store-authentication": "@ucap/ng-store-authentication" } } } diff --git a/projects/store-chat/package.json b/projects/store-chat/package.json index 13cf64c..0296dd9 100644 --- a/projects/store-chat/package.json +++ b/projects/store-chat/package.json @@ -1,6 +1,6 @@ { "name": "@ucap/ng-store-chat", - "version": "0.0.3", + "version": "0.0.4", "publishConfig": { "registry": "http://10.81.13.221:8081/nexus/repository/npm-ucap/" }, @@ -14,6 +14,7 @@ "@ucap/protocol-sync": "~0.0.1", "@ucap/ng-protocol-room": "~0.0.1", "@ucap/ng-protocol-sync": "~0.0.1", + "@ucap/ng-store-authentication": "~0.0.1", "tslib": "^1.10.0" } } diff --git a/projects/store-chat/src/lib/store/room/actions.ts b/projects/store-chat/src/lib/store/room/actions.ts index 88056cf..b15f6c7 100644 --- a/projects/store-chat/src/lib/store/room/actions.ts +++ b/projects/store-chat/src/lib/store/room/actions.ts @@ -2,7 +2,6 @@ import { createAction, props } from '@ngrx/store'; import { LocaleCode } from '@ucap/core'; -import { RoomRequest as RoomsRequest } from '@ucap/protocol-sync'; import { RoomInfo, UserInfo as RoomUserInfo, @@ -29,7 +28,7 @@ import { */ export const rooms = createAction( '[ucap::chat::room] rooms', - props<{ req: RoomsRequest }>() + props<{ localeCode: LocaleCode }>() ); /** * Success of rooms request diff --git a/projects/store-chat/src/lib/store/room/effects.ts b/projects/store-chat/src/lib/store/room/effects.ts index a1be1c4..f167361 100644 --- a/projects/store-chat/src/lib/store/room/effects.ts +++ b/projects/store-chat/src/lib/store/room/effects.ts @@ -1,8 +1,15 @@ import { of } from 'rxjs'; -import { catchError, map, switchMap, exhaustMap } from 'rxjs/operators'; +import { + catchError, + map, + switchMap, + exhaustMap, + withLatestFrom +} from 'rxjs/operators'; import { Injectable } from '@angular/core'; +import { Store, select } from '@ngrx/store'; import { Actions, ofType, createEffect } from '@ngrx/effects'; import { @@ -20,6 +27,10 @@ import { RoomProtocolService } from '@ucap/ng-protocol-room'; import { SyncProtocolService } from '@ucap/ng-protocol-sync'; +import { LoginActions } from '@ucap/ng-store-authentication'; + +import { RoomSelector } from '../state'; + import { rooms, roomsFailure, @@ -61,21 +72,30 @@ import { @Injectable() export class Effects { + postLoginSuccessForRooms$ = createEffect(() => { + return this.actions$.pipe( + ofType(LoginActions.loginSuccess), + map(action => rooms({ localeCode: action.loginSession.localeCode })) + ); + }); + rooms$ = createEffect(() => { return this.actions$.pipe( ofType(rooms), - map(action => action.req), - switchMap(req => { - return this.syncProtocolService.room(req).pipe( - map(res => - roomsSuccess({ - roomList: res.roomList, - roomUserInfoMap: res.roomUserInfoMap, - syncDate: res.res.syncDate - }) - ), - catchError(error => of(roomsFailure({ error }))) - ); + withLatestFrom(this.store.pipe(select(RoomSelector.roomsSyncDate))), + switchMap(([action, syncDate]) => { + return this.syncProtocolService + .room({ syncDate, localeCode: action.localeCode }) + .pipe( + map(res => + roomsSuccess({ + roomList: res.roomList, + roomUserInfoMap: res.roomUserInfoMap, + syncDate: res.res.syncDate + }) + ), + catchError(error => of(roomsFailure({ error }))) + ); }) ); }); @@ -308,6 +328,7 @@ export class Effects { constructor( private actions$: Actions, + private store: Store, private syncProtocolService: SyncProtocolService, private roomProtocolService: RoomProtocolService ) {}