Fix bug
This commit is contained in:
		
							parent
							
								
									b86594148e
								
							
						
					
					
						commit
						6dd635ddf3
					
				
					 5 changed files with 51 additions and 52 deletions
				
			
		| 
						 | 
					@ -2,8 +2,8 @@ import activateMe from './i';
 | 
				
			||||||
import activateApi from './api';
 | 
					import activateApi from './api';
 | 
				
			||||||
import activateStream from './stream';
 | 
					import activateStream from './stream';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default me => {
 | 
					export default (me, stream) => {
 | 
				
			||||||
	activateMe(me);
 | 
						activateMe(me);
 | 
				
			||||||
	activateApi(me);
 | 
						activateApi(me);
 | 
				
			||||||
	activateStream(me);
 | 
						activateStream(stream);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,5 @@
 | 
				
			||||||
import * as riot from 'riot';
 | 
					import * as riot from 'riot';
 | 
				
			||||||
import Connection from '../scripts/stream';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default me => {
 | 
					export default stream => {
 | 
				
			||||||
	const stream = me ? new Connection(me) : null;
 | 
						riot.mixin('stream', { stream });
 | 
				
			||||||
	riot.mixin('stream', {
 | 
					 | 
				
			||||||
		stream: stream
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,11 +11,12 @@ import * as riot from 'riot';
 | 
				
			||||||
import init from '../init';
 | 
					import init from '../init';
 | 
				
			||||||
import route from './router';
 | 
					import route from './router';
 | 
				
			||||||
import fuckAdBlock from './scripts/fuck-ad-block';
 | 
					import fuckAdBlock from './scripts/fuck-ad-block';
 | 
				
			||||||
 | 
					import getPostSummary from '../common/scripts/get-post-summary';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * init
 | 
					 * init
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
init(me => {
 | 
					init(async (me, stream) => {
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Fuck AD Block
 | 
						 * Fuck AD Block
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
| 
						 | 
					@ -27,10 +28,48 @@ init(me => {
 | 
				
			||||||
	if ('Notification' in window) {
 | 
						if ('Notification' in window) {
 | 
				
			||||||
		// 許可を得ていなかったらリクエスト
 | 
							// 許可を得ていなかったらリクエスト
 | 
				
			||||||
		if (Notification.permission == 'default') {
 | 
							if (Notification.permission == 'default') {
 | 
				
			||||||
			Notification.requestPermission();
 | 
								await Notification.requestPermission();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (Notification.permission == 'granted') {
 | 
				
			||||||
 | 
								registerNotifications(stream);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Start routing
 | 
						// Start routing
 | 
				
			||||||
	route(me);
 | 
						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);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,40 +0,0 @@
 | 
				
			||||||
const stream = require('../../common/scripts/stream');
 | 
					 | 
				
			||||||
const getPostSummary = require('../../common/scripts/get-post-summary');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module.exports = me => {
 | 
					 | 
				
			||||||
	const s = stream(me);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	s.event.on('drive_file_created', file => {
 | 
					 | 
				
			||||||
		const n = new Notification('ファイルがアップロードされました', {
 | 
					 | 
				
			||||||
			body: file.name,
 | 
					 | 
				
			||||||
			icon: file.url + '?thumbnail&size=64'
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
		setTimeout(n.close.bind(n), 5000);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	s.event.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);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	s.event.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);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	s.event.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);
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return s;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ import * as riot from 'riot';
 | 
				
			||||||
import api from './common/scripts/api';
 | 
					import api from './common/scripts/api';
 | 
				
			||||||
import signout from './common/scripts/signout';
 | 
					import signout from './common/scripts/signout';
 | 
				
			||||||
import checkForUpdate from './common/scripts/check-for-update';
 | 
					import checkForUpdate from './common/scripts/check-for-update';
 | 
				
			||||||
 | 
					import Connection from './common/scripts/stream';
 | 
				
			||||||
import mixin from './common/mixins';
 | 
					import mixin from './common/mixins';
 | 
				
			||||||
import generateDefaultUserdata from './common/scripts/generate-default-userdata';
 | 
					import generateDefaultUserdata from './common/scripts/generate-default-userdata';
 | 
				
			||||||
import CONFIG from './common/scripts/config';
 | 
					import CONFIG from './common/scripts/config';
 | 
				
			||||||
| 
						 | 
					@ -94,8 +95,11 @@ export default callback => {
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Init stream connection
 | 
				
			||||||
 | 
							const stream = me ? new Connection(me) : null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// ミックスイン初期化
 | 
							// ミックスイン初期化
 | 
				
			||||||
		mixin(me);
 | 
							mixin(me, stream);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// ローディング画面クリア
 | 
							// ローディング画面クリア
 | 
				
			||||||
		const ini = document.getElementById('ini');
 | 
							const ini = document.getElementById('ini');
 | 
				
			||||||
| 
						 | 
					@ -107,7 +111,7 @@ export default callback => {
 | 
				
			||||||
		document.body.appendChild(app);
 | 
							document.body.appendChild(app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			callback(me);
 | 
								callback(me, stream);
 | 
				
			||||||
		} catch (e) {
 | 
							} catch (e) {
 | 
				
			||||||
			panic(e);
 | 
								panic(e);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue