summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/i
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-10-08 15:37:24 +0900
committerGitHub <noreply@github.com>2018-10-08 15:37:24 +0900
commit9c170c426be01773afb15a9868ff3c278e09409c (patch)
tree0229bb52dd9197308d193f4e41bbc11d3dcb95a1 /src/server/api/endpoints/i
parentNew translations ja-JP.yml (Norwegian) (diff)
parentfix(package): update @types/mongodb to version 3.1.10 (#2849) (diff)
downloadmisskey-9c170c426be01773afb15a9868ff3c278e09409c.tar.gz
misskey-9c170c426be01773afb15a9868ff3c278e09409c.tar.bz2
misskey-9c170c426be01773afb15a9868ff3c278e09409c.zip
Merge branch 'develop' into l10n_develop
Diffstat (limited to 'src/server/api/endpoints/i')
-rw-r--r--src/server/api/endpoints/i/favorites.ts4
-rw-r--r--src/server/api/endpoints/i/notifications.ts4
-rw-r--r--src/server/api/endpoints/i/pin.ts48
-rw-r--r--src/server/api/endpoints/i/regenerate_token.ts4
-rw-r--r--src/server/api/endpoints/i/unpin.ts43
-rw-r--r--src/server/api/endpoints/i/update.ts160
-rw-r--r--src/server/api/endpoints/i/update_client_setting.ts4
-rw-r--r--src/server/api/endpoints/i/update_home.ts4
-rw-r--r--src/server/api/endpoints/i/update_mobile_home.ts4
-rw-r--r--src/server/api/endpoints/i/update_widget.ts4
10 files changed, 185 insertions, 94 deletions
diff --git a/src/server/api/endpoints/i/favorites.ts b/src/server/api/endpoints/i/favorites.ts
index 32c1a55fb0..e7cf8a71a7 100644
--- a/src/server/api/endpoints/i/favorites.ts
+++ b/src/server/api/endpoints/i/favorites.ts
@@ -1,5 +1,5 @@
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
-import Favorite, { pack } from '../../../../models/favorite';
+import Favorite, { packMany } from '../../../../models/favorite';
import { ILocalUser } from '../../../../models/user';
export const meta = {
@@ -55,5 +55,5 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
.find(query, { limit, sort });
// Serialize
- res(await Promise.all(favorites.map(favorite => pack(favorite, user))));
+ res(await packMany(favorites, user));
});
diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts
index 46242b9d9f..5cc836e362 100644
--- a/src/server/api/endpoints/i/notifications.ts
+++ b/src/server/api/endpoints/i/notifications.ts
@@ -1,7 +1,7 @@
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
import Notification from '../../../../models/notification';
import Mute from '../../../../models/mute';
-import { pack } from '../../../../models/notification';
+import { packMany } from '../../../../models/notification';
import { getFriendIds } from '../../common/get-friends';
import read from '../../common/read-notification';
import { ILocalUser } from '../../../../models/user';
@@ -83,7 +83,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
});
// Serialize
- res(await Promise.all(notifications.map(notification => pack(notification))));
+ res(await packMany(notifications));
// Mark all as read
if (notifications.length > 0 && markAsRead) {
diff --git a/src/server/api/endpoints/i/pin.ts b/src/server/api/endpoints/i/pin.ts
index ae03a86336..bf729ca091 100644
--- a/src/server/api/endpoints/i/pin.ts
+++ b/src/server/api/endpoints/i/pin.ts
@@ -1,31 +1,37 @@
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
-import User, { ILocalUser } from '../../../../models/user';
-import Note from '../../../../models/note';
+import { ILocalUser } from '../../../../models/user';
import { pack } from '../../../../models/user';
+import { addPinned } from '../../../../services/i/pin';
+import getParams from '../../get-params';
-/**
- * Pin note
- */
-export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
- // Get 'noteId' parameter
- const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
- if (noteIdErr) return rej('invalid noteId param');
+export const meta = {
+ desc: {
+ 'ja-JP': '指定した投稿をピン留めします。'
+ },
- // Fetch pinee
- const note = await Note.findOne({
- _id: noteId,
- userId: user._id
- });
+ requireCredential: true,
- if (note === null) {
- return rej('note not found');
+ kind: 'account-write',
+
+ params: {
+ noteId: $.type(ID).note({
+ desc: {
+ 'ja-JP': '対象の投稿のID'
+ }
+ })
}
+};
- await User.update(user._id, {
- $set: {
- pinnedNoteId: note._id
- }
- });
+export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) return rej(psErr);
+
+ // Processing
+ try {
+ await addPinned(user, ps.noteId);
+ } catch (e) {
+ return rej(e.message);
+ }
// Serialize
const iObj = await pack(user, user, {
diff --git a/src/server/api/endpoints/i/regenerate_token.ts b/src/server/api/endpoints/i/regenerate_token.ts
index fe4a5cd118..2d85f06cfa 100644
--- a/src/server/api/endpoints/i/regenerate_token.ts
+++ b/src/server/api/endpoints/i/regenerate_token.ts
@@ -1,7 +1,7 @@
import $ from 'cafy';
import * as bcrypt from 'bcryptjs';
import User, { ILocalUser } from '../../../../models/user';
-import { publishUserStream } from '../../../../stream';
+import { publishMainStream } from '../../../../stream';
import generateUserToken from '../../common/generate-native-user-token';
export const meta = {
@@ -33,5 +33,5 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
res();
// Publish event
- publishUserStream(user._id, 'my_token_regenerated');
+ publishMainStream(user._id, 'myTokenRegenerated');
});
diff --git a/src/server/api/endpoints/i/unpin.ts b/src/server/api/endpoints/i/unpin.ts
new file mode 100644
index 0000000000..2a81993e4b
--- /dev/null
+++ b/src/server/api/endpoints/i/unpin.ts
@@ -0,0 +1,43 @@
+import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
+import { ILocalUser } from '../../../../models/user';
+import { pack } from '../../../../models/user';
+import { removePinned } from '../../../../services/i/pin';
+import getParams from '../../get-params';
+
+export const meta = {
+ desc: {
+ 'ja-JP': '指定した投稿のピン留めを解除します。'
+ },
+
+ requireCredential: true,
+
+ kind: 'account-write',
+
+ params: {
+ noteId: $.type(ID).note({
+ desc: {
+ 'ja-JP': '対象の投稿のID'
+ }
+ })
+ }
+};
+
+export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) return rej(psErr);
+
+ // Processing
+ try {
+ await removePinned(user, ps.noteId);
+ } catch (e) {
+ return rej(e.message);
+ }
+
+ // Serialize
+ const iObj = await pack(user, user, {
+ detail: true
+ });
+
+ // Send response
+ res(iObj);
+});
diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts
index cdb4eb3f56..548ce5cadb 100644
--- a/src/server/api/endpoints/i/update.ts
+++ b/src/server/api/endpoints/i/update.ts
@@ -1,10 +1,12 @@
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
import User, { isValidName, isValidDescription, isValidLocation, isValidBirthday, pack, ILocalUser } from '../../../../models/user';
-import { publishUserStream } from '../../../../stream';
+import { publishMainStream } from '../../../../stream';
import DriveFile from '../../../../models/drive-file';
import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
import { IApp } from '../../../../models/app';
import config from '../../../../config';
+import { publishToFollowers } from '../../../../services/i/update';
+import getParams from '../../get-params';
export const meta = {
desc: {
@@ -14,75 +16,111 @@ export const meta = {
requireCredential: true,
- kind: 'account-write'
-};
+ kind: 'account-write',
-export default async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
- const isSecure = user != null && app == null;
+ params: {
+ name: $.str.optional.nullable.pipe(isValidName).note({
+ desc: {
+ 'ja-JP': '名前(ハンドルネームやニックネーム)'
+ }
+ }),
- const updates = {} as any;
+ description: $.str.optional.nullable.pipe(isValidDescription).note({
+ desc: {
+ 'ja-JP': 'アカウントの説明や自己紹介'
+ }
+ }),
- // Get 'name' parameter
- const [name, nameErr] = $.str.optional.nullable.pipe(isValidName).get(params.name);
- if (nameErr) return rej('invalid name param');
- if (name) updates.name = name;
+ location: $.str.optional.nullable.pipe(isValidLocation).note({
+ desc: {
+ 'ja-JP': '住んでいる地域、所在'
+ }
+ }),
- // Get 'description' parameter
- const [description, descriptionErr] = $.str.optional.nullable.pipe(isValidDescription).get(params.description);
- if (descriptionErr) return rej('invalid description param');
- if (description !== undefined) updates.description = description;
+ birthday: $.str.optional.nullable.pipe(isValidBirthday).note({
+ desc: {
+ 'ja-JP': '誕生日 (YYYY-MM-DD形式)'
+ }
+ }),
- // Get 'location' parameter
- const [location, locationErr] = $.str.optional.nullable.pipe(isValidLocation).get(params.location);
- if (locationErr) return rej('invalid location param');
- if (location !== undefined) updates['profile.location'] = location;
+ avatarId: $.type(ID).optional.nullable.note({
+ desc: {
+ 'ja-JP': 'アイコンに設定する画像のドライブファイルID'
+ }
+ }),
- // Get 'birthday' parameter
- const [birthday, birthdayErr] = $.str.optional.nullable.pipe(isValidBirthday).get(params.birthday);
- if (birthdayErr) return rej('invalid birthday param');
- if (birthday !== undefined) updates['profile.birthday'] = birthday;
+ bannerId: $.type(ID).optional.nullable.note({
+ desc: {
+ 'ja-JP': 'バナーに設定する画像のドライブファイルID'
+ }
+ }),
- // Get 'avatarId' parameter
- const [avatarId, avatarIdErr] = $.type(ID).optional.nullable.get(params.avatarId);
- if (avatarIdErr) return rej('invalid avatarId param');
- if (avatarId !== undefined) updates.avatarId = avatarId;
+ wallpaperId: $.type(ID).optional.nullable.note({
+ desc: {
+ 'ja-JP': '壁紙に設定する画像のドライブファイルID'
+ }
+ }),
- // Get 'bannerId' parameter
- const [bannerId, bannerIdErr] = $.type(ID).optional.nullable.get(params.bannerId);
- if (bannerIdErr) return rej('invalid bannerId param');
- if (bannerId !== undefined) updates.bannerId = bannerId;
+ isLocked: $.bool.optional.note({
+ desc: {
+ 'ja-JP': '鍵アカウントか否か'
+ }
+ }),
- // Get 'wallpaperId' parameter
- const [wallpaperId, wallpaperIdErr] = $.type(ID).optional.nullable.get(params.wallpaperId);
- if (wallpaperIdErr) return rej('invalid wallpaperId param');
- if (wallpaperId !== undefined) updates.wallpaperId = wallpaperId;
+ isBot: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'Botか否か'
+ }
+ }),
- // Get 'isLocked' parameter
- const [isLocked, isLockedErr] = $.bool.optional.get(params.isLocked);
- if (isLockedErr) return rej('invalid isLocked param');
- if (isLocked != null) updates.isLocked = isLocked;
+ isCat: $.bool.optional.note({
+ desc: {
+ 'ja-JP': '猫か否か'
+ }
+ }),
+
+ autoWatch: $.bool.optional.note({
+ desc: {
+ 'ja-JP': '投稿の自動ウォッチをするか否か'
+ }
+ }),
+
+ alwaysMarkNsfw: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'アップロードするメディアをデフォルトで「閲覧注意」として設定するか'
+ }
+ }),
+ }
+};
+
+export default async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
- // Get 'isBot' parameter
- const [isBot, isBotErr] = $.bool.optional.get(params.isBot);
- if (isBotErr) return rej('invalid isBot param');
- if (isBot != null) updates.isBot = isBot;
+ const isSecure = user != null && app == null;
- // Get 'isCat' parameter
- const [isCat, isCatErr] = $.bool.optional.get(params.isCat);
- if (isCatErr) return rej('invalid isCat param');
- if (isCat != null) updates.isCat = isCat;
+ const updates = {} as any;
- // Get 'autoWatch' parameter
- const [autoWatch, autoWatchErr] = $.bool.optional.get(params.autoWatch);
- if (autoWatchErr) return rej('invalid autoWatch param');
- if (autoWatch != null) updates['settings.autoWatch'] = autoWatch;
+ if (ps.name !== undefined) updates.name = ps.name;
+ if (ps.description !== undefined) updates.description = ps.description;
+ if (ps.location !== undefined) updates['profile.location'] = ps.location;
+ if (ps.birthday !== undefined) updates['profile.birthday'] = ps.birthday;
+ if (ps.avatarId !== undefined) updates.avatarId = ps.avatarId;
+ if (ps.bannerId !== undefined) updates.bannerId = ps.bannerId;
+ if (ps.wallpaperId !== undefined) updates.wallpaperId = ps.wallpaperId;
+ if (typeof ps.isLocked == 'boolean') updates.isLocked = ps.isLocked;
+ if (typeof ps.isBot == 'boolean') updates.isBot = ps.isBot;
+ if (typeof ps.isCat == 'boolean') updates.isCat = ps.isCat;
+ if (typeof ps.autoWatch == 'boolean') updates['settings.autoWatch'] = ps.autoWatch;
+ if (typeof ps.alwaysMarkNsfw == 'boolean') updates['settings.alwaysMarkNsfw'] = ps.alwaysMarkNsfw;
- if (avatarId) {
+ if (ps.avatarId) {
const avatar = await DriveFile.findOne({
- _id: avatarId
+ _id: ps.avatarId
});
if (avatar == null) return rej('avatar not found');
+ if (!avatar.contentType.startsWith('image/')) return rej('avatar not an image');
updates.avatarUrl = avatar.metadata.thumbnailUrl || avatar.metadata.url || `${config.drive_url}/${avatar._id}`;
@@ -91,12 +129,13 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a
}
}
- if (bannerId) {
+ if (ps.bannerId) {
const banner = await DriveFile.findOne({
- _id: bannerId
+ _id: ps.bannerId
});
if (banner == null) return rej('banner not found');
+ if (!banner.contentType.startsWith('image/')) return rej('banner not an image');
updates.bannerUrl = banner.metadata.url || `${config.drive_url}/${banner._id}`;
@@ -105,13 +144,13 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a
}
}
- if (wallpaperId !== undefined) {
- if (wallpaperId === null) {
+ if (ps.wallpaperId !== undefined) {
+ if (ps.wallpaperId === null) {
updates.wallpaperUrl = null;
updates.wallpaperColor = null;
} else {
const wallpaper = await DriveFile.findOne({
- _id: wallpaperId
+ _id: ps.wallpaperId
});
if (wallpaper == null) return rej('wallpaper not found');
@@ -138,10 +177,13 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a
res(iObj);
// Publish meUpdated event
- publishUserStream(user._id, 'meUpdated', iObj);
+ publishMainStream(user._id, 'meUpdated', iObj);
// 鍵垢を解除したとき、溜まっていたフォローリクエストがあるならすべて承認
- if (user.isLocked && isLocked === false) {
+ if (user.isLocked && ps.isLocked === false) {
acceptAllFollowRequests(user);
}
+
+ // フォロワーにUpdateを配信
+ publishToFollowers(user._id);
});
diff --git a/src/server/api/endpoints/i/update_client_setting.ts b/src/server/api/endpoints/i/update_client_setting.ts
index aed93c792f..2c05299dff 100644
--- a/src/server/api/endpoints/i/update_client_setting.ts
+++ b/src/server/api/endpoints/i/update_client_setting.ts
@@ -1,6 +1,6 @@
import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user';
-import { publishUserStream } from '../../../../stream';
+import { publishMainStream } from '../../../../stream';
export const meta = {
requireCredential: true,
@@ -26,7 +26,7 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
res();
// Publish event
- publishUserStream(user._id, 'clientSettingUpdated', {
+ publishMainStream(user._id, 'clientSettingUpdated', {
key: name,
value
});
diff --git a/src/server/api/endpoints/i/update_home.ts b/src/server/api/endpoints/i/update_home.ts
index ffca9b90b3..27afc9fe5a 100644
--- a/src/server/api/endpoints/i/update_home.ts
+++ b/src/server/api/endpoints/i/update_home.ts
@@ -1,6 +1,6 @@
import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user';
-import { publishUserStream } from '../../../../stream';
+import { publishMainStream } from '../../../../stream';
export const meta = {
requireCredential: true,
@@ -25,5 +25,5 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
res();
- publishUserStream(user._id, 'home_updated', home);
+ publishMainStream(user._id, 'homeUpdated', home);
});
diff --git a/src/server/api/endpoints/i/update_mobile_home.ts b/src/server/api/endpoints/i/update_mobile_home.ts
index 0b72fbe2c1..1d4df389e4 100644
--- a/src/server/api/endpoints/i/update_mobile_home.ts
+++ b/src/server/api/endpoints/i/update_mobile_home.ts
@@ -1,6 +1,6 @@
import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user';
-import { publishUserStream } from '../../../../stream';
+import { publishMainStream } from '../../../../stream';
export const meta = {
requireCredential: true,
@@ -24,5 +24,5 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
res();
- publishUserStream(user._id, 'mobile_home_updated', home);
+ publishMainStream(user._id, 'mobileHomeUpdated', home);
});
diff --git a/src/server/api/endpoints/i/update_widget.ts b/src/server/api/endpoints/i/update_widget.ts
index 5cbe7c07a3..92499493eb 100644
--- a/src/server/api/endpoints/i/update_widget.ts
+++ b/src/server/api/endpoints/i/update_widget.ts
@@ -1,6 +1,6 @@
import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user';
-import { publishUserStream } from '../../../../stream';
+import { publishMainStream } from '../../../../stream';
export const meta = {
requireCredential: true,
@@ -73,7 +73,7 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
//#endregion
if (widget) {
- publishUserStream(user._id, 'widgetUpdated', {
+ publishMainStream(user._id, 'widgetUpdated', {
id, data
});