summaryrefslogtreecommitdiff
path: root/src/web/app/desktop/script.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-11-17 01:24:44 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-11-17 01:24:44 +0900
commitc614e6f5d73b3b4314c7f6abf52260e58cc176ad (patch)
treeb8ad5a47d532a9af4060022e5ef3de4166f884c5 /src/web/app/desktop/script.ts
parenttypo (diff)
downloadmisskey-c614e6f5d73b3b4314c7f6abf52260e58cc176ad.tar.gz
misskey-c614e6f5d73b3b4314c7f6abf52260e58cc176ad.tar.bz2
misskey-c614e6f5d73b3b4314c7f6abf52260e58cc176ad.zip
#925, #926, and refactoring
Diffstat (limited to 'src/web/app/desktop/script.ts')
-rw-r--r--src/web/app/desktop/script.ts83
1 files changed, 47 insertions, 36 deletions
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'
+ 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), 5000);
});
- 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'
+ 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);
});
- 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'
+ 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);
});
- 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'
+ 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);
});
- n.onclick = () => {
- n.close();
- (riot as any).mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), {
- user: message.user
+
+ 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'
});
- };
- setTimeout(n.close.bind(n), 7000);
- });
+ 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);
+ });
+ }
}