summaryrefslogtreecommitdiff
path: root/src/api/endpoints/messaging
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/endpoints/messaging')
-rw-r--r--src/api/endpoints/messaging/history.ts15
-rw-r--r--src/api/endpoints/messaging/messages.ts20
-rw-r--r--src/api/endpoints/messaging/messages/create.ts16
-rw-r--r--src/api/endpoints/messaging/unread.ts10
4 files changed, 46 insertions, 15 deletions
diff --git a/src/api/endpoints/messaging/history.ts b/src/api/endpoints/messaging/history.ts
index 5f7c9276dd..1683ca7a89 100644
--- a/src/api/endpoints/messaging/history.ts
+++ b/src/api/endpoints/messaging/history.ts
@@ -3,7 +3,8 @@
*/
import $ from 'cafy';
import History from '../../models/messaging-history';
-import serialize from '../../serializers/messaging-message';
+import Mute from '../../models/mute';
+import { pack } from '../../models/messaging-message';
/**
* Show messaging history
@@ -17,10 +18,18 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param');
+ const mute = await Mute.find({
+ muter_id: user._id,
+ deleted_at: { $exists: false }
+ });
+
// Get history
const history = await History
.find({
- user_id: user._id
+ user_id: user._id,
+ partner: {
+ $nin: mute.map(m => m.mutee_id)
+ }
}, {
limit: limit,
sort: {
@@ -30,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(history.map(async h =>
- await serialize(h.message, user))));
+ await pack(h.message, user))));
});
diff --git a/src/api/endpoints/messaging/messages.ts b/src/api/endpoints/messaging/messages.ts
index 7b270924eb..67ba5e9d6d 100644
--- a/src/api/endpoints/messaging/messages.ts
+++ b/src/api/endpoints/messaging/messages.ts
@@ -4,7 +4,7 @@
import $ from 'cafy';
import Message from '../../models/messaging-message';
import User from '../../models/user';
-import serialize from '../../serializers/messaging-message';
+import { pack } from '../../models/messaging-message';
import read from '../../common/read-messaging-message';
/**
@@ -44,13 +44,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param');
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) return rej('invalid max_id param');
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) return rej('invalid until_id param');
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- return rej('cannot set since_id and max_id');
+ // Check if both of since_id and until_id is specified
+ if (sinceId && untilId) {
+ return rej('cannot set since_id and until_id');
}
const query = {
@@ -72,9 +72,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
}
@@ -87,7 +87,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Serialize
res(await Promise.all(messages.map(async message =>
- await serialize(message, user, {
+ await pack(message, user, {
populateRecipient: false
}))));
diff --git a/src/api/endpoints/messaging/messages/create.ts b/src/api/endpoints/messaging/messages/create.ts
index 3c7689f967..1b8a5f59e6 100644
--- a/src/api/endpoints/messaging/messages/create.ts
+++ b/src/api/endpoints/messaging/messages/create.ts
@@ -6,8 +6,9 @@ import Message from '../../../models/messaging-message';
import { isValidText } from '../../../models/messaging-message';
import History from '../../../models/messaging-history';
import User from '../../../models/user';
+import Mute from '../../../models/mute';
import DriveFile from '../../../models/drive-file';
-import serialize from '../../../serializers/messaging-message';
+import { pack } from '../../../models/messaging-message';
import publishUserStream from '../../../event';
import { publishMessagingStream, publishMessagingIndexStream, pushSw } from '../../../event';
import config from '../../../../conf';
@@ -78,7 +79,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- const messageObj = await serialize(message);
+ const messageObj = await pack(message);
// Reponse
res(messageObj);
@@ -97,6 +98,17 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
setTimeout(async () => {
const freshMessage = await Message.findOne({ _id: message._id }, { is_read: true });
if (!freshMessage.is_read) {
+ //#region ただしミュートされているなら発行しない
+ const mute = await Mute.find({
+ muter_id: recipient._id,
+ deleted_at: { $exists: false }
+ });
+ const mutedUserIds = mute.map(m => m.mutee_id.toString());
+ if (mutedUserIds.indexOf(user._id.toString()) != -1) {
+ return;
+ }
+ //#endregion
+
publishUserStream(message.recipient_id, 'unread_messaging_message', messageObj);
pushSw(message.recipient_id, 'unread_messaging_message', messageObj);
}
diff --git a/src/api/endpoints/messaging/unread.ts b/src/api/endpoints/messaging/unread.ts
index 40bc83fe1c..c4326e1d22 100644
--- a/src/api/endpoints/messaging/unread.ts
+++ b/src/api/endpoints/messaging/unread.ts
@@ -2,6 +2,7 @@
* Module dependencies
*/
import Message from '../../models/messaging-message';
+import Mute from '../../models/mute';
/**
* Get count of unread messages
@@ -11,8 +12,17 @@ import Message from '../../models/messaging-message';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
+ const mute = await Mute.find({
+ muter_id: user._id,
+ deleted_at: { $exists: false }
+ });
+ const mutedUserIds = mute.map(m => m.mutee_id);
+
const count = await Message
.count({
+ user_id: {
+ $nin: mutedUserIds
+ },
recipient_id: user._id,
is_read: false
});