Sharkey/src/client/app/common/scripts/streaming/home.ts

112 lines
2.3 KiB
TypeScript
Raw Normal View History

2018-03-06 08:35:25 +09:00
import * as merge from 'object-assign-deep';
2017-06-09 01:03:54 +09:00
import Stream from './stream';
2018-03-07 17:48:32 +09:00
import StreamManager from './stream-manager';
2018-04-29 21:37:51 +09:00
import MiOS from '../../../mios';
2017-06-09 01:03:54 +09:00
/**
* Home stream connection
*/
2018-03-07 17:48:32 +09:00
export class HomeStream extends Stream {
2018-02-26 19:23:53 +09:00
constructor(os: MiOS, me) {
2018-03-15 19:53:46 +09:00
super(os, '', {
2018-04-08 03:58:11 +09:00
i: me.token
2017-06-09 01:03:54 +09:00
});
2017-08-30 17:45:23 +09:00
// 最終利用日時を更新するため定期的にaliveメッセージを送信
setInterval(() => {
this.send({ type: 'alive' });
2018-04-08 03:58:11 +09:00
me.lastUsedAt = new Date();
2017-08-30 17:45:23 +09:00
}, 1000 * 60);
2017-11-17 01:24:44 +09:00
// 自分の情報が更新されたとき
2018-02-21 15:30:03 +09:00
this.on('i_updated', i => {
2018-03-06 08:35:25 +09:00
if (os.debug) {
console.log('I updated:', i);
}
2018-04-29 17:17:15 +09:00
2018-05-27 13:49:09 +09:00
os.store.dispatch('mergeMe', i);
2018-04-29 17:17:15 +09:00
});
2018-05-29 01:22:39 +09:00
this.on('read_all_notifications', () => {
os.store.dispatch('mergeMe', {
hasUnreadNotification: false
});
});
this.on('unread_notification', () => {
os.store.dispatch('mergeMe', {
hasUnreadNotification: true
});
});
this.on('read_all_messaging_messages', () => {
os.store.dispatch('mergeMe', {
hasUnreadMessagingMessage: false
});
});
this.on('unread_messaging_message', () => {
os.store.dispatch('mergeMe', {
hasUnreadMessagingMessage: true
});
});
2018-04-29 17:17:15 +09:00
this.on('clientSettingUpdated', x => {
os.store.commit('settings/set', {
key: x.key,
value: x.value
});
});
this.on('home_updated', x => {
if (x.home) {
os.store.commit('settings/setHome', x.home);
} else {
os.store.commit('settings/setHomeWidget', {
id: x.id,
data: x.data
});
}
2018-02-21 15:30:03 +09:00
});
2017-08-28 23:47:43 +09:00
this.on('mobile_home_updated', x => {
if (x.home) {
os.store.commit('settings/setMobileHome', x.home);
} else {
os.store.commit('settings/setMobileHomeWidget', {
id: x.id,
data: x.data
});
}
});
2017-11-17 01:24:44 +09:00
// トークンが再生成されたとき
2018-04-29 17:17:15 +09:00
// このままではMisskeyが利用できないので強制的にサインアウトさせる
2017-11-17 03:28:37 +09:00
this.on('my_token_regenerated', () => {
2018-05-20 20:26:38 +09:00
alert('%i18n:common.my-token-regenerated%');
2018-02-26 19:23:53 +09:00
os.signout();
2017-08-28 23:47:43 +09:00
});
2017-06-09 01:03:54 +09:00
}
}
2018-03-07 17:48:32 +09:00
export class HomeStreamManager extends StreamManager<HomeStream> {
private me;
private os: MiOS;
constructor(os: MiOS, me) {
super();
this.me = me;
this.os = os;
}
public getConnection() {
if (this.connection == null) {
this.connection = new HomeStream(this.os, this.me);
}
return this.connection;
}
}