summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/endpoints')
-rw-r--r--src/server/api/endpoints/messaging/messages.ts7
-rw-r--r--src/server/api/endpoints/messaging/messages/create.ts7
-rw-r--r--src/server/api/endpoints/messaging/unread.ts29
-rw-r--r--src/server/api/endpoints/notes.ts4
-rw-r--r--src/server/api/endpoints/notes/delete.ts26
-rw-r--r--src/server/api/endpoints/notes/global-timeline.ts28
-rw-r--r--src/server/api/endpoints/notes/local-timeline.ts32
-rw-r--r--src/server/api/endpoints/notes/replies.ts26
-rw-r--r--src/server/api/endpoints/notifications/get_unread_count.ts28
-rw-r--r--src/server/api/endpoints/notifications/mark_as_read_all.ts11
10 files changed, 83 insertions, 115 deletions
diff --git a/src/server/api/endpoints/messaging/messages.ts b/src/server/api/endpoints/messaging/messages.ts
index 0338aba68a..9c3a48334b 100644
--- a/src/server/api/endpoints/messaging/messages.ts
+++ b/src/server/api/endpoints/messaging/messages.ts
@@ -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
diff --git a/src/server/api/endpoints/messaging/messages/create.ts b/src/server/api/endpoints/messaging/messages/create.ts
index db471839e7..41238de1e1 100644
--- a/src/server/api/endpoints/messaging/messages/create.ts
+++ b/src/server/api/endpoints/messaging/messages/create.ts
@@ -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 });
diff --git a/src/server/api/endpoints/messaging/unread.ts b/src/server/api/endpoints/messaging/unread.ts
deleted file mode 100644
index 1d83af501d..0000000000
--- a/src/server/api/endpoints/messaging/unread.ts
+++ /dev/null
@@ -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
- });
-});
diff --git a/src/server/api/endpoints/notes.ts b/src/server/api/endpoints/notes.ts
index 21946d1bd3..e6fe80ac8a 100644
--- a/src/server/api/endpoints/notes.ts
+++ b/src/server/api/endpoints/notes.ts
@@ -53,7 +53,9 @@ module.exports = (params) => new Promise(async (res, rej) => {
const sort = {
_id: -1
};
- const query = {} as any;
+ const query = {
+ visibility: 'public'
+ } as any;
if (sinceId) {
sort._id = 1;
query._id = {
diff --git a/src/server/api/endpoints/notes/delete.ts b/src/server/api/endpoints/notes/delete.ts
new file mode 100644
index 0000000000..9bbb1541d6
--- /dev/null
+++ b/src/server/api/endpoints/notes/delete.ts
@@ -0,0 +1,26 @@
+import $ from 'cafy'; import ID from '../../../../cafy-id';
+import Note from '../../../../models/note';
+import deleteNote from '../../../../services/note/delete';
+
+/**
+ * Delete a note
+ */
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ // Get 'noteId' parameter
+ const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
+ if (noteIdErr) return rej('invalid noteId param');
+
+ // Fetch note
+ const note = await Note.findOne({
+ _id: noteId,
+ userId: user._id
+ });
+
+ if (note === null) {
+ return rej('note not found');
+ }
+
+ await deleteNote(user, note);
+
+ res();
+});
diff --git a/src/server/api/endpoints/notes/global-timeline.ts b/src/server/api/endpoints/notes/global-timeline.ts
index d22a1763de..7cf06c3af1 100644
--- a/src/server/api/endpoints/notes/global-timeline.ts
+++ b/src/server/api/endpoints/notes/global-timeline.ts
@@ -9,7 +9,7 @@ import { pack } from '../../../../models/note';
/**
* Get timeline of global
*/
-module.exports = async (params, user, app) => {
+module.exports = async (params, user) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) throw 'invalid limit param';
@@ -36,9 +36,9 @@ module.exports = async (params, user, app) => {
}
// ミュートしているユーザーを取得
- const mutedUserIds = (await Mute.find({
+ const mutedUserIds = user ? (await Mute.find({
muterId: user._id
- })).map(m => m.muteeId);
+ })).map(m => m.muteeId) : null;
//#region Construct query
const sort = {
@@ -46,17 +46,23 @@ module.exports = async (params, user, app) => {
};
const query = {
- // mute
- userId: {
+ // public only
+ visibility: 'public'
+ } as any;
+
+ if (mutedUserIds && mutedUserIds.length > 0) {
+ query.userId = {
$nin: mutedUserIds
- },
- '_reply.userId': {
+ };
+
+ query['_reply.userId'] = {
$nin: mutedUserIds
- },
- '_renote.userId': {
+ };
+
+ query['_renote.userId'] = {
$nin: mutedUserIds
- }
- } as any;
+ };
+ }
if (sinceId) {
sort._id = 1;
diff --git a/src/server/api/endpoints/notes/local-timeline.ts b/src/server/api/endpoints/notes/local-timeline.ts
index e7ebe5d960..7d01de3d43 100644
--- a/src/server/api/endpoints/notes/local-timeline.ts
+++ b/src/server/api/endpoints/notes/local-timeline.ts
@@ -9,7 +9,7 @@ import { pack } from '../../../../models/note';
/**
* Get timeline of local
*/
-module.exports = async (params, user, app) => {
+module.exports = async (params, user) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) throw 'invalid limit param';
@@ -36,9 +36,9 @@ module.exports = async (params, user, app) => {
}
// ミュートしているユーザーを取得
- const mutedUserIds = (await Mute.find({
+ const mutedUserIds = user ? (await Mute.find({
muterId: user._id
- })).map(m => m.muteeId);
+ })).map(m => m.muteeId) : null;
//#region Construct query
const sort = {
@@ -46,21 +46,27 @@ module.exports = async (params, user, app) => {
};
const query = {
- // mute
- userId: {
- $nin: mutedUserIds
- },
- '_reply.userId': {
- $nin: mutedUserIds
- },
- '_renote.userId': {
- $nin: mutedUserIds
- },
+ // public only
+ visibility: 'public',
// local
'_user.host': null
} as any;
+ if (mutedUserIds && mutedUserIds.length > 0) {
+ query.userId = {
+ $nin: mutedUserIds
+ };
+
+ query['_reply.userId'] = {
+ $nin: mutedUserIds
+ };
+
+ query['_renote.userId'] = {
+ $nin: mutedUserIds
+ };
+ }
+
if (sinceId) {
sort._id = 1;
query._id = {
diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts
index 11d221d8f7..608027f6b1 100644
--- a/src/server/api/endpoints/notes/replies.ts
+++ b/src/server/api/endpoints/notes/replies.ts
@@ -1,15 +1,8 @@
-/**
- * Module dependencies
- */
import $ from 'cafy'; import ID from '../../../../cafy-id';
import Note, { pack } from '../../../../models/note';
/**
- * Show a replies of a note
- *
- * @param {any} params
- * @param {any} user
- * @return {Promise<any>}
+ * Get replies of a note
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
@@ -24,10 +17,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
- // Get 'sort' parameter
- const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
- if (sortError) return rej('invalid sort param');
-
// Lookup note
const note = await Note.findOne({
_id: noteId
@@ -37,17 +26,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return rej('note not found');
}
- // Issue query
- const replies = await Note
- .find({ replyId: note._id }, {
- limit: limit,
- skip: offset,
- sort: {
- _id: sort == 'asc' ? 1 : -1
- }
- });
+ const ids = (note._replyIds || []).slice(offset, offset + limit);
// Serialize
- res(await Promise.all(replies.map(async note =>
- await pack(note, user))));
+ res(await Promise.all(ids.map(id => pack(id, user))));
});
diff --git a/src/server/api/endpoints/notifications/get_unread_count.ts b/src/server/api/endpoints/notifications/get_unread_count.ts
deleted file mode 100644
index 9766366ff1..0000000000
--- a/src/server/api/endpoints/notifications/get_unread_count.ts
+++ /dev/null
@@ -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
- });
-});
diff --git a/src/server/api/endpoints/notifications/mark_as_read_all.ts b/src/server/api/endpoints/notifications/mark_as_read_all.ts
index dce3cb4663..7a48ca3e62 100644
--- a/src/server/api/endpoints/notifications/mark_as_read_all.ts
+++ b/src/server/api/endpoints/notifications/mark_as_read_all.ts
@@ -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');
});