This commit is contained in:
병준 박 2019-10-16 15:01:16 +09:00
commit 230e824003
11 changed files with 259 additions and 75 deletions

View File

@ -39,7 +39,11 @@ export class ChatComponent implements OnInit, OnDestroy {
private store: Store<any>,
private logger: NGXLogger,
private sessionStorageService: SessionStorageService
) {}
) {
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
KEY_VER_INFO
);
}
ngOnInit() {
this.roomSubscription = combineLatest([

View File

@ -61,7 +61,9 @@ export class GroupComponent implements OnInit, OnDestroy {
loginRes: LoginResponse;
loginResSubscription: Subscription;
sessionVerinfo: VersionInfo2Response;
sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
KEY_VER_INFO
);
constructor(
private store: Store<any>,
@ -72,9 +74,6 @@ export class GroupComponent implements OnInit, OnDestroy {
ngOnInit() {
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
this.sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
KEY_VER_INFO
);
this.companyCode = loginInfo.companyCode;
this.loginResSubscription = this.store

View File

@ -9,7 +9,7 @@
</div>
<div>
<ucap-profile-user-list-item *ngFor="let userInfo of selectedDepartmentUserInfoList$ | async"
[userInfo]="userInfo" [checkable]="true">
[userInfo]="userInfo" [checkable]="true" [sessionVerinfo]="sessionVerinfo">
</ucap-profile-user-list-item>
</div>
<div>

View File

@ -16,6 +16,8 @@ import * as QueryStore from '@app/store/messenger/query';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
import { take, map, switchMap } from 'rxjs/operators';
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
import { KEY_VER_INFO } from '@app/types/ver-info.type';
@Component({
selector: 'app-layout-chat-left-sidenav-organization',
@ -29,6 +31,9 @@ export class OrganizationComponent implements OnInit {
selectedDepartmentStatus$: Observable<DeptUserResponse>;
loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
sessionVerinfo = this.sessionStorageService.get<VersionInfo2Response>(
KEY_VER_INFO
);
constructor(
private store: Store<any>,

View File

@ -42,7 +42,9 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewChecked {
roomInfoSubscription: Subscription;
userInfoList$: Observable<UserInfo[]>;
eventListProcessing$: Observable<boolean>;
sessionVerInfo: VersionInfo2Response;
sessionVerInfo = this.sessionStorageService.get<VersionInfo2Response>(
KEY_VER_INFO
);
constructor(
private store: Store<any>,
@ -52,9 +54,6 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewChecked {
ngOnInit() {
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
this.sessionVerInfo = this.sessionStorageService.get<VersionInfo2Response>(
KEY_VER_INFO
);
this.loginResSubscription = this.store
.pipe(

View File

@ -8,7 +8,8 @@ import {
SendNotification,
ReadNotification,
CancelNotification,
DelNotification
DelNotification,
ReadRequest
} from '@ucap-webmessenger/protocol-event';
export const info = createAction(
@ -69,6 +70,24 @@ export const sendFailure = createAction(
props<{ error: any }>()
);
export const read = createAction(
'[Messenger::Event] read',
props<ReadRequest>()
);
export const readSuccess = createAction(
'[Messenger::Event] read Success',
props<{
infoList: Info[];
res: InfoResponse;
}>()
);
export const readFailure = createAction(
'[Messenger::Event] read Failure',
props<{ error: any }>()
);
export const sendNotification = createAction(
'[Messenger::Event] Send Notification',
props<{ noti: SendNotification }>()

View File

@ -22,10 +22,12 @@ import {
EventProtocolService,
SSVC_TYPE_EVENT_INFO_DATA,
SSVC_TYPE_EVENT_INFO_RES,
SendResponse
SendResponse,
ReadResponse
} from '@ucap-webmessenger/protocol-event';
import * as ChatStore from '@app/store/messenger/chat';
import * as SyncStore from '@app/store/messenger/sync';
import {
info,
@ -40,10 +42,15 @@ import {
readNotification,
cancelNotification,
delNotification,
recallInfoList
recallInfoList,
read,
readFailure
} from './actions';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import { RoomInfo } from '@ucap-webmessenger/protocol-room';
import { refreshRoom } from '../sync';
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
import { Dictionary } from '@ngrx/entity';
@Injectable()
export class Effects {
@ -77,12 +84,28 @@ export class Effects {
infoList.push(...(res as InfoData).infoList);
break;
case SSVC_TYPE_EVENT_INFO_RES:
this.store.dispatch(
infoSuccess({
infoList,
res: res as InfoResponse
})
);
{
this.store.dispatch(
infoSuccess({
infoList,
res: res as InfoResponse
})
);
if (req.baseSeq === 0) {
// 최초 이벤트 목록 조회시 SSVC_TYPE_EVENT_READ_REQ 수행.
const maxSeq = Math.max.apply(
Math,
infoList.map(v => v.seq)
);
this.store.dispatch(
read({
roomSeq: req.roomSeq,
lastReadSeq: Number(maxSeq)
})
);
}
}
break;
}
}),
@ -94,6 +117,28 @@ export class Effects {
{ dispatch: false }
);
read$ = createEffect(
() => {
return this.actions$.pipe(
ofType(read),
switchMap(req => {
return this.eventProtocolService.read(req).pipe(
map((res: ReadResponse) => {
this.store.dispatch(
SyncStore.updateUnreadCount({
roomSeq: res.roomSeq,
noReadCnt: 0
})
);
}),
catchError(error => of(readFailure({ error })))
);
})
);
},
{ dispatch: false }
);
send$ = createEffect(() =>
this.actions$.pipe(
ofType(send),
@ -166,13 +211,32 @@ export class Effects {
withLatestFrom(
this.store.pipe(
select((state: any) => state.messenger.room.roomInfo as RoomInfo)
),
this.store.pipe(
select(
(state: any) =>
state.messenger.sync.room.entities as Dictionary<RoomInfo>
)
)
),
tap(([action, roomInfo]) => {
tap(([action, roomInfo, trgtRoomInfos]) => {
// opened room :: event add
if (!!roomInfo && roomInfo.roomSeq === action.roomSeq) {
this.store.dispatch(appendInfoList({ info: action.info }));
}
// not opened room :: unread count increased
if (!roomInfo || roomInfo.roomSeq !== action.roomSeq) {
const noReadCnt = trgtRoomInfos[action.roomSeq].noReadCnt;
this.store.dispatch(
SyncStore.updateUnreadCount({
roomSeq: action.roomSeq,
noReadCnt: noReadCnt + 1
})
);
}
// 대화 > 리스트 :: finalEventMessage refresh
this.store.dispatch(ChatStore.newEventMessage(action));
})
);
@ -201,13 +265,24 @@ export class Effects {
)
),
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));
}
// 대화 > 리스트의 항목 갱신
const loginInfo = this.sessionStorageService.get<LoginInfo>(
KEY_LOGIN_INFO
);
this.store.dispatch(
SyncStore.refreshRoom({
roomSeq: action.noti.roomSeq,
isDetail: true,
localeCode: loginInfo.localeCode
})
);
})
);
},

View File

@ -10,7 +10,8 @@ import {
import {
RoomInfo,
UserInfoShort,
UserInfo as RoomUserInfo
UserInfo as RoomUserInfo,
InfoRequest
} from '@ucap-webmessenger/protocol-room';
import { Info } from '@ucap-webmessenger/protocol-event';
@ -75,3 +76,28 @@ export const updateRoomForNewEventMessage = createAction(
info: Info;
}>()
);
export const refreshRoom = createAction(
'[Messenger::Sync] refresh room in sync',
props<InfoRequest>()
);
export const refreshRoomSuccess = createAction(
'[Messenger::Sync] refresh room in sync Success',
props<{
roomInfo: RoomInfo;
userInfoShortList: UserInfoShort[];
userInfoList: RoomUserInfo[];
}>()
);
export const refreshRoomFailure = createAction(
'[Messenger::Sync] refresh room in sync Failure',
props<{ error: any }>()
);
export const updateUnreadCount = createAction(
'[Messenger::Sync] Update unread count',
props<{
roomSeq: string;
noReadCnt?: number;
}>()
);

View File

@ -26,7 +26,10 @@ import {
room,
roomFailure,
roomSuccess,
updateRoomForNewEventMessage
updateRoomForNewEventMessage,
refreshRoom,
refreshRoomFailure,
refreshRoomSuccess
} from './actions';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
@ -54,7 +57,15 @@ import { regViewSuccess } from '@app/store/messenger/option';
import {
RoomInfo,
UserInfoShort,
UserInfo as RoomUserInfo
UserInfo as RoomUserInfo,
RoomProtocolService,
SSVC_TYPE_ROOM_INFO_ROOM,
SSVC_TYPE_ROOM_INFO_USER,
SSVC_TYPE_ROOM_INFO_USER2,
InfoData,
UserShortData,
UserData,
SSVC_TYPE_ROOM_INFO_RES
} from '@ucap-webmessenger/protocol-room';
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
@ -328,10 +339,56 @@ export class Effects {
{ dispatch: false }
);
refreshRoom$ = createEffect(
() => {
let roomInfo: RoomInfo;
let userInfoShortList: UserInfoShort[];
let userInfoList: RoomUserInfo[];
return this.actions$.pipe(
ofType(refreshRoom),
tap(() => {
roomInfo = null;
userInfoShortList = [];
userInfoList = [];
}),
switchMap(req => {
return this.roomProtocolService.info(req).pipe(
map(res => {
switch (res.SSVC_TYPE) {
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(
refreshRoomSuccess({
roomInfo,
userInfoShortList,
userInfoList
})
);
break;
}
}),
catchError(error => of(refreshRoomFailure({ error })))
);
})
);
},
{ dispatch: false }
);
constructor(
private actions$: Actions,
private store: Store<any>,
private syncProtocolService: SyncProtocolService,
private roomProtocolService: RoomProtocolService,
private sessionStorageService: SessionStorageService,
private logger: NGXLogger
) {}

View File

@ -11,7 +11,9 @@ import {
buddy2Success,
group2Success,
roomSuccess,
updateRoomForNewEventMessage
updateRoomForNewEventMessage,
refreshRoomSuccess,
updateUnreadCount
} from './actions';
import {
RoomUserDetailData,
@ -113,6 +115,52 @@ export const reducer = createReducer(
};
}),
on(refreshRoomSuccess, (state, action) => {
const roomUserList: RoomUserDetailData[] = [];
const roomUserShortList: RoomUserData[] = [];
if (action.userInfoList) {
roomUserList.push({
roomSeq: action.roomInfo.roomSeq,
userInfos: action.userInfoList
});
}
if (action.userInfoShortList) {
roomUserShortList.push({
roomSeq: action.roomInfo.roomSeq,
userInfos: action.userInfoShortList
});
}
return {
...state,
room: adapterRoom.upsertOne(action.roomInfo, {
...state.room
}),
roomUser: adapterRoomUser.upsertMany(roomUserList, {
...state.roomUser
}),
roomUserShort: adapterRoomUserShort.upsertMany(roomUserShortList, {
...state.roomUserShort
})
};
}),
on(updateUnreadCount, (state, action) => {
const roomInfo: RoomInfo = {
...state.room.entities[action.roomSeq],
noReadCnt: action.noReadCnt
};
return {
...state,
room: adapterRoom.updateOne(
{ id: action.roomSeq, changes: roomInfo },
{ ...state.room }
)
};
}),
on(AuthenticationStore.logout, (state, action) => {
return {
...initialState

View File

@ -8,11 +8,7 @@ import {
import { NGXLogger } from 'ngx-logger';
import { VersionInfo2Response } from '@ucap-webmessenger/api-public';
import { EventType } from '@ucap-webmessenger/protocol-event';
import {
FileInfo,
StickerInfo,
MassTextInfo
} from '@ucap-webmessenger/ui-chat';
import { FileInfo, StickerInfo } from '@ucap-webmessenger/ui-chat';
import { FileType } from '@ucap-webmessenger/protocol-file';
import {
LoginResponse,
@ -43,51 +39,7 @@ export class ListItemComponent implements OnInit {
if (this.roomInfo.isTimeRoom) {
this.finalEventMessage = '비밀 대화방입니다.';
} else {
try {
switch (this.roomInfo.finalEventType) {
case EventType.File:
{
let msg = 'Attach File';
const contentJson: FileInfo = JSON.parse(
this.roomInfo.finalEventMessage
);
if (contentJson.FileType === FileType.File) {
msg = '첨부파일';
} else if (contentJson.FileType === FileType.Image) {
msg = '이미지';
} else if (contentJson.FileType === FileType.Video) {
msg = '동영상';
}
this.finalEventMessage = msg;
}
break;
case EventType.Sticker:
{
let msg = '스티커';
const contentJson: StickerInfo = JSON.parse(
this.roomInfo.finalEventMessage
);
if (contentJson.chat) {
msg += ' ' + contentJson.chat;
}
this.finalEventMessage = msg;
}
break;
case EventType.MassText:
{
const contentJson: MassTextInfo = JSON.parse(
this.roomInfo.finalEventMessage
);
this.finalEventMessage = contentJson.Content;
}
break;
default:
this.finalEventMessage = this.roomInfo.finalEventMessage;
}
} catch (e) {
this.logger.error(e);
this.finalEventMessage = this.roomInfo.finalEventMessage;
}
this.finalEventMessage = this.roomInfo.finalEventMessage;
}
}