From 817efad9dfdd76fcf80a1e55b73feedfa0dbe85c Mon Sep 17 00:00:00 2001 From: Richard Park Date: Thu, 10 Oct 2019 10:43:06 +0900 Subject: [PATCH] Notification is implemented --- .../components/main.page.component.html | 2 +- .../src/app/services/notification.service.ts | 181 +++++++++++++++++- .../authentication-protocol.service.ts | 10 +- .../lib/services/event-protocol.service.ts | 56 +++++- .../src/public-api.ts | 8 +- .../src/lib/services/info-protocol.service.ts | 42 +++- .../src/lib/services/room-protocol.service.ts | 83 +++++++- .../src/public-api.ts | 3 + .../lib/services/status-protocol.service.ts | 42 +++- 9 files changed, 390 insertions(+), 37 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/pages/messenger/components/main.page.component.html b/projects/ucap-webmessenger-app/src/app/pages/messenger/components/main.page.component.html index e1c2a904..5b0e9a0d 100644 --- a/projects/ucap-webmessenger-app/src/app/pages/messenger/components/main.page.component.html +++ b/projects/ucap-webmessenger-app/src/app/pages/messenger/components/main.page.component.html @@ -13,7 +13,7 @@ > -

sidenav

+

Auto-resizing sidenav

diff --git a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts index 474bbdb3..4a1e460c 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -12,13 +12,53 @@ import { LogoutRemoteNotification } from '@ucap-webmessenger/protocol-authentication'; -import * as AuthenticationStore from '../store/account/authentication'; +import * as AuthenticationStore from '@app/store/account/authentication'; import { NGXLogger } from 'ngx-logger'; +import { + EventProtocolService, + SSVC_TYPE_EVENT_SEND_NOTI, + SendNotification, + SSVC_TYPE_EVENT_READ_NOTI, + SSVC_TYPE_EVENT_CANCEL_NOTI, + SSVC_TYPE_EVENT_DEL_RES +} 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'; @Injectable() export class AppNotificationService { constructor( private authenticationProtocolService: AuthenticationProtocolService, + private eventProtocolService: EventProtocolService, + private infoProtocolService: InfoProtocolService, + private roomProtocolService: RoomProtocolService, + private statusProtocolService: StatusProtocolService, private store: Store, private logger: NGXLogger ) {} @@ -31,11 +71,19 @@ export class AppNotificationService { case SSVC_TYPE_LOGOUT_RES: { const res = notiOrRes as LogoutResponse; + this.logger.debug( + 'Notification::authenticationProtocolService::LogoutResponse', + res + ); } break; case SSVC_TYPE_LOGOUT_REMOTE_NOTI: { const noti = notiOrRes as LogoutRemoteNotification; + this.logger.debug( + 'Notification::authenticationProtocolService::LogoutRemoteNotification', + noti + ); } break; default: @@ -45,5 +93,136 @@ export class AppNotificationService { }) ) .subscribe(); + + this.eventProtocolService.notification$ + .pipe( + tap(notiOrRes => { + switch (notiOrRes.Type) { + case SSVC_TYPE_EVENT_SEND_NOTI: + { + const noti = notiOrRes as SendNotification; + this.logger.debug( + 'Notification::eventProtocolService::SendNotification', + noti + ); + } + break; + case SSVC_TYPE_EVENT_READ_NOTI: + { + const noti = notiOrRes as ReadNotification; + this.logger.debug( + 'Notification::eventProtocolService::ReadNotification', + noti + ); + } + break; + case SSVC_TYPE_EVENT_CANCEL_NOTI: + { + const noti = notiOrRes as CancelNotification; + this.logger.debug( + 'Notification::eventProtocolService::CancelNotification', + noti + ); + } + break; + case SSVC_TYPE_EVENT_DEL_RES: + { + const noti = notiOrRes as DelNotification; + this.logger.debug( + 'Notification::eventProtocolService::DelNotification', + noti + ); + } + break; + default: + break; + } + }) + ) + .subscribe(); + this.infoProtocolService.notification$ + .pipe( + tap(notiOrRes => { + switch (notiOrRes.Type) { + case SSVC_TYPE_INFO_USER_NOTI: + { + const noti = notiOrRes as UserNotification; + this.logger.debug( + 'Notification::infoProtocolService::UserNotification', + noti + ); + } + break; + default: + break; + } + }) + ) + .subscribe(); + this.roomProtocolService.notification$ + .pipe( + tap(notiOrRes => { + switch (notiOrRes.Type) { + case SSVC_TYPE_ROOM_INVITE_NOTI: + { + const noti = notiOrRes as InviteNotification; + this.logger.debug( + 'Notification::roomProtocolService::InviteNotification', + noti + ); + } + break; + case SSVC_TYPE_ROOM_EXIT_NOTI: + { + const noti = notiOrRes as ExitNotification; + this.logger.debug( + 'Notification::roomProtocolService::ExitNotification', + noti + ); + } + break; + case SSVC_TYPE_ROOM_EXIT_FORCING_NOTI: + { + const noti = notiOrRes as ExitForcingNotification; + this.logger.debug( + 'Notification::roomProtocolService::ExitForcingNotification', + noti + ); + } + break; + case SSVC_TYPE_ROOM_FONT_UPD_NOTI: + { + const noti = notiOrRes as UpdateFontNotification; + this.logger.debug( + 'Notification::roomProtocolService::UpdateFontNotification', + noti + ); + } + break; + default: + break; + } + }) + ) + .subscribe(); + this.statusProtocolService.notification$ + .pipe( + tap(notiOrRes => { + switch (notiOrRes.Type) { + case SSVC_TYPE_STATUS_NOTI: + { + const noti = notiOrRes as StatusNotification; + this.logger.debug( + 'Notification::statusProtocolService::StatusNotification', + noti + ); + } + break; + default: + break; + } + }) + ) + .subscribe(); } } diff --git a/projects/ucap-webmessenger-protocol-authentication/src/lib/services/authentication-protocol.service.ts b/projects/ucap-webmessenger-protocol-authentication/src/lib/services/authentication-protocol.service.ts index 1cd48016..ea22b397 100644 --- a/projects/ucap-webmessenger-protocol-authentication/src/lib/services/authentication-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-authentication/src/lib/services/authentication-protocol.service.ts @@ -34,16 +34,14 @@ import { LogoutRemoteNotification } from '../protocols/logout-remote'; +type Notifications = LogoutResponse | LogoutRemoteNotification; + @Injectable({ providedIn: 'root' }) export class AuthenticationProtocolService { - private logoutNotificationSubject: Subject< - LogoutResponse | LogoutRemoteNotification - >; - public logoutNotification$: Observable< - LogoutResponse | LogoutRemoteNotification - >; + private logoutNotificationSubject: Subject; + public logoutNotification$: Observable; constructor(private protocolService: ProtocolService) { this.logoutNotificationSubject = new Subject(); diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/services/event-protocol.service.ts b/projects/ucap-webmessenger-protocol-event/src/lib/services/event-protocol.service.ts index bf4156ae..6b64183b 100644 --- a/projects/ucap-webmessenger-protocol-event/src/lib/services/event-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-event/src/lib/services/event-protocol.service.ts @@ -31,20 +31,27 @@ import { SSVC_TYPE_EVENT_READ_REQ, SSVC_TYPE_EVENT_DEL_REQ, SSVC_TYPE_EVENT_CANCEL_REQ, - SSVC_TYPE_EVENT_CANCEL_NOTI + SSVC_TYPE_EVENT_CANCEL_NOTI, + SSVC_TYPE_EVENT_SEND_NOTI, + SSVC_TYPE_EVENT_READ_NOTI, + SSVC_TYPE_EVENT_DEL_RES } from '../types/service'; import { SendRequest, SendResponse, decodeSend, - encodeSend + encodeSend, + decodeSendNotification, + SendNotification } from '../protocols/send'; import { PushRequest, encodePush } from '../protocols/push'; import { ReadResponse, ReadRequest, encodeRead, - decodeRead + decodeRead, + decodeReadNotification, + ReadNotification } from '../protocols/read'; import { DelRequest, @@ -60,33 +67,62 @@ import { CancelNotification, decodeCancelNotification } from '../protocols/cancel'; +import { decodeDelNotification, DelNotification } from '../protocols/del'; + +type Notifications = + | SendNotification + | ReadNotification + | CancelNotification + | DelNotification; @Injectable({ providedIn: 'root' }) export class EventProtocolService { - private eventNotificationSubject: Subject; - public eventNotification$: Observable; + private notificationSubject: Subject; + public notification$: Observable; constructor(private protocolService: ProtocolService) { - this.eventNotificationSubject = new Subject(); - this.eventNotification$ = this.eventNotificationSubject - .asObservable() - .pipe(share()); + this.notificationSubject = new Subject(); + this.notification$ = this.notificationSubject.asObservable().pipe(share()); this.protocolService.serverMessage .pipe( filter(message => message.serviceType === SVC_TYPE_EVENT), tap(message => { switch (message.subServiceType) { + case SSVC_TYPE_EVENT_SEND_NOTI: + { + this.notificationSubject.next({ + ...decodeSendNotification(message), + Type: SSVC_TYPE_EVENT_SEND_NOTI + }); + } + break; + case SSVC_TYPE_EVENT_READ_NOTI: + { + this.notificationSubject.next({ + ...decodeReadNotification(message), + Type: SSVC_TYPE_EVENT_READ_NOTI + }); + } + break; case SSVC_TYPE_EVENT_CANCEL_NOTI: { - this.eventNotificationSubject.next({ + this.notificationSubject.next({ ...decodeCancelNotification(message), Type: SSVC_TYPE_EVENT_CANCEL_NOTI }); } break; + case SSVC_TYPE_EVENT_DEL_RES: + { + this.notificationSubject.next({ + ...decodeDelNotification(message), + Type: SSVC_TYPE_EVENT_DEL_RES + }); + } + break; default: break; } diff --git a/projects/ucap-webmessenger-protocol-event/src/public-api.ts b/projects/ucap-webmessenger-protocol-event/src/public-api.ts index 44ee9937..33179b83 100644 --- a/projects/ucap-webmessenger-protocol-event/src/public-api.ts +++ b/projects/ucap-webmessenger-protocol-event/src/public-api.ts @@ -4,14 +4,18 @@ export * from './lib/models/info'; +export * from './lib/protocols/cancel'; +export * from './lib/protocols/del'; export * from './lib/protocols/info'; +export * from './lib/protocols/push'; +export * from './lib/protocols/read'; export * from './lib/protocols/send'; export * from './lib/services/event-protocol.service'; -export * from './lib/ucap-event-protocol.module'; - export * from './lib/types/event.type'; export * from './lib/types/push-cl.type'; export * from './lib/types/push-status.type'; export * from './lib/types/service'; + +export * from './lib/ucap-event-protocol.module'; diff --git a/projects/ucap-webmessenger-protocol-info/src/lib/services/info-protocol.service.ts b/projects/ucap-webmessenger-protocol-info/src/lib/services/info-protocol.service.ts index 35bc132b..97b6fc76 100644 --- a/projects/ucap-webmessenger-protocol-info/src/lib/services/info-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-info/src/lib/services/info-protocol.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; -import { map, take } from 'rxjs/operators'; +import { Observable, Subject } from 'rxjs'; +import { map, take, share, filter, tap } from 'rxjs/operators'; import { ProtocolService } from '@ucap-webmessenger/protocol'; import { @@ -9,13 +9,16 @@ import { SSVC_TYPE_INFO_USER_REQ, SSVC_TYPE_INFO_STATE_REQ, SSVC_TYPE_INFO_USER_OPTION_REQ, - SSVC_TYPE_INFO_USER_OPTION_UPD_REQ + SSVC_TYPE_INFO_USER_OPTION_UPD_REQ, + SSVC_TYPE_INFO_USER_NOTI } from '../types/service'; import { UserRequest, encodeUser, UserResponse, - decodeUser + decodeUser, + decodeUserNotification, + UserNotification } from '../protocols/user'; import { StatusRequest, @@ -32,11 +35,40 @@ import { decodeUserOptionUpdate } from '../protocols/user-option'; +type Notifications = UserNotification; + @Injectable({ providedIn: 'root' }) export class InfoProtocolService { - constructor(private protocolService: ProtocolService) {} + private notificationSubject: Subject; + public notification$: Observable; + + constructor(private protocolService: ProtocolService) { + this.notificationSubject = new Subject(); + this.notification$ = this.notificationSubject.asObservable().pipe(share()); + + this.protocolService.serverMessage + .pipe( + filter(message => message.serviceType === SVC_TYPE_INFO), + tap(message => { + switch (message.subServiceType) { + case SSVC_TYPE_INFO_USER_NOTI: + { + this.notificationSubject.next({ + ...decodeUserNotification(message), + Type: SSVC_TYPE_INFO_USER_NOTI + }); + } + break; + + default: + break; + } + }) + ) + .subscribe(); + } public user(req: UserRequest): Observable { return this.protocolService diff --git a/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts b/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts index a0109103..2aa215db 100644 --- a/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; -import { map, take, takeWhile } from 'rxjs/operators'; +import { Observable, Subject } from 'rxjs'; +import { map, take, takeWhile, share, tap, filter } from 'rxjs/operators'; import { ProtocolService } from '@ucap-webmessenger/protocol'; import { @@ -22,7 +22,11 @@ import { SSVC_TYPE_ROOM_USER_STATUS_REQ, SSVC_TYPE_ROOM_UPD_REQ, SSVC_TYPE_ROOM_INFO_UPD_REQ, - SSVC_TYPE_ROOM_FONT_UPD_REQ + SSVC_TYPE_ROOM_FONT_UPD_REQ, + SSVC_TYPE_ROOM_INVITE_NOTI, + SSVC_TYPE_ROOM_EXIT_NOTI, + SSVC_TYPE_ROOM_EXIT_FORCING_NOTI, + SSVC_TYPE_ROOM_FONT_UPD_NOTI } from '../types/service'; import { OpenRequest, @@ -46,7 +50,9 @@ import { InviteRequest, InviteResponse, encodeInvite, - decodeInvite + decodeInvite, + decodeInviteNotification, + InviteNotification } from '../protocols/invite'; import { InfoRequest, @@ -76,7 +82,11 @@ import { encodeExitForcing, decodeExitForcing, decodeAllExit, - ExitAllResponse + ExitAllResponse, + decodeExitForcingNotification, + decodeExitNotification, + ExitNotification, + ExitForcingNotification } from '../protocols/exit'; import { UpdateRequest, @@ -90,14 +100,73 @@ import { UpdateFontRequest, UpdateFontResponse, encodeUpdateFont, - decodeUpdateFont + decodeUpdateFont, + decodeUpdateFontNotification, + UpdateFontNotification } from '../protocols/update'; +type Notifications = + | UpdateFontNotification + | InviteNotification + | ExitNotification + | ExitForcingNotification; + @Injectable({ providedIn: 'root' }) export class RoomProtocolService { - constructor(private protocolService: ProtocolService) {} + private notificationSubject: Subject; + public notification$: Observable; + + constructor(private protocolService: ProtocolService) { + this.notificationSubject = new Subject(); + this.notification$ = this.notificationSubject.asObservable().pipe(share()); + + this.protocolService.serverMessage + .pipe( + filter(message => message.serviceType === SVC_TYPE_ROOM), + tap(message => { + switch (message.subServiceType) { + case SSVC_TYPE_ROOM_INVITE_NOTI: + { + this.notificationSubject.next({ + ...decodeInviteNotification(message), + Type: SSVC_TYPE_ROOM_INVITE_NOTI + }); + } + break; + case SSVC_TYPE_ROOM_EXIT_NOTI: + { + this.notificationSubject.next({ + ...decodeExitNotification(message), + Type: SSVC_TYPE_ROOM_EXIT_NOTI + }); + } + break; + case SSVC_TYPE_ROOM_EXIT_FORCING_NOTI: + { + this.notificationSubject.next({ + ...decodeExitForcingNotification(message), + Type: SSVC_TYPE_ROOM_EXIT_FORCING_NOTI + }); + } + break; + case SSVC_TYPE_ROOM_FONT_UPD_NOTI: + { + this.notificationSubject.next({ + ...decodeUpdateFontNotification(message), + Type: SSVC_TYPE_ROOM_FONT_UPD_NOTI + }); + } + break; + + default: + break; + } + }) + ) + .subscribe(); + } public open(req: OpenRequest): Observable { return this.protocolService diff --git a/projects/ucap-webmessenger-protocol-room/src/public-api.ts b/projects/ucap-webmessenger-protocol-room/src/public-api.ts index a8d42deb..ddf6144e 100644 --- a/projects/ucap-webmessenger-protocol-room/src/public-api.ts +++ b/projects/ucap-webmessenger-protocol-room/src/public-api.ts @@ -6,11 +6,14 @@ export * from './lib/models/room-info'; export * from './lib/models/user-info'; export * from './lib/models/user-info-short'; +export * from './lib/protocols/exit'; export * from './lib/protocols/info'; export * from './lib/protocols/invite'; export * from './lib/protocols/open'; +export * from './lib/protocols/update'; export * from './lib/services/room-protocol.service'; + export * from './lib/types/employee.type'; export * from './lib/types/room.type'; export * from './lib/types/service'; diff --git a/projects/ucap-webmessenger-protocol-status/src/lib/services/status-protocol.service.ts b/projects/ucap-webmessenger-protocol-status/src/lib/services/status-protocol.service.ts index adaefd64..f8e472ad 100644 --- a/projects/ucap-webmessenger-protocol-status/src/lib/services/status-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-status/src/lib/services/status-protocol.service.ts @@ -1,14 +1,16 @@ import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; -import { map, take, takeWhile } from 'rxjs/operators'; +import { Observable, Subject } from 'rxjs'; +import { map, take, takeWhile, share, filter, tap } from 'rxjs/operators'; import { ProtocolService } from '@ucap-webmessenger/protocol'; import { StatusRequest, encodeStatus, decodeStatus, - StatusResponse + StatusResponse, + decodeStatusNotification, + StatusNotification } from '../protocols/status'; import { SVC_TYPE_STATUS, @@ -19,7 +21,8 @@ import { SSVC_TYPE_STATUS_BUDDY_REQ, SSVC_TYPE_STATUS_MSG_UPD_REQ, SSVC_TYPE_STATUS_SUBSCRIPT_REQ, - SSVC_TYPE_STATUS_UNSUBSCRIPT_REQ + SSVC_TYPE_STATUS_UNSUBSCRIPT_REQ, + SSVC_TYPE_STATUS_NOTI } from '../types/service'; import { BulkInfoRequest, @@ -47,11 +50,40 @@ import { encodeUnSubscribe } from '../protocols/unsubscribe'; +type Notifications = StatusNotification; + @Injectable({ providedIn: 'root' }) export class StatusProtocolService { - constructor(private protocolService: ProtocolService) {} + private notificationSubject: Subject; + public notification$: Observable; + + constructor(private protocolService: ProtocolService) { + this.notificationSubject = new Subject(); + this.notification$ = this.notificationSubject.asObservable().pipe(share()); + + this.protocolService.serverMessage + .pipe( + filter(message => message.serviceType === SVC_TYPE_STATUS), + tap(message => { + switch (message.subServiceType) { + case SSVC_TYPE_STATUS_NOTI: + { + this.notificationSubject.next({ + ...decodeStatusNotification(message), + Type: SSVC_TYPE_STATUS_NOTI + }); + } + break; + + default: + break; + } + }) + ) + .subscribe(); + } public status(req: StatusRequest): Observable { return this.protocolService