diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag
index 48c5c705d3..8300bd5715 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 b4a8d829d6..bc0fc8dfe3 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 86df2d4924..8897748ae1 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 00ff686f69..a1cbc191d8 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 28c66df5c0..fc4a27e4f4 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 @@