From 1d282b59cbe54a1f0fd3b9b11f9e141cc4b6d338 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Tue, 12 Nov 2019 10:38:51 +0900 Subject: [PATCH] open room of notification is implemented --- .../src/lib/models/electron-notification.ts | 2 +- .../services/electron-notification.service.ts | 32 ++++++------ .../ucap-webmessenger-electron/src/index.ts | 18 ++++--- .../components/main.page.component.ts | 51 +++++++++++-------- .../lib/notification/notification.service.ts | 5 +- .../lib/services/browser-native.service.ts | 28 +++++++--- .../lib/services/electron-native.service.ts | 23 ++++++++- .../src/lib/types/channel.type.ts | 4 ++ .../src/lib/services/native.service.ts | 2 + 9 files changed, 114 insertions(+), 51 deletions(-) diff --git a/electron-projects/ucap-webmessenger-electron-notification/src/lib/models/electron-notification.ts b/electron-projects/ucap-webmessenger-electron-notification/src/lib/models/electron-notification.ts index c7416e57..f583ac1c 100644 --- a/electron-projects/ucap-webmessenger-electron-notification/src/lib/models/electron-notification.ts +++ b/electron-projects/ucap-webmessenger-electron-notification/src/lib/models/electron-notification.ts @@ -3,7 +3,7 @@ import { ElectronNotificationEventType } from '../types/event.type'; export interface ElectronNotificationEvent { type: ElectronNotificationEventType; id: number; - close?: (reason: any) => void; + close?: (reason?: any) => void; } export interface ElectronNotification { diff --git a/electron-projects/ucap-webmessenger-electron-notification/src/lib/services/electron-notification.service.ts b/electron-projects/ucap-webmessenger-electron-notification/src/lib/services/electron-notification.service.ts index 351ef9d5..ea13e059 100644 --- a/electron-projects/ucap-webmessenger-electron-notification/src/lib/services/electron-notification.service.ts +++ b/electron-projects/ucap-webmessenger-electron-notification/src/lib/services/electron-notification.service.ts @@ -5,7 +5,7 @@ import * as fse from 'fs-extra'; import { AnimationQueue } from '../utils/animation-queue'; import { ElectronNotificationOptions, - DefaultElectronNotificationOptions + DefaultElectronNotificationOptions, } from '../models/electron-notification-options'; import { screen, BrowserWindow, ipcMain, IpcMainEvent, shell } from 'electron'; import { ElectronNotification } from '../models/electron-notification'; @@ -43,12 +43,12 @@ export class ElectronNotificationService { constructor(options?: ElectronNotificationOptions) { this.customOptions = { - ...DefaultElectronNotificationOptions + ...DefaultElectronNotificationOptions, }; if (!!options) { this.customOptions = { ...this.customOptions, - ...options + ...options, }; } @@ -60,7 +60,7 @@ export class ElectronNotificationService { if (!!options) { this.customOptions = { ...this.customOptions, - ...options + ...options, }; } this.calcDimensions(); @@ -89,7 +89,7 @@ export class ElectronNotificationService { this.animationQueue.push({ context: this, func: this.showNotification, - args: [notification] + args: [notification], }); return notification.id; } @@ -124,7 +124,7 @@ export class ElectronNotificationService { this.lowerRightCornerPosition = { x: display.bounds.x + display.workArea.x + display.workAreaSize.width, - y: display.bounds.y + display.workArea.y + display.workAreaSize.height + y: display.bounds.y + display.workArea.y + display.workAreaSize.height, }; this.calcDimensions(); @@ -177,7 +177,7 @@ export class ElectronNotificationService { notificationWindow[onClickElectronNotification]({ type: ElectronNotificationEventType.Click, id: notification.id, - close: self.buildCloseNotificationSafely(onClose) + close: self.buildCloseNotificationSafely(onClose), }); delete notificationWindow[onClickElectronNotification]; } @@ -188,17 +188,17 @@ export class ElectronNotificationService { private calcDimensions() { this.totalDimension = { width: this.customOptions.width + this.customOptions.padding, - height: this.customOptions.height + this.customOptions.padding + height: this.customOptions.height + this.customOptions.padding, }; this.firstPosition = { x: this.lowerRightCornerPosition.x - this.totalDimension.width, - y: this.lowerRightCornerPosition.y - this.totalDimension.height + y: this.lowerRightCornerPosition.y - this.totalDimension.height, }; this.nextInsertPosition = { x: this.firstPosition.x, - y: this.firstPosition.y + y: this.firstPosition.y, }; } @@ -217,7 +217,7 @@ export class ElectronNotificationService { this.templateUrl = url.format({ pathname: this.customOptions.templatePath, protocol: 'file:', - slashes: true + slashes: true, }); } catch (e) { console.log( @@ -266,11 +266,11 @@ export class ElectronNotificationService { notification.onShow({ type: ElectronNotificationEventType.Show, id: notification.id, - close: onCloseNotificationSafely + close: onCloseNotificationSafely, }); } - if (!!notification.onClose) { + if (!!notification.onClick) { notificationWindow[onClickElectronNotification] = notification.onClick; } else { @@ -321,7 +321,7 @@ export class ElectronNotificationService { if (!!notificationWindow[onCloseElectronNotification]) { notificationWindow[onCloseElectronNotification]({ type: e, - id: notification.id + id: notification.id, }); delete notificationWindow[onCloseElectronNotification]; } @@ -353,7 +353,7 @@ export class ElectronNotificationService { self.animationQueue.push({ context: self, func: onClose, - args: [reason] + args: [reason], }); }; } @@ -366,7 +366,7 @@ export class ElectronNotificationService { this.animationQueue.push({ context: this, func: this.showNotification, - args: [this.notificationQueue.shift()] + args: [this.notificationQueue.shift()], }); } } diff --git a/electron-projects/ucap-webmessenger-electron/src/index.ts b/electron-projects/ucap-webmessenger-electron/src/index.ts index 1f7afb88..3e6f4e12 100644 --- a/electron-projects/ucap-webmessenger-electron/src/index.ts +++ b/electron-projects/ucap-webmessenger-electron/src/index.ts @@ -12,7 +12,8 @@ import { UpdaterChannel, FileChannel, IdleStateChannel, - NotificationChannel + NotificationChannel, + ChatChannel, } from '@ucap-webmessenger/native-electron'; import { ElectronNotificationService } from '@ucap-webmessenger/electron-notification'; @@ -105,7 +106,7 @@ function createWindow() { import('electron-devtools-installer').then(edi => { const ChromeLens = { id: 'idikgljglpfilbhaboonnpnnincjhjkd', - electron: '>=1.2.1' + electron: '>=1.2.1', }; const extensions = [edi.REDUX_DEVTOOLS, ChromeLens]; @@ -165,7 +166,7 @@ app.on(ElectronAppChannel.Ready, () => { defaultStyleAppIcon: { display: 'none' }, defaultStyleImage: {}, defaultStyleClose: {}, - defaultStyleText: {} + defaultStyleText: {}, }); notificationService.options.defaultWindow.webPreferences.preload = path.join( @@ -289,9 +290,14 @@ ipcMain.on( 'resources/notification/sound/messageAlarm.mp3' ) : '', - onClick: () => { - console.log('onClick'); - } + onClick: e => { + appWindow.browserWindow.webContents.send( + ChatChannel.OpenRoom, + noti.roomSeq + ); + appWindow.show(); + e.close(); + }, }); } ); diff --git a/projects/ucap-webmessenger-app/src/app/pages/messenger/components/main.page.component.ts b/projects/ucap-webmessenger-app/src/app/pages/messenger/components/main.page.component.ts index 65d424a8..939ec59d 100644 --- a/projects/ucap-webmessenger-app/src/app/pages/messenger/components/main.page.component.ts +++ b/projects/ucap-webmessenger-app/src/app/pages/messenger/components/main.page.component.ts @@ -1,44 +1,45 @@ -import { map, tap } from 'rxjs/operators'; -import { Component, OnInit, Inject, OnDestroy, ViewChild } from '@angular/core'; +import { map, tap } from "rxjs/operators"; +import { Component, OnInit, Inject, OnDestroy, ViewChild } from "@angular/core"; -import { Store, select } from '@ngrx/store'; +import { Store, select } from "@ngrx/store"; -import * as AppSotre from '@app/store'; -import * as ChatStore from '@app/store/messenger/chat'; -import { Observable, Subscription } from 'rxjs'; +import * as AppSotre from "@app/store"; +import * as ChatStore from "@app/store/messenger/chat"; +import { Observable, Subscription } from "rxjs"; import { WindowIdle, UCAP_NATIVE_SERVICE, NativeService -} from '@ucap-webmessenger/native'; +} from "@ucap-webmessenger/native"; -import { UserInfo } from '@ucap-webmessenger/protocol-sync'; +import { UserInfo } from "@ucap-webmessenger/protocol-sync"; import { UserInfoSS, UserInfoF, UserInfoDN -} from '@ucap-webmessenger/protocol-query'; -import { StatusProtocolService } from '@ucap-webmessenger/protocol-status'; -import { StatusType, StatusCode } from '@ucap-webmessenger/core'; -import { DialogService } from '@ucap-webmessenger/ui'; +} from "@ucap-webmessenger/protocol-query"; +import { StatusProtocolService } from "@ucap-webmessenger/protocol-status"; +import { StatusType, StatusCode } from "@ucap-webmessenger/core"; +import { DialogService } from "@ucap-webmessenger/ui"; import { ProfileDialogComponent, ProfileDialogData, ProfileDialogResult -} from '@app/layouts/messenger/dialogs/profile/profile.dialog.component'; -import { MatSidenav, MatDrawer } from '@angular/material'; +} from "@app/layouts/messenger/dialogs/profile/profile.dialog.component"; +import { MatSidenav, MatDrawer } from "@angular/material"; @Component({ - selector: 'app-page-messenger-main', - templateUrl: './main.page.component.html', - styleUrls: ['./main.page.component.scss'] + selector: "app-page-messenger-main", + templateUrl: "./main.page.component.html", + styleUrls: ["./main.page.component.scss"] }) export class MainPageComponent implements OnInit { selectedChat$: Observable; selectedRightDrawer$: Observable; idleStateChangedSubscription: Subscription; + chatOpenRoomSubscription: Subscription; - @ViewChild('rightDrawer', { static: true }) rightDrawer: MatDrawer; + @ViewChild("rightDrawer", { static: true }) rightDrawer: MatDrawer; constructor( @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, @@ -74,7 +75,7 @@ export class MainPageComponent implements OnInit { console.log(action); let statusType: StatusCode; - if (action === 'IDLE') { + if (action === "IDLE") { // away statusType = StatusCode.Away; } else { @@ -85,15 +86,25 @@ export class MainPageComponent implements OnInit { this.statusProtocolService.status({ statusDivisionType: StatusType.Messenger, statusType, - statusMessage: '' + statusMessage: "" }); }); + + this.chatOpenRoomSubscription = this.nativeService + .chatOpenRoom() + .subscribe(roomSeq => { + this.store.dispatch(ChatStore.selectedRoom({ roomSeq })); + }); } OnDestroy(): void { if (!!this.idleStateChangedSubscription) { this.idleStateChangedSubscription.unsubscribe(); } + + if (!!this.chatOpenRoomSubscription) { + this.chatOpenRoomSubscription.unsubscribe(); + } } onOpenedChange(event: boolean) { diff --git a/projects/ucap-webmessenger-native-browser/src/lib/notification/notification.service.ts b/projects/ucap-webmessenger-native-browser/src/lib/notification/notification.service.ts index b6d86ca7..1e1aa425 100644 --- a/projects/ucap-webmessenger-native-browser/src/lib/notification/notification.service.ts +++ b/projects/ucap-webmessenger-native-browser/src/lib/notification/notification.service.ts @@ -20,13 +20,16 @@ export class NotificationService { } } - notify(noti: NotificationRequest) { + notify(noti: NotificationRequest, click?: () => void) { const notification = new Notification(noti.title, { body: noti.contents, icon: noti.image || 'assets/images/img_nophoto_50.png' }); notification.onclick = e => { console.log('notification.onclick'); + if (!!click) { + click(); + } }; notification.onclose = e => { console.log('notification.onclose'); diff --git a/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts b/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts index 5df23317..67c5978f 100644 --- a/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts +++ b/projects/ucap-webmessenger-native-browser/src/lib/services/browser-native.service.ts @@ -1,31 +1,36 @@ -import { Observable } from 'rxjs'; +import { Observable, Subject } from 'rxjs'; import { NativeService, WindowState, NotificationRequest, - WindowIdle + WindowIdle, } from '@ucap-webmessenger/native'; import { HttpClient } from '@angular/common/http'; -import { map } from 'rxjs/operators'; +import { map, share } from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { TranslateLoader } from '@ngx-translate/core'; import { TranslateLoaderService } from '../translate/browser-loader'; import { NotificationService } from '../notification/notification.service'; @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class BrowserNativeService implements NativeService { private notificationService: NotificationService; + private chatOpenRoomSubject: Subject | null = null; + private chatOpenRoom$: Observable | null = null; + postAppInit(): void { this.notificationService.requestPermission(); } notify(noti: NotificationRequest): void { - console.log('ddd'); - this.notificationService.notify(noti); + this.notificationService.notify(noti, () => { + window.focus(); + this.chatOpenRoomSubject.next(noti.roomSeq); + }); } closeAllNotify(): void {} @@ -89,6 +94,17 @@ export class BrowserNativeService implements NativeService { }); } + chatOpenRoom(): Observable { + if (!this.chatOpenRoomSubject) { + this.chatOpenRoomSubject = new Subject(); + this.chatOpenRoom$ = this.chatOpenRoomSubject + .asObservable() + .pipe(share()); + } + + return this.chatOpenRoom$; + } + getTranslateLoader(prefix?: string, suffix?: string): TranslateLoader { return new TranslateLoaderService(this, prefix, suffix); } diff --git a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts index c4e58732..4a7bf321 100644 --- a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts +++ b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts @@ -14,7 +14,8 @@ import { UpdaterChannel, FileChannel, WindowStateChannel, - IdleStateChannel + IdleStateChannel, + ChatChannel } from '../types/channel.type'; import { Injectable } from '@angular/core'; import { TranslateLoaderService } from '../translate/electron-loader'; @@ -30,6 +31,9 @@ export class ElectronNativeService implements NativeService { private idleStateChangedSubject: Subject | null = null; private idleStateChanged$: Observable | null = null; + private chatOpenRoomSubject: Subject | null = null; + private chatOpenRoom$: Observable | null = null; + postAppInit(): void {} notify(noti: NotificationRequest): void { @@ -153,6 +157,23 @@ export class ElectronNativeService implements NativeService { return this.idleStateChanged$; } + chatOpenRoom(): Observable { + if (!this.chatOpenRoomSubject) { + this.chatOpenRoomSubject = new Subject(); + this.chatOpenRoom$ = this.chatOpenRoomSubject + .asObservable() + .pipe(share()); + } + + ipcRenderer.on( + ChatChannel.OpenRoom, + (event: IpcRendererEvent, roomSeq: string) => { + this.chatOpenRoomSubject.next(roomSeq); + } + ); + return this.chatOpenRoom$; + } + getTranslateLoader(prefix?: string, suffix?: string): TranslateLoader { return new TranslateLoaderService(this, prefix, suffix); } diff --git a/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts b/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts index c698832c..36235950 100644 --- a/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts +++ b/projects/ucap-webmessenger-native-electron/src/lib/types/channel.type.ts @@ -1,3 +1,7 @@ +export enum ChatChannel { + OpenRoom = 'UCAP::chat::openRoom' +} + export enum NotificationChannel { Notify = 'UCAP::notification::notify', CloseAllNotify = 'UCAP::notification::closeAllNotify' diff --git a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts index 1a8c5d5f..4aebb58d 100644 --- a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts +++ b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts @@ -25,5 +25,7 @@ export interface NativeService { idleStateChanged(): Observable; + chatOpenRoom(): Observable; + getTranslateLoader(prefix?: string, suffix?: string): TranslateLoader; }