mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-23 09:23:48 +01:00
This commit is contained in:
parent
0024e02f80
commit
7c35faf546
@ -28,6 +28,30 @@ export class HomeStream extends Stream {
|
|||||||
os.store.dispatch('mergeMe', i);
|
os.store.dispatch('mergeMe', i);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
this.on('clientSettingUpdated', x => {
|
this.on('clientSettingUpdated', x => {
|
||||||
os.store.commit('settings/set', {
|
os.store.commit('settings/set', {
|
||||||
key: x.key,
|
key: x.key,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="notifications">
|
<div class="notifications">
|
||||||
<button :data-active="isOpen" @click="toggle" title="%i18n:@title%">
|
<button :data-active="isOpen" @click="toggle" title="%i18n:@title%">
|
||||||
%fa:R bell%<template v-if="hasUnreadNotifications">%fa:circle%</template>
|
%fa:R bell%<template v-if="hasUnreadNotification">%fa:circle%</template>
|
||||||
</button>
|
</button>
|
||||||
<div class="pop" v-if="isOpen">
|
<div class="pop" v-if="isOpen">
|
||||||
<mk-notifications/>
|
<mk-notifications/>
|
||||||
@ -16,44 +16,15 @@ import contains from '../../../common/scripts/contains';
|
|||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isOpen: false,
|
isOpen: false
|
||||||
hasUnreadNotifications: false,
|
|
||||||
connection: null,
|
|
||||||
connectionId: null
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
computed: {
|
||||||
if (this.$store.getters.isSignedIn) {
|
hasUnreadNotification(): boolean {
|
||||||
this.connection = (this as any).os.stream.getConnection();
|
return this.$store.getters.isSignedIn && this.$store.state.i.hasUnreadNotification;
|
||||||
this.connectionId = (this as any).os.stream.use();
|
|
||||||
|
|
||||||
this.connection.on('read_all_notifications', this.onReadAllNotifications);
|
|
||||||
this.connection.on('unread_notification', this.onUnreadNotification);
|
|
||||||
|
|
||||||
// Fetch count of unread notifications
|
|
||||||
(this as any).api('notifications/get_unread_count').then(res => {
|
|
||||||
if (res.count > 0) {
|
|
||||||
this.hasUnreadNotifications = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
beforeDestroy() {
|
|
||||||
if (this.$store.getters.isSignedIn) {
|
|
||||||
this.connection.off('read_all_notifications', this.onReadAllNotifications);
|
|
||||||
this.connection.off('unread_notification', this.onUnreadNotification);
|
|
||||||
(this as any).os.stream.dispose(this.connectionId);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onReadAllNotifications() {
|
|
||||||
this.hasUnreadNotifications = false;
|
|
||||||
},
|
|
||||||
|
|
||||||
onUnreadNotification() {
|
|
||||||
this.hasUnreadNotifications = true;
|
|
||||||
},
|
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
this.isOpen ? this.close() : this.open();
|
this.isOpen ? this.close() : this.open();
|
||||||
},
|
},
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<p ref="welcomeback" v-if="$store.getters.isSignedIn">おかえりなさい、<b>{{ $store.state.i | userName }}</b>さん</p>
|
<p ref="welcomeback" v-if="$store.getters.isSignedIn">おかえりなさい、<b>{{ $store.state.i | userName }}</b>さん</p>
|
||||||
<div class="content" ref="mainContainer">
|
<div class="content" ref="mainContainer">
|
||||||
<button class="nav" @click="$parent.isDrawerOpening = true">%fa:bars%</button>
|
<button class="nav" @click="$parent.isDrawerOpening = true">%fa:bars%</button>
|
||||||
<template v-if="hasUnreadNotifications || hasUnreadMessagingMessages || hasGameInvitations">%fa:circle%</template>
|
<template v-if="hasUnreadNotification || hasUnreadMessagingMessage || hasGameInvitation">%fa:circle%</template>
|
||||||
<h1>
|
<h1>
|
||||||
<slot>Misskey</slot>
|
<slot>Misskey</slot>
|
||||||
</h1>
|
</h1>
|
||||||
@ -25,13 +25,19 @@ export default Vue.extend({
|
|||||||
props: ['func'],
|
props: ['func'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
hasUnreadNotifications: false,
|
hasGameInvitation: false,
|
||||||
hasUnreadMessagingMessages: false,
|
|
||||||
hasGameInvitations: false,
|
|
||||||
connection: null,
|
connection: null,
|
||||||
connectionId: null
|
connectionId: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
hasUnreadNotification(): boolean {
|
||||||
|
return this.$store.getters.isSignedIn && this.$store.state.i.hasUnreadNotification;
|
||||||
|
},
|
||||||
|
hasUnreadMessagingMessage(): boolean {
|
||||||
|
return this.$store.getters.isSignedIn && this.$store.state.i.hasUnreadMessagingMessage;
|
||||||
|
}
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$store.commit('setUiHeaderHeight', 48);
|
this.$store.commit('setUiHeaderHeight', 48);
|
||||||
|
|
||||||
@ -39,27 +45,9 @@ export default Vue.extend({
|
|||||||
this.connection = (this as any).os.stream.getConnection();
|
this.connection = (this as any).os.stream.getConnection();
|
||||||
this.connectionId = (this as any).os.stream.use();
|
this.connectionId = (this as any).os.stream.use();
|
||||||
|
|
||||||
this.connection.on('read_all_notifications', this.onReadAllNotifications);
|
|
||||||
this.connection.on('unread_notification', this.onUnreadNotification);
|
|
||||||
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_invited', this.onOthelloInvited);
|
||||||
this.connection.on('othello_no_invites', this.onOthelloNoInvites);
|
this.connection.on('othello_no_invites', this.onOthelloNoInvites);
|
||||||
|
|
||||||
// Fetch count of unread notifications
|
|
||||||
(this as any).api('notifications/get_unread_count').then(res => {
|
|
||||||
if (res.count > 0) {
|
|
||||||
this.hasUnreadNotifications = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fetch count of unread messaging messages
|
|
||||||
(this as any).api('messaging/unread').then(res => {
|
|
||||||
if (res.count > 0) {
|
|
||||||
this.hasUnreadMessagingMessages = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const ago = (new Date().getTime() - new Date(this.$store.state.i.lastUsedAt).getTime()) / 1000;
|
const ago = (new Date().getTime() - new Date(this.$store.state.i.lastUsedAt).getTime()) / 1000;
|
||||||
const isHisasiburi = ago >= 3600;
|
const isHisasiburi = ago >= 3600;
|
||||||
this.$store.state.i.lastUsedAt = new Date();
|
this.$store.state.i.lastUsedAt = new Date();
|
||||||
@ -110,33 +98,17 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
if (this.$store.getters.isSignedIn) {
|
if (this.$store.getters.isSignedIn) {
|
||||||
this.connection.off('read_all_notifications', this.onReadAllNotifications);
|
|
||||||
this.connection.off('unread_notification', this.onUnreadNotification);
|
|
||||||
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_invited', this.onOthelloInvited);
|
||||||
this.connection.off('othello_no_invites', this.onOthelloNoInvites);
|
this.connection.off('othello_no_invites', this.onOthelloNoInvites);
|
||||||
(this as any).os.stream.dispose(this.connectionId);
|
(this as any).os.stream.dispose(this.connectionId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onReadAllNotifications() {
|
|
||||||
this.hasUnreadNotifications = false;
|
|
||||||
},
|
|
||||||
onUnreadNotification() {
|
|
||||||
this.hasUnreadNotifications = true;
|
|
||||||
},
|
|
||||||
onReadAllMessagingMessages() {
|
|
||||||
this.hasUnreadMessagingMessages = false;
|
|
||||||
},
|
|
||||||
onUnreadMessagingMessage() {
|
|
||||||
this.hasUnreadMessagingMessages = true;
|
|
||||||
},
|
|
||||||
onOthelloInvited() {
|
onOthelloInvited() {
|
||||||
this.hasGameInvitations = true;
|
this.hasGameInvitation = true;
|
||||||
},
|
},
|
||||||
onOthelloNoInvites() {
|
onOthelloNoInvites() {
|
||||||
this.hasGameInvitations = false;
|
this.hasGameInvitation = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<div class="links">
|
<div class="links">
|
||||||
<ul>
|
<ul>
|
||||||
<li><router-link to="/" :data-active="$route.name == 'index'">%fa:home%%i18n:@home%%fa:angle-right%</router-link></li>
|
<li><router-link to="/" :data-active="$route.name == 'index'">%fa:home%%i18n:@home%%fa:angle-right%</router-link></li>
|
||||||
<li><router-link to="/i/notifications" :data-active="$route.name == 'notifications'">%fa:R bell%%i18n:@notifications%<template v-if="hasUnreadNotifications">%fa:circle%</template>%fa:angle-right%</router-link></li>
|
<li><router-link to="/i/notifications" :data-active="$route.name == 'notifications'">%fa:R bell%%i18n:@notifications%<template v-if="hasUnreadNotification">%fa:circle%</template>%fa:angle-right%</router-link></li>
|
||||||
<li><router-link to="/i/messaging" :data-active="$route.name == 'messaging'">%fa:R comments%%i18n:@messaging%<template v-if="hasUnreadMessagingMessages">%fa:circle%</template>%fa:angle-right%</router-link></li>
|
<li><router-link to="/i/messaging" :data-active="$route.name == 'messaging'">%fa:R comments%%i18n:@messaging%<template v-if="hasUnreadMessagingMessages">%fa:circle%</template>%fa:angle-right%</router-link></li>
|
||||||
<li><router-link to="/othello" :data-active="$route.name == 'othello'">%fa:gamepad%ゲーム<template v-if="hasGameInvitations">%fa:circle%</template>%fa:angle-right%</router-link></li>
|
<li><router-link to="/othello" :data-active="$route.name == 'othello'">%fa:gamepad%ゲーム<template v-if="hasGameInvitations">%fa:circle%</template>%fa:angle-right%</router-link></li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -46,47 +46,31 @@ export default Vue.extend({
|
|||||||
props: ['isOpen'],
|
props: ['isOpen'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
hasUnreadNotifications: false,
|
hasGameInvitation: false,
|
||||||
hasUnreadMessagingMessages: false,
|
|
||||||
hasGameInvitations: false,
|
|
||||||
connection: null,
|
connection: null,
|
||||||
connectionId: null,
|
connectionId: null,
|
||||||
aboutUrl: `${docsUrl}/${lang}/about`
|
aboutUrl: `${docsUrl}/${lang}/about`
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
hasUnreadNotification(): boolean {
|
||||||
|
return this.$store.getters.isSignedIn && this.$store.state.i.hasUnreadNotification;
|
||||||
|
},
|
||||||
|
hasUnreadMessagingMessage(): boolean {
|
||||||
|
return this.$store.getters.isSignedIn && this.$store.state.i.hasUnreadMessagingMessage;
|
||||||
|
}
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.$store.getters.isSignedIn) {
|
if (this.$store.getters.isSignedIn) {
|
||||||
this.connection = (this as any).os.stream.getConnection();
|
this.connection = (this as any).os.stream.getConnection();
|
||||||
this.connectionId = (this as any).os.stream.use();
|
this.connectionId = (this as any).os.stream.use();
|
||||||
|
|
||||||
this.connection.on('read_all_notifications', this.onReadAllNotifications);
|
|
||||||
this.connection.on('unread_notification', this.onUnreadNotification);
|
|
||||||
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_invited', this.onOthelloInvited);
|
||||||
this.connection.on('othello_no_invites', this.onOthelloNoInvites);
|
this.connection.on('othello_no_invites', this.onOthelloNoInvites);
|
||||||
|
|
||||||
// Fetch count of unread notifications
|
|
||||||
(this as any).api('notifications/get_unread_count').then(res => {
|
|
||||||
if (res.count > 0) {
|
|
||||||
this.hasUnreadNotifications = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fetch count of unread messaging messages
|
|
||||||
(this as any).api('messaging/unread').then(res => {
|
|
||||||
if (res.count > 0) {
|
|
||||||
this.hasUnreadMessagingMessages = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
if (this.$store.getters.isSignedIn) {
|
if (this.$store.getters.isSignedIn) {
|
||||||
this.connection.off('read_all_notifications', this.onReadAllNotifications);
|
|
||||||
this.connection.off('unread_notification', this.onUnreadNotification);
|
|
||||||
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_invited', this.onOthelloInvited);
|
||||||
this.connection.off('othello_no_invites', this.onOthelloNoInvites);
|
this.connection.off('othello_no_invites', this.onOthelloNoInvites);
|
||||||
(this as any).os.stream.dispose(this.connectionId);
|
(this as any).os.stream.dispose(this.connectionId);
|
||||||
@ -98,23 +82,11 @@ export default Vue.extend({
|
|||||||
if (query == null || query == '') return;
|
if (query == null || query == '') return;
|
||||||
this.$router.push('/search?q=' + encodeURIComponent(query));
|
this.$router.push('/search?q=' + encodeURIComponent(query));
|
||||||
},
|
},
|
||||||
onReadAllNotifications() {
|
|
||||||
this.hasUnreadNotifications = false;
|
|
||||||
},
|
|
||||||
onUnreadNotification() {
|
|
||||||
this.hasUnreadNotifications = true;
|
|
||||||
},
|
|
||||||
onReadAllMessagingMessages() {
|
|
||||||
this.hasUnreadMessagingMessages = false;
|
|
||||||
},
|
|
||||||
onUnreadMessagingMessage() {
|
|
||||||
this.hasUnreadMessagingMessages = true;
|
|
||||||
},
|
|
||||||
onOthelloInvited() {
|
onOthelloInvited() {
|
||||||
this.hasGameInvitations = true;
|
this.hasGameInvitation = true;
|
||||||
},
|
},
|
||||||
onOthelloNoInvites() {
|
onOthelloNoInvites() {
|
||||||
this.hasGameInvitations = false;
|
this.hasGameInvitation = false;
|
||||||
},
|
},
|
||||||
dark() {
|
dark() {
|
||||||
this.$store.commit('device/set', {
|
this.$store.commit('device/set', {
|
||||||
|
@ -3,6 +3,7 @@ import Notification from '../models/notification';
|
|||||||
import Mute from '../models/mute';
|
import Mute from '../models/mute';
|
||||||
import { pack } from '../models/notification';
|
import { pack } from '../models/notification';
|
||||||
import stream from './stream';
|
import stream from './stream';
|
||||||
|
import User from '../models/user';
|
||||||
|
|
||||||
export default (
|
export default (
|
||||||
notifiee: mongo.ObjectID,
|
notifiee: mongo.ObjectID,
|
||||||
@ -29,6 +30,13 @@ export default (
|
|||||||
stream(notifiee, 'notification',
|
stream(notifiee, 'notification',
|
||||||
await pack(notification));
|
await pack(notification));
|
||||||
|
|
||||||
|
// Update flag
|
||||||
|
User.update({ _id: notifiee }, {
|
||||||
|
$set: {
|
||||||
|
hasUnreadNotification: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
|
// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const fresh = await Notification.findOne({ _id: notification._id }, { isRead: true });
|
const fresh = await Notification.findOne({ _id: notification._id }, { isRead: true });
|
||||||
|
@ -4,6 +4,7 @@ import { IMessagingMessage as IMessage } from '../../../models/messaging-message
|
|||||||
import publishUserStream from '../../../publishers/stream';
|
import publishUserStream from '../../../publishers/stream';
|
||||||
import { publishMessagingStream } from '../../../publishers/stream';
|
import { publishMessagingStream } from '../../../publishers/stream';
|
||||||
import { publishMessagingIndexStream } from '../../../publishers/stream';
|
import { publishMessagingIndexStream } from '../../../publishers/stream';
|
||||||
|
import User from '../../../models/user';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark as read message(s)
|
* Mark as read message(s)
|
||||||
@ -62,6 +63,13 @@ export default (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
// Update flag
|
||||||
|
User.update({ _id: userId }, {
|
||||||
|
$set: {
|
||||||
|
hasUnreadMessagingMessage: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 全ての(いままで未読だった)自分宛てのメッセージを(これで)読みましたよというイベントを発行
|
// 全ての(いままで未読だった)自分宛てのメッセージを(これで)読みましたよというイベントを発行
|
||||||
publishUserStream(userId, 'read_all_messaging_messages');
|
publishUserStream(userId, 'read_all_messaging_messages');
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import * as mongo from 'mongodb';
|
|||||||
import { default as Notification, INotification } from '../../../models/notification';
|
import { default as Notification, INotification } from '../../../models/notification';
|
||||||
import publishUserStream from '../../../publishers/stream';
|
import publishUserStream from '../../../publishers/stream';
|
||||||
import Mute from '../../../models/mute';
|
import Mute from '../../../models/mute';
|
||||||
|
import User from '../../../models/user';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark as read notification(s)
|
* Mark as read notification(s)
|
||||||
@ -57,6 +58,13 @@ export default (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
// Update flag
|
||||||
|
User.update({ _id: userId }, {
|
||||||
|
$set: {
|
||||||
|
hasUnreadNotification: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
|
// 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
|
||||||
publishUserStream(userId, 'read_all_notifications');
|
publishUserStream(userId, 'read_all_notifications');
|
||||||
}
|
}
|
||||||
|
@ -279,11 +279,6 @@ const endpoints: Endpoint[] = [
|
|||||||
kind: 'account/read'
|
kind: 'account/read'
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
name: 'notifications/get_unread_count',
|
|
||||||
withCredential: true,
|
|
||||||
kind: 'notification-read'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'notifications/delete',
|
name: 'notifications/delete',
|
||||||
withCredential: true,
|
withCredential: true,
|
||||||
@ -610,11 +605,6 @@ const endpoints: Endpoint[] = [
|
|||||||
withCredential: true,
|
withCredential: true,
|
||||||
kind: 'messaging-read'
|
kind: 'messaging-read'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'messaging/unread',
|
|
||||||
withCredential: true,
|
|
||||||
kind: 'messaging-read'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'messaging/messages',
|
name: 'messaging/messages',
|
||||||
withCredential: true,
|
withCredential: true,
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
/**
|
|
||||||
* Module dependencies
|
|
||||||
*/
|
|
||||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||||
import Message from '../../../../models/messaging-message';
|
import Message from '../../../../models/messaging-message';
|
||||||
import User from '../../../../models/user';
|
import User from '../../../../models/user';
|
||||||
@ -9,10 +6,6 @@ import read from '../../common/read-messaging-message';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get messages
|
* Get messages
|
||||||
*
|
|
||||||
* @param {any} params
|
|
||||||
* @param {any} user
|
|
||||||
* @return {Promise<any>}
|
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
|
@ -91,6 +91,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||||||
publishMessagingIndexStream(message.recipientId, 'message', messageObj);
|
publishMessagingIndexStream(message.recipientId, 'message', messageObj);
|
||||||
publishUserStream(message.recipientId, 'messaging_message', messageObj);
|
publishUserStream(message.recipientId, 'messaging_message', messageObj);
|
||||||
|
|
||||||
|
// Update flag
|
||||||
|
User.update({ _id: recipient._id }, {
|
||||||
|
$set: {
|
||||||
|
hasUnreadMessagingMessage: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する
|
// 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const freshMessage = await Message.findOne({ _id: message._id }, { isRead: true });
|
const freshMessage = await Message.findOne({ _id: message._id }, { isRead: true });
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/**
|
|
||||||
* Module dependencies
|
|
||||||
*/
|
|
||||||
import Message from '../../../../models/messaging-message';
|
|
||||||
import Mute from '../../../../models/mute';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get count of unread messages
|
|
||||||
*/
|
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
|
||||||
const mute = await Mute.find({
|
|
||||||
muterId: user._id,
|
|
||||||
deletedAt: { $exists: false }
|
|
||||||
});
|
|
||||||
const mutedUserIds = mute.map(m => m.muteeId);
|
|
||||||
|
|
||||||
const count = await Message
|
|
||||||
.count({
|
|
||||||
userId: {
|
|
||||||
$nin: mutedUserIds
|
|
||||||
},
|
|
||||||
recipientId: user._id,
|
|
||||||
isRead: false
|
|
||||||
});
|
|
||||||
|
|
||||||
res({
|
|
||||||
count: count
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Module dependencies
|
|
||||||
*/
|
|
||||||
import Notification from '../../../../models/notification';
|
|
||||||
import Mute from '../../../../models/mute';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get count of unread notifications
|
|
||||||
*/
|
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
|
||||||
const mute = await Mute.find({
|
|
||||||
muterId: user._id
|
|
||||||
});
|
|
||||||
const mutedUserIds = mute.map(m => m.muteeId);
|
|
||||||
|
|
||||||
const count = await Notification
|
|
||||||
.count({
|
|
||||||
notifieeId: user._id,
|
|
||||||
notifierId: {
|
|
||||||
$nin: mutedUserIds
|
|
||||||
},
|
|
||||||
isRead: false
|
|
||||||
});
|
|
||||||
|
|
||||||
res({
|
|
||||||
count: count
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,8 +1,6 @@
|
|||||||
/**
|
|
||||||
* Module dependencies
|
|
||||||
*/
|
|
||||||
import Notification from '../../../../models/notification';
|
import Notification from '../../../../models/notification';
|
||||||
import event from '../../../../publishers/stream';
|
import event from '../../../../publishers/stream';
|
||||||
|
import User from '../../../../models/user';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark as read all notifications
|
* Mark as read all notifications
|
||||||
@ -23,6 +21,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||||||
// Response
|
// Response
|
||||||
res();
|
res();
|
||||||
|
|
||||||
|
// Update flag
|
||||||
|
User.update({ _id: user._id }, {
|
||||||
|
$set: {
|
||||||
|
hasUnreadNotification: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 全ての通知を読みましたよというイベントを発行
|
// 全ての通知を読みましたよというイベントを発行
|
||||||
event(user._id, 'read_all_notifications');
|
event(user._id, 'read_all_notifications');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user