summaryrefslogtreecommitdiff
path: root/src/server/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api')
-rw-r--r--src/server/api/common/read-notification.ts9
-rw-r--r--src/server/api/endpoints.ts2
-rw-r--r--src/server/api/endpoints/drive/files/create.ts9
-rw-r--r--src/server/api/endpoints/i/notifications.ts3
-rw-r--r--src/server/api/endpoints/i/update.ts6
-rw-r--r--src/server/api/endpoints/notes.ts8
-rw-r--r--src/server/api/endpoints/notes/conversation.ts (renamed from src/server/api/endpoints/notes/context.ts)15
-rw-r--r--src/server/api/endpoints/notifications/get_unread_count.ts3
8 files changed, 40 insertions, 15 deletions
diff --git a/src/server/api/common/read-notification.ts b/src/server/api/common/read-notification.ts
index 7b9faf4cf4..cdb87a4114 100644
--- a/src/server/api/common/read-notification.ts
+++ b/src/server/api/common/read-notification.ts
@@ -1,6 +1,7 @@
import * as mongo from 'mongodb';
import { default as Notification, INotification } from '../../../models/notification';
import publishUserStream from '../../../publishers/stream';
+import Mute from '../../../models/mute';
/**
* Mark as read notification(s)
@@ -26,6 +27,11 @@ export default (
? [new mongo.ObjectID(message)]
: [(message as INotification)._id];
+ const mute = await Mute.find({
+ muterId: userId
+ });
+ const mutedUserIds = mute.map(m => m.muteeId);
+
// Update documents
await Notification.update({
_id: { $in: ids },
@@ -42,6 +48,9 @@ export default (
const count = await Notification
.count({
notifieeId: userId,
+ notifierId: {
+ $nin: mutedUserIds
+ },
isRead: false
}, {
limit: 1
diff --git a/src/server/api/endpoints.ts b/src/server/api/endpoints.ts
index 7647c76d3d..892da3540f 100644
--- a/src/server/api/endpoints.ts
+++ b/src/server/api/endpoints.ts
@@ -482,7 +482,7 @@ const endpoints: Endpoint[] = [
name: 'notes/replies'
},
{
- name: 'notes/context'
+ name: 'notes/conversation'
},
{
name: 'notes/create',
diff --git a/src/server/api/endpoints/drive/files/create.ts b/src/server/api/endpoints/drive/files/create.ts
index e9348e4e2f..dd748d6bba 100644
--- a/src/server/api/endpoints/drive/files/create.ts
+++ b/src/server/api/endpoints/drive/files/create.ts
@@ -1,6 +1,7 @@
/**
* Module dependencies
*/
+import * as fs from 'fs';
import $ from 'cafy'; import ID from '../../../../../cafy-id';
import { validateFileName, pack } from '../../../../../models/drive-file';
import create from '../../../../../services/drive/add-file';
@@ -32,15 +33,23 @@ module.exports = async (file, params, user): Promise<any> => {
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
if (folderIdErr) throw 'invalid folderId param';
+ function cleanup() {
+ fs.unlink(file.path, () => {});
+ }
+
try {
// Create file
const driveFile = await create(user, file.path, name, null, folderId);
+ cleanup();
+
// Serialize
return pack(driveFile);
} catch (e) {
console.error(e);
+ cleanup();
+
throw e;
}
};
diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts
index 50ed9b27e8..ba9c47508c 100644
--- a/src/server/api/endpoints/i/notifications.ts
+++ b/src/server/api/endpoints/i/notifications.ts
@@ -96,8 +96,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
});
// Serialize
- res(await Promise.all(notifications.map(async notification =>
- await pack(notification))));
+ res(await Promise.all(notifications.map(notification => pack(notification))));
// Mark as read all
if (notifications.length > 0 && markAsRead) {
diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts
index b7b25d0f65..6e0c5b8515 100644
--- a/src/server/api/endpoints/i/update.ts
+++ b/src/server/api/endpoints/i/update.ts
@@ -47,6 +47,11 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
if (isBotErr) return rej('invalid isBot param');
if (isBot != null) user.isBot = isBot;
+ // Get 'isCat' parameter
+ const [isCat, isCatErr] = $.bool.optional().get(params.isCat);
+ if (isCatErr) return rej('invalid isCat param');
+ if (isCat != null) user.isCat = isCat;
+
// Get 'autoWatch' parameter
const [autoWatch, autoWatchErr] = $.bool.optional().get(params.autoWatch);
if (autoWatchErr) return rej('invalid autoWatch param');
@@ -82,6 +87,7 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
bannerColor: user.bannerColor,
profile: user.profile,
isBot: user.isBot,
+ isCat: user.isCat,
settings: user.settings
}
});
diff --git a/src/server/api/endpoints/notes.ts b/src/server/api/endpoints/notes.ts
index 4ce7613d70..21946d1bd3 100644
--- a/src/server/api/endpoints/notes.ts
+++ b/src/server/api/endpoints/notes.ts
@@ -8,6 +8,10 @@ import Note, { pack } from '../../../models/note';
* Get all notes
*/
module.exports = (params) => new Promise(async (res, rej) => {
+ // Get 'local' parameter
+ const [local, localErr] = $.bool.optional().get(params.local);
+ if (localErr) return rej('invalid local param');
+
// Get 'reply' parameter
const [reply, replyErr] = $.bool.optional().get(params.reply);
if (replyErr) return rej('invalid reply param');
@@ -61,6 +65,10 @@ module.exports = (params) => new Promise(async (res, rej) => {
};
}
+ if (local) {
+ query['_user.host'] = null;
+ }
+
if (reply != undefined) {
query.replyId = reply ? { $exists: true, $ne: null } : null;
}
diff --git a/src/server/api/endpoints/notes/context.ts b/src/server/api/endpoints/notes/conversation.ts
index 1cd27250e2..02f7229ccf 100644
--- a/src/server/api/endpoints/notes/context.ts
+++ b/src/server/api/endpoints/notes/conversation.ts
@@ -5,11 +5,7 @@ import $ from 'cafy'; import ID from '../../../../cafy-id';
import Note, { pack } from '../../../../models/note';
/**
- * Show a context of a note
- *
- * @param {any} params
- * @param {any} user
- * @return {Promise<any>}
+ * Show conversation of a note
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
@@ -33,7 +29,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return rej('note not found');
}
- const context = [];
+ const conversation = [];
let i = 0;
async function get(id) {
@@ -41,10 +37,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const p = await Note.findOne({ _id: id });
if (i > offset) {
- context.push(p);
+ conversation.push(p);
}
- if (context.length == limit) {
+ if (conversation.length == limit) {
return;
}
@@ -58,6 +54,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Serialize
- res(await Promise.all(context.map(async note =>
- await pack(note, user))));
+ res(await Promise.all(conversation.map(note => pack(note, user))));
});
diff --git a/src/server/api/endpoints/notifications/get_unread_count.ts b/src/server/api/endpoints/notifications/get_unread_count.ts
index 600a80d194..9766366ff1 100644
--- a/src/server/api/endpoints/notifications/get_unread_count.ts
+++ b/src/server/api/endpoints/notifications/get_unread_count.ts
@@ -9,8 +9,7 @@ import Mute from '../../../../models/mute';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
const mute = await Mute.find({
- muterId: user._id,
- deletedAt: { $exists: false }
+ muterId: user._id
});
const mutedUserIds = mute.map(m => m.muteeId);