This commit is contained in:
syuilo
2018-05-29 01:22:39 +09:00
parent 973b1e42ef
commit ab16fb3a3f
13 changed files with 92 additions and 191 deletions

View File

@ -4,6 +4,7 @@ import { IMessagingMessage as IMessage } from '../../../models/messaging-message
import publishUserStream from '../../../publishers/stream';
import { publishMessagingStream } from '../../../publishers/stream';
import { publishMessagingIndexStream } from '../../../publishers/stream';
import User from '../../../models/user';
/**
* Mark as read message(s)
@ -62,6 +63,13 @@ export default (
});
if (count == 0) {
// Update flag
User.update({ _id: userId }, {
$set: {
hasUnreadMessagingMessage: false
}
});
// 全ての(いままで未読だった)自分宛てのメッセージを(これで)読みましたよというイベントを発行
publishUserStream(userId, 'read_all_messaging_messages');
}

View File

@ -2,6 +2,7 @@ import * as mongo from 'mongodb';
import { default as Notification, INotification } from '../../../models/notification';
import publishUserStream from '../../../publishers/stream';
import Mute from '../../../models/mute';
import User from '../../../models/user';
/**
* Mark as read notification(s)
@ -57,6 +58,13 @@ export default (
});
if (count == 0) {
// Update flag
User.update({ _id: userId }, {
$set: {
hasUnreadNotification: false
}
});
// 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
publishUserStream(userId, 'read_all_notifications');
}

View File

@ -279,11 +279,6 @@ const endpoints: Endpoint[] = [
kind: 'account/read'
},
{
name: 'notifications/get_unread_count',
withCredential: true,
kind: 'notification-read'
},
{
name: 'notifications/delete',
withCredential: true,
@ -610,11 +605,6 @@ const endpoints: Endpoint[] = [
withCredential: true,
kind: 'messaging-read'
},
{
name: 'messaging/unread',
withCredential: true,
kind: 'messaging-read'
},
{
name: 'messaging/messages',
withCredential: true,

View File

@ -1,6 +1,3 @@
/**
* Module dependencies
*/
import $ from 'cafy'; import ID from '../../../../cafy-id';
import Message from '../../../../models/messaging-message';
import User from '../../../../models/user';
@ -9,10 +6,6 @@ import read from '../../common/read-messaging-message';
/**
* Get messages
*
* @param {any} params
* @param {any} user
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'userId' parameter

View File

@ -91,6 +91,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
publishMessagingIndexStream(message.recipientId, 'message', messageObj);
publishUserStream(message.recipientId, 'messaging_message', messageObj);
// Update flag
User.update({ _id: recipient._id }, {
$set: {
hasUnreadMessagingMessage: true
}
});
// 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する
setTimeout(async () => {
const freshMessage = await Message.findOne({ _id: message._id }, { isRead: true });

View File

@ -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
});
});

View File

@ -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
});
});

View File

@ -1,8 +1,6 @@
/**
* Module dependencies
*/
import Notification from '../../../../models/notification';
import event from '../../../../publishers/stream';
import User from '../../../../models/user';
/**
* Mark as read all notifications
@ -23,6 +21,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Response
res();
// Update flag
User.update({ _id: user._id }, {
$set: {
hasUnreadNotification: false
}
});
// 全ての通知を読みましたよというイベントを発行
event(user._id, 'read_all_notifications');
});