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

103 lines
2.1 KiB
TypeScript
Raw Normal View History

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