#925, #926, and refactoring

This commit is contained in:
syuilo 2017-11-17 01:24:44 +09:00
parent 4129dce95a
commit c614e6f5d7
38 changed files with 358 additions and 216 deletions

View file

@ -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);
});
}
}

View file

@ -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 => {

View file

@ -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 => {

View file

@ -138,7 +138,7 @@
</style>
<script>
import ChannelStream from '../../../common/scripts/channel-stream';
import ChannelStream from '../../../common/scripts/streaming/channel-stream';
this.mixin('api');

View file

@ -75,13 +75,16 @@
};
this.mixin('widget');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.images = [];
this.initializing = true;
this.on('mount', () => {
this.stream.on('drive_file_created', this.onStreamDriveFileCreated);
this.connection.on('drive_file_created', this.onStreamDriveFileCreated);
this.api('drive/stream', {
type: 'image/*',
@ -95,7 +98,8 @@
});
this.on('unmount', () => {
this.stream.off('drive_file_created', this.onStreamDriveFileCreated);
this.connection.off('drive_file_created', this.onStreamDriveFileCreated);
this.stream.dispose(this.connectionId);
});
this.onStreamDriveFileCreated = file => {

View file

@ -40,7 +40,10 @@
<script>
this.mixin('i');
this.mixin('api');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.isLoading = true;
this.isEmpty = false;
@ -48,9 +51,9 @@
this.noFollowing = this.I.following_count == 0;
this.on('mount', () => {
this.stream.on('post', this.onStreamPost);
this.stream.on('follow', this.onStreamFollow);
this.stream.on('unfollow', this.onStreamUnfollow);
this.connection.on('post', this.onStreamPost);
this.connection.on('follow', this.onStreamFollow);
this.connection.on('unfollow', this.onStreamUnfollow);
document.addEventListener('keydown', this.onDocumentKeydown);
window.addEventListener('scroll', this.onScroll);
@ -59,9 +62,10 @@
});
this.on('unmount', () => {
this.stream.off('post', this.onStreamPost);
this.stream.off('follow', this.onStreamFollow);
this.stream.off('unfollow', this.onStreamUnfollow);
this.connection.off('post', this.onStreamPost);
this.connection.off('follow', this.onStreamFollow);
this.connection.off('unfollow', this.onStreamUnfollow);
this.stream.dispose(this.connectionId);
document.removeEventListener('keydown', this.onDocumentKeydown);
window.removeEventListener('scroll', this.onScroll);

View file

@ -212,9 +212,12 @@
this.mixin('i');
this.mixin('api');
this.mixin('stream');
this.mixin('user-preview');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.notifications = [];
this.loading = true;
@ -235,11 +238,12 @@
});
});
this.stream.on('notification', this.onNotification);
this.connection.on('notification', this.onNotification);
});
this.on('unmount', () => {
this.stream.off('notification', this.onNotification);
this.connection.off('notification', this.onNotification);
this.stream.dispose(this.connectionId);
});
this.on('update', () => {
@ -253,7 +257,7 @@
this.onNotification = notification => {
// TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない
this.stream.send({
this.connection.send({
type: 'read_notification',
id: notification.id
});

View file

@ -12,10 +12,12 @@
this.mixin('i');
this.mixin('api');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.unreadCount = 0;
this.page = this.opts.mode || 'timeline';
this.on('mount', () => {
@ -24,12 +26,14 @@
});
document.title = 'Misskey';
Progress.start();
this.stream.on('post', this.onStreamPost);
this.connection.on('post', this.onStreamPost);
document.addEventListener('visibilitychange', this.windowOnVisibilitychange, false);
});
this.on('unmount', () => {
this.stream.off('post', this.onStreamPost);
this.connection.off('post', this.onStreamPost);
this.stream.dispose(this.connectionId);
document.removeEventListener('visibilitychange', this.windowOnVisibilitychange);
});

View file

@ -430,9 +430,12 @@
this.mixin('i');
this.mixin('api');
this.mixin('stream');
this.mixin('user-preview');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.isDetailOpened = false;
this.set = post => {
@ -468,21 +471,21 @@
this.capture = withHandler => {
if (this.SIGNIN) {
this.stream.send({
this.connection.send({
type: 'capture',
id: this.post.id
});
if (withHandler) this.stream.on('post-updated', this.onStreamPostUpdated);
if (withHandler) this.connection.on('post-updated', this.onStreamPostUpdated);
}
};
this.decapture = withHandler => {
if (this.SIGNIN) {
this.stream.send({
this.connection.send({
type: 'decapture',
id: this.post.id
});
if (withHandler) this.stream.off('post-updated', this.onStreamPostUpdated);
if (withHandler) this.connection.off('post-updated', this.onStreamPostUpdated);
}
};
@ -490,7 +493,7 @@
this.capture(true);
if (this.SIGNIN) {
this.stream.on('_connected_', this.onStreamConnected);
this.connection.on('_connected_', this.onStreamConnected);
}
if (this.p.text) {
@ -515,7 +518,8 @@
this.on('unmount', () => {
this.decapture(true);
this.stream.off('_connected_', this.onStreamConnected);
this.connection.off('_connected_', this.onStreamConnected);
this.stream.dispose(this.connectionId);
});
this.reply = () => {

View file

@ -423,14 +423,17 @@
<script>
this.mixin('i');
this.mixin('api');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.page = this.opts.page;
this.on('mount', () => {
if (this.SIGNIN) {
this.stream.on('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.stream.on('unread_messaging_message', this.onUnreadMessagingMessage);
this.connection.on('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.connection.on('unread_messaging_message', this.onUnreadMessagingMessage);
// Fetch count of unread messaging messages
this.api('messaging/unread').then(res => {
@ -445,8 +448,9 @@
this.on('unmount', () => {
if (this.SIGNIN) {
this.stream.off('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.stream.off('unread_messaging_message', this.onUnreadMessagingMessage);
this.connection.off('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.connection.off('unread_messaging_message', this.onUnreadMessagingMessage);
this.stream.dispose(this.connectionId);
}
});