#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

@ -52,7 +52,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)
@ -67,14 +70,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

@ -12,7 +12,10 @@
<script>
this.mixin('i');
this.mixin('api');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.noFollowing = this.I.following_count == 0;
@ -30,15 +33,16 @@
};
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);
});
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);
});
this.more = () => {

View File

@ -82,7 +82,10 @@
this.getPostSummary = getPostSummary;
this.mixin('api');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.notifications = [];
this.loading = true;
@ -106,11 +109,12 @@
this.trigger('fetched');
});
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', () => {
@ -124,7 +128,7 @@
this.onNotification = notification => {
// TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない
this.stream.send({
this.connection.send({
type: 'read_notification',
id: notification.id
});

View File

@ -13,7 +13,10 @@
import openPostForm from '../../scripts/open-post-form';
this.mixin('i');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.unreadCount = 0;
@ -28,7 +31,7 @@
Progress.start();
this.stream.on('post', this.onStreamPost);
this.connection.on('post', this.onStreamPost);
document.addEventListener('visibilitychange', this.onVisibilitychange, false);
this.refs.ui.refs.home.on('loaded', () => {
@ -37,7 +40,8 @@
});
this.on('unmount', () => {
this.stream.off('post', this.onStreamPost);
this.connection.off('post', this.onStreamPost);
this.stream.dispose(this.connectionId);
document.removeEventListener('visibilitychange', this.onVisibilitychange);
});

View File

@ -473,7 +473,10 @@
this.mixin('i');
this.mixin('api');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.set = post => {
this.post = post;
@ -508,21 +511,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);
}
};
@ -530,7 +533,7 @@
this.capture(true);
if (this.SIGNIN) {
this.stream.on('_connected_', this.onStreamConnected);
this.connection.on('_connected_', this.onStreamConnected);
}
if (this.p.text) {
@ -555,7 +558,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

@ -12,16 +12,20 @@
</style>
<script>
this.mixin('i');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.isDrawerOpening = false;
this.on('mount', () => {
this.stream.on('notification', this.onStreamNotification);
this.connection.on('notification', this.onStreamNotification);
});
this.on('unmount', () => {
this.stream.off('notification', this.onStreamNotification);
this.connection.off('notification', this.onStreamNotification);
this.stream.dispose(this.connectionId);
});
this.toggleDrawer = () => {
@ -31,7 +35,7 @@
this.onStreamNotification = notification => {
// TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない
this.stream.send({
this.connection.send({
type: 'read_notification',
id: notification.id
});
@ -145,15 +149,18 @@
import ui from '../scripts/ui-event';
this.mixin('api');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.func = null;
this.funcIcon = null;
this.on('mount', () => {
this.stream.on('read_all_notifications', this.onReadAllNotifications);
this.stream.on('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.stream.on('unread_messaging_message', this.onUnreadMessagingMessage);
this.connection.on('read_all_notifications', this.onReadAllNotifications);
this.connection.on('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.connection.on('unread_messaging_message', this.onUnreadMessagingMessage);
// Fetch count of unread notifications
this.api('notifications/get_unread_count').then(res => {
@ -175,9 +182,10 @@
});
this.on('unmount', () => {
this.stream.off('read_all_notifications', this.onReadAllNotifications);
this.stream.off('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.stream.off('unread_messaging_message', this.onUnreadMessagingMessage);
this.connection.off('read_all_notifications', this.onReadAllNotifications);
this.connection.off('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.connection.off('unread_messaging_message', this.onUnreadMessagingMessage);
this.stream.dispose(this.connectionId);
ui.off('title', this.setTitle);
ui.off('func', this.setFunc);
@ -348,12 +356,15 @@
this.mixin('i');
this.mixin('page');
this.mixin('api');
this.mixin('stream');
this.connection = this.stream.getConnection();
this.connectionId = this.stream.use();
this.on('mount', () => {
this.stream.on('read_all_notifications', this.onReadAllNotifications);
this.stream.on('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.stream.on('unread_messaging_message', this.onUnreadMessagingMessage);
this.connection.on('read_all_notifications', this.onReadAllNotifications);
this.connection.on('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.connection.on('unread_messaging_message', this.onUnreadMessagingMessage);
// Fetch count of unread notifications
this.api('notifications/get_unread_count').then(res => {
@ -375,9 +386,10 @@
});
this.on('unmount', () => {
this.stream.off('read_all_notifications', this.onReadAllNotifications);
this.stream.off('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.stream.off('unread_messaging_message', this.onUnreadMessagingMessage);
this.connection.off('read_all_notifications', this.onReadAllNotifications);
this.connection.off('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.connection.off('unread_messaging_message', this.onUnreadMessagingMessage);
this.stream.dispose(this.connectionId);
});
this.onReadAllNotifications = () => {