Fix bug and refactor

This commit is contained in:
syuilo 2018-10-09 15:08:31 +09:00
parent ba1c823fb1
commit 136b13e7ca
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
10 changed files with 101 additions and 104 deletions

View file

@ -26,92 +26,6 @@ export default class Stream extends EventEmitter {
this.stream.addEventListener('open', this.onOpen); this.stream.addEventListener('open', this.onOpen);
this.stream.addEventListener('close', this.onClose); this.stream.addEventListener('close', this.onClose);
this.stream.addEventListener('message', this.onMessage); this.stream.addEventListener('message', this.onMessage);
if (user) {
const main = this.useSharedConnection('main');
// 自分の情報が更新されたとき
main.on('meUpdated', i => {
os.store.dispatch('mergeMe', i);
});
main.on('readAllNotifications', () => {
os.store.dispatch('mergeMe', {
hasUnreadNotification: false
});
});
main.on('unreadNotification', () => {
os.store.dispatch('mergeMe', {
hasUnreadNotification: true
});
});
main.on('readAllMessagingMessages', () => {
os.store.dispatch('mergeMe', {
hasUnreadMessagingMessage: false
});
});
main.on('unreadMessagingMessage', () => {
os.store.dispatch('mergeMe', {
hasUnreadMessagingMessage: true
});
});
main.on('unreadMention', () => {
os.store.dispatch('mergeMe', {
hasUnreadMentions: true
});
});
main.on('readAllUnreadMentions', () => {
os.store.dispatch('mergeMe', {
hasUnreadMentions: false
});
});
main.on('unreadSpecifiedNote', () => {
os.store.dispatch('mergeMe', {
hasUnreadSpecifiedNotes: true
});
});
main.on('readAllUnreadSpecifiedNotes', () => {
os.store.dispatch('mergeMe', {
hasUnreadSpecifiedNotes: false
});
});
main.on('clientSettingUpdated', x => {
os.store.commit('settings/set', {
key: x.key,
value: x.value
});
});
main.on('homeUpdated', x => {
os.store.commit('settings/setHome', x);
});
main.on('mobileHomeUpdated', x => {
os.store.commit('settings/setMobileHome', x);
});
main.on('widgetUpdated', x => {
os.store.commit('settings/setWidget', {
id: x.id,
data: x.data
});
});
// トークンが再生成されたとき
// このままではMisskeyが利用できないので強制的にサインアウトさせる
main.on('myTokenRegenerated', () => {
alert('%i18n:common.my-token-regenerated%');
os.signout();
});
}
} }
public useSharedConnection = (channel: string): SharedConnection => { public useSharedConnection = (channel: string): SharedConnection => {

View file

@ -71,8 +71,7 @@ export default Vue.extend({
this.pingClock = setInterval(() => { this.pingClock = setInterval(() => {
if (this.matching) { if (this.matching) {
this.connection.send({ this.connection.send('ping', {
type: 'ping',
id: this.matching.id id: this.matching.id
}); });
} }

View file

@ -113,8 +113,7 @@ export default define({
this.connection.on('stats', this.onStats); this.connection.on('stats', this.onStats);
this.connection.on('statsLog', this.onStatsLog); this.connection.on('statsLog', this.onStatsLog);
this.connection.send({ this.connection.send('requestLog',{
type: 'requestLog',
id: Math.random().toString() id: Math.random().toString()
}); });
}, },

View file

@ -91,8 +91,7 @@ export default Vue.extend({
mounted() { mounted() {
this.connection.on('stats', this.onStats); this.connection.on('stats', this.onStats);
this.connection.on('statsLog', this.onStatsLog); this.connection.on('statsLog', this.onStatsLog);
this.connection.send({ this.connection.send('requestLog', {
type: 'requestLog',
id: Math.random().toString() id: Math.random().toString()
}); });
}, },

View file

@ -181,8 +181,7 @@ export default Vue.extend({
onNotification(notification) { onNotification(notification) {
// TODO: () // TODO: ()
this.connection.send({ (this as any).os.stream.send('readNotification', {
type: 'readNotification',
id: notification.id id: notification.id
}); });

View file

@ -77,8 +77,7 @@ export default Vue.extend({
mounted() { mounted() {
this.connection.on('stats', this.onStats); this.connection.on('stats', this.onStats);
this.connection.on('statsLog', this.onStatsLog); this.connection.on('statsLog', this.onStatsLog);
this.connection.send({ this.connection.send('requestLog', {
type: 'requestLog',
id: Math.random().toString(), id: Math.random().toString(),
length: 200 length: 200
}); });

View file

@ -113,8 +113,7 @@ export default Vue.extend({
onNotification(notification) { onNotification(notification) {
// TODO: () // TODO: ()
this.connection.send({ (this as any).os.stream.send('readNotification', {
type: 'readNotification',
id: notification.id id: notification.id
}); });

View file

@ -212,7 +212,7 @@ export default class MiOS extends EventEmitter {
const fetched = () => { const fetched = () => {
this.emit('signedin'); this.emit('signedin');
this.stream = new Stream(this); this.initStream();
// Finish init // Finish init
callback(); callback();
@ -247,12 +247,103 @@ export default class MiOS extends EventEmitter {
// Finish init // Finish init
callback(); callback();
this.stream = new Stream(this); this.initStream();
} }
}); });
} }
} }
@autobind
private initStream() {
this.stream = new Stream(this);
if (this.store.getters.isSignedIn) {
const main = this.stream.useSharedConnection('main');
// 自分の情報が更新されたとき
main.on('meUpdated', i => {
this.store.dispatch('mergeMe', i);
});
main.on('readAllNotifications', () => {
this.store.dispatch('mergeMe', {
hasUnreadNotification: false
});
});
main.on('unreadNotification', () => {
this.store.dispatch('mergeMe', {
hasUnreadNotification: true
});
});
main.on('readAllMessagingMessages', () => {
this.store.dispatch('mergeMe', {
hasUnreadMessagingMessage: false
});
});
main.on('unreadMessagingMessage', () => {
this.store.dispatch('mergeMe', {
hasUnreadMessagingMessage: true
});
});
main.on('unreadMention', () => {
this.store.dispatch('mergeMe', {
hasUnreadMentions: true
});
});
main.on('readAllUnreadMentions', () => {
this.store.dispatch('mergeMe', {
hasUnreadMentions: false
});
});
main.on('unreadSpecifiedNote', () => {
this.store.dispatch('mergeMe', {
hasUnreadSpecifiedNotes: true
});
});
main.on('readAllUnreadSpecifiedNotes', () => {
this.store.dispatch('mergeMe', {
hasUnreadSpecifiedNotes: false
});
});
main.on('clientSettingUpdated', x => {
this.store.commit('settings/set', {
key: x.key,
value: x.value
});
});
main.on('homeUpdated', x => {
this.store.commit('settings/setHome', x);
});
main.on('mobileHomeUpdated', x => {
this.store.commit('settings/setMobileHome', x);
});
main.on('widgetUpdated', x => {
this.store.commit('settings/setWidget', {
id: x.id,
data: x.data
});
});
// トークンが再生成されたとき
// このままではMisskeyが利用できないので強制的にサインアウトさせる
main.on('myTokenRegenerated', () => {
alert('%i18n:common.my-token-regenerated%');
this.signout();
});
}
}
/** /**
* Register service worker * Register service worker
*/ */

View file

@ -98,8 +98,7 @@ export default Vue.extend({
onNotification(notification) { onNotification(notification) {
// TODO: () // TODO: ()
this.connection.send({ (this as any).os.stream.send('readNotification', {
type: 'readNotification',
id: notification.id id: notification.id
}); });

View file

@ -58,8 +58,7 @@ export default Vue.extend({
methods: { methods: {
onNotification(notification) { onNotification(notification) {
// TODO: () // TODO: ()
this.connection.send({ (this as any).os.stream.send('readNotification', {
type: 'readNotification',
id: notification.id id: notification.id
}); });