1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-12 21:58:58 +09:00
This commit is contained in:
syuilo 2018-05-29 02:31:32 +09:00
parent 9f1385b03a
commit 9d27fa7eaa

View File

@ -12,7 +12,7 @@
<a @click="messaging">
%fa:comments%
<p>%i18n:@messaging%</p>
<template v-if="hasUnreadMessagingMessages">%fa:circle%</template>
<template v-if="hasUnreadMessagingMessage">%fa:circle%</template>
</a>
</li>
<li class="game">
@ -35,48 +35,33 @@ import MkGameWindow from './game-window.vue';
export default Vue.extend({
data() {
return {
hasUnreadMessagingMessages: false,
hasGameInvitations: false,
connection: null,
connectionId: null
};
},
computed: {
hasUnreadMessagingMessage(): boolean {
return this.$store.getters.isSignedIn && this.$store.state.i.hasUnreadMessagingMessage;
}
},
mounted() {
if (this.$store.getters.isSignedIn) {
this.connection = (this as any).os.stream.getConnection();
this.connectionId = (this as any).os.stream.use();
this.connection.on('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.connection.on('unread_messaging_message', this.onUnreadMessagingMessage);
this.connection.on('othello_invited', this.onOthelloInvited);
this.connection.on('othello_no_invites', this.onOthelloNoInvites);
// Fetch count of unread messaging messages
(this as any).api('messaging/unread').then(res => {
if (res.count > 0) {
this.hasUnreadMessagingMessages = true;
}
});
}
},
beforeDestroy() {
if (this.$store.getters.isSignedIn) {
this.connection.off('read_all_messaging_messages', this.onReadAllMessagingMessages);
this.connection.off('unread_messaging_message', this.onUnreadMessagingMessage);
this.connection.off('othello_invited', this.onOthelloInvited);
this.connection.off('othello_no_invites', this.onOthelloNoInvites);
(this as any).os.stream.dispose(this.connectionId);
}
},
methods: {
onUnreadMessagingMessage() {
this.hasUnreadMessagingMessages = true;
},
onReadAllMessagingMessages() {
this.hasUnreadMessagingMessages = false;
},
onOthelloInvited() {
this.hasGameInvitations = true;
},