diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-11-13 18:05:35 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-11-13 18:05:35 +0900 |
| commit | bc9a8283c66d7588f931d4b802f7ab1fa7aa3226 (patch) | |
| tree | cac529d136737c95b1656564756da8c4ae84df32 /src/web/app/desktop/script.ts | |
| parent | :v: (diff) | |
| download | sharkey-bc9a8283c66d7588f931d4b802f7ab1fa7aa3226.tar.gz sharkey-bc9a8283c66d7588f931d4b802f7ab1fa7aa3226.tar.bz2 sharkey-bc9a8283c66d7588f931d4b802f7ab1fa7aa3226.zip | |
なんかもうめっちゃ変えた
Diffstat (limited to 'src/web/app/desktop/script.ts')
| -rw-r--r-- | src/web/app/desktop/script.ts | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/web/app/desktop/script.ts b/src/web/app/desktop/script.ts new file mode 100644 index 0000000000..a0453865ec --- /dev/null +++ b/src/web/app/desktop/script.ts @@ -0,0 +1,91 @@ +/** + * Desktop Client + */ + +// Style +import './style.styl'; + +require('./tags'); +require('./mixins'); +import * as riot from 'riot'; +import init from '../init'; +import route from './router'; +import fuckAdBlock from './scripts/fuck-ad-block'; +import getPostSummary from '../../../common/get-post-summary'; + +/** + * init + */ +init(async (me, stream) => { + /** + * Fuck AD Block + */ + fuckAdBlock(); + + /** + * Init Notification + */ + if ('Notification' in window) { + // 許可を得ていなかったらリクエスト + if ((Notification as any).permission == 'default') { + await Notification.requestPermission(); + } + + if ((Notification as any).permission == 'granted') { + registerNotifications(stream); + } + } + + // Start routing + route(me); +}); + +function registerNotifications(stream) { + 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); + }); + + 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 + }); + }; + setTimeout(n.close.bind(n), 7000); + }); +} |