From c614e6f5d73b3b4314c7f6abf52260e58cc176ad Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 17 Nov 2017 01:24:44 +0900 Subject: [PATCH] #925, #926, and refactoring --- src/web/app/ch/tags/channel.tag | 2 +- src/web/app/common/mios.ts | 23 +++-- src/web/app/common/mixins.ts | 8 +- src/web/app/common/scripts/stream-manager.ts | 33 ------- .../scripts/{ => streaming}/channel-stream.ts | 4 +- .../{ => streaming}/drive-stream-manager.ts | 0 .../scripts/{ => streaming}/drive-stream.ts | 4 +- .../scripts/streaming/home-stream-manager.ts | 20 ++++ .../scripts/{ => streaming}/home-stream.ts | 9 +- .../messaging-index-stream-manager.ts | 0 .../{ => streaming}/messaging-index-stream.ts | 4 +- .../{ => streaming}/messaging-stream.ts | 4 +- .../requests-stream-manager.ts | 0 .../{ => streaming}/requests-stream.ts | 4 +- .../{ => streaming}/server-stream-manager.ts | 0 .../scripts/{ => streaming}/server-stream.ts | 4 +- .../scripts/streaming/stream-manager.ts | 73 ++++++++++++++ .../common/scripts/{ => streaming}/stream.ts | 22 ++--- src/web/app/common/tags/messaging/room.tag | 2 +- src/web/app/common/tags/signin-history.tag | 8 +- src/web/app/common/tags/stream-indicator.tag | 45 +++++---- src/web/app/desktop/script.ts | 97 +++++++++++-------- .../app/desktop/tags/big-follow-button.tag | 12 ++- src/web/app/desktop/tags/follow-button.tag | 12 ++- .../app/desktop/tags/home-widgets/channel.tag | 2 +- .../tags/home-widgets/photo-stream.tag | 8 +- .../desktop/tags/home-widgets/timeline.tag | 16 +-- src/web/app/desktop/tags/notifications.tag | 12 ++- src/web/app/desktop/tags/pages/home.tag | 10 +- src/web/app/desktop/tags/timeline.tag | 18 ++-- src/web/app/desktop/tags/ui.tag | 12 ++- src/web/app/mobile/tags/follow-button.tag | 12 ++- src/web/app/mobile/tags/home-timeline.tag | 16 +-- src/web/app/mobile/tags/notifications.tag | 10 +- src/web/app/mobile/tags/page/home.tag | 8 +- src/web/app/mobile/tags/timeline.tag | 16 +-- src/web/app/mobile/tags/ui.tag | 42 +++++--- src/web/app/status/tags/index.tag | 2 +- 38 files changed, 358 insertions(+), 216 deletions(-) delete mode 100644 src/web/app/common/scripts/stream-manager.ts rename src/web/app/common/scripts/{ => streaming}/channel-stream.ts (70%) rename src/web/app/common/scripts/{ => streaming}/drive-stream-manager.ts (100%) rename src/web/app/common/scripts/{ => streaming}/drive-stream.ts (67%) create mode 100644 src/web/app/common/scripts/streaming/home-stream-manager.ts rename src/web/app/common/scripts/{ => streaming}/home-stream.ts (62%) rename src/web/app/common/scripts/{ => streaming}/messaging-index-stream-manager.ts (100%) rename src/web/app/common/scripts/{ => streaming}/messaging-index-stream.ts (70%) rename src/web/app/common/scripts/{ => streaming}/messaging-stream.ts (80%) rename src/web/app/common/scripts/{ => streaming}/requests-stream-manager.ts (100%) rename src/web/app/common/scripts/{ => streaming}/requests-stream.ts (64%) rename src/web/app/common/scripts/{ => streaming}/server-stream-manager.ts (100%) rename src/web/app/common/scripts/{ => streaming}/server-stream.ts (63%) create mode 100644 src/web/app/common/scripts/streaming/stream-manager.ts rename src/web/app/common/scripts/{ => streaming}/stream.ts (85%) diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index 48c5c705d..8300bd571 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -55,7 +55,7 @@ diff --git a/src/web/app/desktop/script.ts b/src/web/app/desktop/script.ts index b4a8d829d..bc0fc8dfe 100644 --- a/src/web/app/desktop/script.ts +++ b/src/web/app/desktop/script.ts @@ -13,6 +13,7 @@ import route from './router'; import fuckAdBlock from './scripts/fuck-ad-block'; import getPostSummary from '../../../common/get-post-summary'; import MiOS from '../common/mios'; +import HomeStreamManager from '../common/scripts/streaming/home-stream-manager'; /** * init @@ -41,52 +42,62 @@ init(async (mios: MiOS) => { route(mios); }); -function registerNotifications(stream) { +function registerNotifications(stream: HomeStreamManager) { if (stream == null) return; - stream.on('drive_file_created', file => { - const n = new Notification('ファイルがアップロードされました', { - body: file.name, - icon: file.url + '?thumbnail&size=64' - }); - setTimeout(n.close.bind(n), 5000); + if (stream.hasConnection) { + attach(stream.borrow()); + } + + stream.on('connected', connection => { + attach(connection); }); - stream.on('mention', post => { - const n = new Notification(`${post.user.name}さんから:`, { - body: getPostSummary(post), - icon: post.user.avatar_url + '?thumbnail&size=64' - }); - setTimeout(n.close.bind(n), 6000); - }); - - stream.on('reply', post => { - const n = new Notification(`${post.user.name}さんから返信:`, { - body: getPostSummary(post), - icon: post.user.avatar_url + '?thumbnail&size=64' - }); - setTimeout(n.close.bind(n), 6000); - }); - - stream.on('quote', post => { - const n = new Notification(`${post.user.name}さんが引用:`, { - body: getPostSummary(post), - icon: post.user.avatar_url + '?thumbnail&size=64' - }); - setTimeout(n.close.bind(n), 6000); - }); - - stream.on('unread_messaging_message', message => { - const n = new Notification(`${message.user.name}さんからメッセージ:`, { - body: message.text, // TODO: getMessagingMessageSummary(message), - icon: message.user.avatar_url + '?thumbnail&size=64' - }); - n.onclick = () => { - n.close(); - (riot as any).mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), { - user: message.user + function attach(connection) { + connection.on('drive_file_created', file => { + const n = new Notification('ファイルがアップロードされました', { + body: file.name, + icon: file.url + '?thumbnail&size=64' }); - }; - setTimeout(n.close.bind(n), 7000); - }); + setTimeout(n.close.bind(n), 5000); + }); + + connection.on('mention', post => { + const n = new Notification(`${post.user.name}さんから:`, { + body: getPostSummary(post), + icon: post.user.avatar_url + '?thumbnail&size=64' + }); + setTimeout(n.close.bind(n), 6000); + }); + + connection.on('reply', post => { + const n = new Notification(`${post.user.name}さんから返信:`, { + body: getPostSummary(post), + icon: post.user.avatar_url + '?thumbnail&size=64' + }); + setTimeout(n.close.bind(n), 6000); + }); + + connection.on('quote', post => { + const n = new Notification(`${post.user.name}さんが引用:`, { + body: getPostSummary(post), + icon: post.user.avatar_url + '?thumbnail&size=64' + }); + setTimeout(n.close.bind(n), 6000); + }); + + connection.on('unread_messaging_message', message => { + const n = new Notification(`${message.user.name}さんからメッセージ:`, { + body: message.text, // TODO: getMessagingMessageSummary(message), + icon: message.user.avatar_url + '?thumbnail&size=64' + }); + n.onclick = () => { + n.close(); + (riot as any).mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), { + user: message.user + }); + }; + setTimeout(n.close.bind(n), 7000); + }); + } } diff --git a/src/web/app/desktop/tags/big-follow-button.tag b/src/web/app/desktop/tags/big-follow-button.tag index 86df2d492..8897748ae 100644 --- a/src/web/app/desktop/tags/big-follow-button.tag +++ b/src/web/app/desktop/tags/big-follow-button.tag @@ -74,7 +74,10 @@ this.mixin('i'); this.mixin('api'); + this.mixin('stream'); + this.connection = this.stream.getConnection(); + this.connectionId = this.stream.use(); this.user = null; this.userPromise = isPromise(this.opts.user) @@ -89,14 +92,15 @@ init: false, user: user }); - this.stream.on('follow', this.onStreamFollow); - this.stream.on('unfollow', this.onStreamUnfollow); + this.connection.on('follow', this.onStreamFollow); + this.connection.on('unfollow', this.onStreamUnfollow); }); }); this.on('unmount', () => { - this.stream.off('follow', this.onStreamFollow); - this.stream.off('unfollow', this.onStreamUnfollow); + this.connection.off('follow', this.onStreamFollow); + this.connection.off('unfollow', this.onStreamUnfollow); + this.stream.dispose(this.connectionId); }); this.onStreamFollow = user => { diff --git a/src/web/app/desktop/tags/follow-button.tag b/src/web/app/desktop/tags/follow-button.tag index 00ff686f6..a1cbc191d 100644 --- a/src/web/app/desktop/tags/follow-button.tag +++ b/src/web/app/desktop/tags/follow-button.tag @@ -71,7 +71,10 @@ this.mixin('i'); this.mixin('api'); + this.mixin('stream'); + this.connection = this.stream.getConnection(); + this.connectionId = this.stream.use(); this.user = null; this.userPromise = isPromise(this.opts.user) @@ -86,14 +89,15 @@ init: false, user: user }); - this.stream.on('follow', this.onStreamFollow); - this.stream.on('unfollow', this.onStreamUnfollow); + this.connection.on('follow', this.onStreamFollow); + this.connection.on('unfollow', this.onStreamUnfollow); }); }); this.on('unmount', () => { - this.stream.off('follow', this.onStreamFollow); - this.stream.off('unfollow', this.onStreamUnfollow); + this.connection.off('follow', this.onStreamFollow); + this.connection.off('unfollow', this.onStreamUnfollow); + this.stream.dispose(this.connectionId); }); this.onStreamFollow = user => { diff --git a/src/web/app/desktop/tags/home-widgets/channel.tag b/src/web/app/desktop/tags/home-widgets/channel.tag index 28c66df5c..fc4a27e4f 100644 --- a/src/web/app/desktop/tags/home-widgets/channel.tag +++ b/src/web/app/desktop/tags/home-widgets/channel.tag @@ -138,7 +138,7 @@