2019-09-19 09:22:13 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
2019-10-08 07:15:36 +00:00
|
|
|
import { tap } from 'rxjs/operators';
|
2019-09-19 09:22:13 +00:00
|
|
|
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
|
|
|
import {
|
|
|
|
SSVC_TYPE_LOGOUT_RES,
|
|
|
|
SSVC_TYPE_LOGOUT_REMOTE_NOTI,
|
2019-10-08 07:15:36 +00:00
|
|
|
AuthenticationProtocolService,
|
|
|
|
LogoutResponse,
|
|
|
|
LogoutRemoteNotification
|
2019-09-19 09:22:13 +00:00
|
|
|
} from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
|
2019-09-26 02:11:22 +00:00
|
|
|
import { NGXLogger } from 'ngx-logger';
|
2019-10-10 01:43:06 +00:00
|
|
|
import {
|
|
|
|
EventProtocolService,
|
|
|
|
SSVC_TYPE_EVENT_SEND_NOTI,
|
|
|
|
SendNotification,
|
|
|
|
SSVC_TYPE_EVENT_READ_NOTI,
|
|
|
|
SSVC_TYPE_EVENT_CANCEL_NOTI,
|
2019-10-10 04:35:32 +00:00
|
|
|
SSVC_TYPE_EVENT_DEL_RES,
|
2019-10-29 01:10:08 +00:00
|
|
|
Info,
|
|
|
|
SSVC_TYPE_EVENT_SEND_RES,
|
|
|
|
SSVC_TYPE_EVENT_READ_RES
|
2019-10-10 01:43:06 +00:00
|
|
|
} from '@ucap-webmessenger/protocol-event';
|
|
|
|
import {
|
|
|
|
InfoProtocolService,
|
|
|
|
SSVC_TYPE_INFO_USER_NOTI,
|
|
|
|
UserNotification
|
|
|
|
} from '@ucap-webmessenger/protocol-info';
|
|
|
|
import {
|
|
|
|
RoomProtocolService,
|
|
|
|
SSVC_TYPE_ROOM_INVITE_NOTI,
|
|
|
|
SSVC_TYPE_ROOM_EXIT_NOTI,
|
|
|
|
SSVC_TYPE_ROOM_EXIT_FORCING_NOTI,
|
|
|
|
SSVC_TYPE_ROOM_FONT_UPD_NOTI,
|
|
|
|
InviteNotification
|
|
|
|
} from '@ucap-webmessenger/protocol-room';
|
|
|
|
import {
|
|
|
|
StatusProtocolService,
|
|
|
|
SSVC_TYPE_STATUS_NOTI,
|
|
|
|
StatusNotification
|
|
|
|
} from '@ucap-webmessenger/protocol-status';
|
|
|
|
import {
|
|
|
|
ReadNotification,
|
|
|
|
CancelNotification,
|
|
|
|
DelNotification
|
|
|
|
} from '@ucap-webmessenger/protocol-event';
|
|
|
|
import {
|
|
|
|
ExitNotification,
|
|
|
|
ExitForcingNotification,
|
|
|
|
UpdateFontNotification
|
|
|
|
} from '@ucap-webmessenger/protocol-room';
|
2019-09-19 09:22:13 +00:00
|
|
|
|
2019-10-11 07:40:55 +00:00
|
|
|
import * as AuthenticationStore from '@app/store/account/authentication';
|
|
|
|
import * as InfoStore from '@app/store/account/info';
|
|
|
|
import * as EventStore from '@app/store/messenger/event';
|
|
|
|
import * as RoomStore from '@app/store/messenger/room';
|
|
|
|
import * as StatusStore from '@app/store/messenger/status';
|
|
|
|
|
2019-09-19 09:22:13 +00:00
|
|
|
@Injectable()
|
|
|
|
export class AppNotificationService {
|
|
|
|
constructor(
|
2019-10-08 07:15:36 +00:00
|
|
|
private authenticationProtocolService: AuthenticationProtocolService,
|
2019-10-10 01:43:06 +00:00
|
|
|
private eventProtocolService: EventProtocolService,
|
|
|
|
private infoProtocolService: InfoProtocolService,
|
|
|
|
private roomProtocolService: RoomProtocolService,
|
|
|
|
private statusProtocolService: StatusProtocolService,
|
2019-09-26 02:11:22 +00:00
|
|
|
private store: Store<any>,
|
|
|
|
private logger: NGXLogger
|
2019-09-19 09:22:13 +00:00
|
|
|
) {}
|
|
|
|
|
|
|
|
public subscribe(): void {
|
2019-10-08 07:15:36 +00:00
|
|
|
this.authenticationProtocolService.logoutNotification$
|
2019-09-19 09:22:13 +00:00
|
|
|
.pipe(
|
2019-10-08 07:15:36 +00:00
|
|
|
tap(notiOrRes => {
|
2019-10-10 03:14:01 +00:00
|
|
|
switch (notiOrRes.SSVC_TYPE) {
|
2019-10-08 07:15:36 +00:00
|
|
|
case SSVC_TYPE_LOGOUT_RES:
|
|
|
|
{
|
|
|
|
const res = notiOrRes as LogoutResponse;
|
2019-10-10 01:43:06 +00:00
|
|
|
this.logger.debug(
|
|
|
|
'Notification::authenticationProtocolService::LogoutResponse',
|
|
|
|
res
|
|
|
|
);
|
2019-10-08 07:15:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_LOGOUT_REMOTE_NOTI:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as LogoutRemoteNotification;
|
2019-10-10 01:43:06 +00:00
|
|
|
this.logger.debug(
|
|
|
|
'Notification::authenticationProtocolService::LogoutRemoteNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-08 07:15:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-09-19 09:22:13 +00:00
|
|
|
this.store.dispatch(AuthenticationStore.logout());
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-10-10 01:43:06 +00:00
|
|
|
|
|
|
|
this.eventProtocolService.notification$
|
|
|
|
.pipe(
|
|
|
|
tap(notiOrRes => {
|
2019-10-10 03:14:01 +00:00
|
|
|
switch (notiOrRes.SSVC_TYPE) {
|
2019-10-29 01:10:08 +00:00
|
|
|
case SSVC_TYPE_EVENT_SEND_RES:
|
2019-10-10 01:43:06 +00:00
|
|
|
case SSVC_TYPE_EVENT_SEND_NOTI:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as SendNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::eventProtocolService::SendNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-10 04:35:32 +00:00
|
|
|
|
|
|
|
this.store.dispatch(
|
2019-10-11 05:01:43 +00:00
|
|
|
EventStore.sendNotification({
|
|
|
|
noti
|
2019-10-10 04:35:32 +00:00
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-10-29 01:10:08 +00:00
|
|
|
case SSVC_TYPE_EVENT_READ_RES:
|
2019-10-10 01:43:06 +00:00
|
|
|
case SSVC_TYPE_EVENT_READ_NOTI:
|
|
|
|
{
|
2019-10-10 03:14:01 +00:00
|
|
|
// 대화방 unread count 처리.
|
2019-10-10 01:43:06 +00:00
|
|
|
const noti = notiOrRes as ReadNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::eventProtocolService::ReadNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-11 05:01:43 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
EventStore.readNotification({
|
|
|
|
noti
|
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_EVENT_CANCEL_NOTI:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as CancelNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::eventProtocolService::CancelNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-11 05:01:43 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
EventStore.cancelNotification({
|
|
|
|
noti
|
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_EVENT_DEL_RES:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as DelNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::eventProtocolService::DelNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-11 05:01:43 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
EventStore.delNotification({
|
|
|
|
noti
|
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
this.infoProtocolService.notification$
|
|
|
|
.pipe(
|
|
|
|
tap(notiOrRes => {
|
2019-10-10 03:14:01 +00:00
|
|
|
switch (notiOrRes.SSVC_TYPE) {
|
2019-10-10 01:43:06 +00:00
|
|
|
case SSVC_TYPE_INFO_USER_NOTI:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as UserNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::infoProtocolService::UserNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-11 07:40:55 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
InfoStore.userNotification({
|
|
|
|
noti
|
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
this.roomProtocolService.notification$
|
|
|
|
.pipe(
|
|
|
|
tap(notiOrRes => {
|
2019-10-10 03:14:01 +00:00
|
|
|
switch (notiOrRes.SSVC_TYPE) {
|
2019-10-10 01:43:06 +00:00
|
|
|
case SSVC_TYPE_ROOM_INVITE_NOTI:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as InviteNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::roomProtocolService::InviteNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-11 07:40:55 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
RoomStore.inviteNotification({
|
|
|
|
noti
|
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_ROOM_EXIT_NOTI:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as ExitNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::roomProtocolService::ExitNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-11 07:40:55 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
RoomStore.exitNotification({
|
|
|
|
noti
|
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_ROOM_EXIT_FORCING_NOTI:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as ExitForcingNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::roomProtocolService::ExitForcingNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-11 07:40:55 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
RoomStore.exitForcingNotification({
|
|
|
|
noti
|
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_ROOM_FONT_UPD_NOTI:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as UpdateFontNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::roomProtocolService::UpdateFontNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-11 07:40:55 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
RoomStore.updateFontNotification({
|
|
|
|
noti
|
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
this.statusProtocolService.notification$
|
|
|
|
.pipe(
|
|
|
|
tap(notiOrRes => {
|
2019-10-10 03:14:01 +00:00
|
|
|
switch (notiOrRes.SSVC_TYPE) {
|
2019-10-10 01:43:06 +00:00
|
|
|
case SSVC_TYPE_STATUS_NOTI:
|
|
|
|
{
|
|
|
|
const noti = notiOrRes as StatusNotification;
|
|
|
|
this.logger.debug(
|
|
|
|
'Notification::statusProtocolService::StatusNotification',
|
|
|
|
noti
|
|
|
|
);
|
2019-10-11 07:40:55 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
StatusStore.statusNotification({
|
|
|
|
noti
|
|
|
|
})
|
|
|
|
);
|
2019-10-10 01:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
2019-09-19 09:22:13 +00:00
|
|
|
}
|
|
|
|
}
|