From 6dd635ddf3d0928bb0a283a21f342ff05e8e61ba Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 7 Jun 2017 00:04:28 +0900 Subject: Fix bug --- src/web/app/desktop/script.js | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/web/app/desktop/script.js') diff --git a/src/web/app/desktop/script.js b/src/web/app/desktop/script.js index b3691f7ff2..6beba44ffa 100644 --- a/src/web/app/desktop/script.js +++ b/src/web/app/desktop/script.js @@ -11,11 +11,12 @@ import * as riot from 'riot'; import init from '../init'; import route from './router'; import fuckAdBlock from './scripts/fuck-ad-block'; +import getPostSummary from '../common/scripts/get-post-summary'; /** * init */ -init(me => { +init(async (me, stream) => { /** * Fuck AD Block */ @@ -27,10 +28,48 @@ init(me => { if ('Notification' in window) { // 許可を得ていなかったらリクエスト if (Notification.permission == 'default') { - Notification.requestPermission(); + await Notification.requestPermission(); + } + + if (Notification.permission == 'granted') { + registerNotifications(stream); } } // Start routing route(me); }); + +function registerNotifications(stream) { + 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); + }); + + 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); + }); +} -- cgit v1.3.1-freya