yumechi-no-kuni/src/server/api/endpoints/i/update.ts
Xeltica cd0f8a4ef9
表示する通知を種別ごとに設定できるように (#6647)
* ストリーミング以外は一通り実装

* ストリーミング分も適用

* 通知のグローバル設定をサーバーサイドに保存

* グローバル通知を使うようにしたら更新されなくなるのを修正

* サーバーサイド処理

* i/notifications のパラメーター includeTypes に空配列を渡すと全部の通知が来る問題を修正

* 全て有効/無効ボタンを実装

* Squashed commit of the following:

commit c3c111529e
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Wed Aug 19 22:29:04 2020 +0900

    12.47.0

commit 2dbab66cfe
Author: syuilo <Syuilotan@yahoo.co.jp>
Date:   Wed Aug 19 22:24:39 2020 +0900

    New Crowdin updates (#6617)

    * New translations ja-JP.yml (French)

    * New translations ja-JP.yml (Arabic)

    * New translations ja-JP.yml (French)

    * New translations ja-JP.yml (Spanish)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (Spanish)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (Spanish)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (Spanish)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (Korean)

    * New translations ja-JP.yml (Korean)

    * New translations ja-JP.yml (Korean)

    * New translations ja-JP.yml (Spanish)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (Korean)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (Spanish)

    * New translations ja-JP.yml (Arabic)

    * New translations ja-JP.yml (French)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (Japanese, Kansai)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (Korean)

    * New translations ja-JP.yml (Chinese Simplified)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (Spanish)

    * New translations ja-JP.yml (Arabic)

    * New translations ja-JP.yml (French)

    * New translations ja-JP.yml (Chinese Traditional)

    * New translations ja-JP.yml (German)

    * New translations ja-JP.yml (English)

    * New translations ja-JP.yml (Chinese Simplified)

commit 01238d6b1a
Author: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
Date:   Wed Aug 19 22:24:02 2020 +0900

    Update README.md [AUTOGEN] (#6593)

commit c34f302b1c
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Wed Aug 19 21:47:18 2020 +0900

    enhance(client): サーバーから切断されたときにダイアログで警告を表示できるように

commit 6870262f8d
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Wed Aug 19 17:52:11 2020 +0900

    enhance(client): Better element visible detection

commit c54d5e7040
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Wed Aug 19 17:51:31 2020 +0900

    fix(clinet): 誤字によりスクロールイベントリスナが解除されていなかったのを修正

commit 0ace009a54
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Tue Aug 18 22:52:54 2020 +0900

    fix(server): Prevent error when recieve non-json data from websocket

    Fix #6658

commit 48e8ee440b
Author: MeiMei <30769358+mei23@users.noreply.github.com>
Date:   Tue Aug 18 22:48:52 2020 +0900

    WebPのアニメーションが失われるのを修正 Fix #6625 (#6649)

commit 9855405b89
Author: syuilo <Syuilotan@yahoo.co.jp>
Date:   Tue Aug 18 22:44:21 2020 +0900

    Channel (#6621)

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wop

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * add notes

    * wip

    * wip

    * wip

    * wip

    * sound

    * wip

    * add kick_gaba2

    * wip

commit 122076e8ea
Author: MeiMei <30769358+mei23@users.noreply.github.com>
Date:   Sat Aug 15 04:27:19 2020 +0900

    Sign (request-target) Fix #6652 (#6656)

commit 7c5ac2cbb4
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Fri Aug 14 15:24:55 2020 +0900

    perf(server): Add isSensitive index to improve query performance

commit ccda2181c1
Author: MeiMei <30769358+mei23@users.noreply.github.com>
Date:   Fri Aug 14 00:54:33 2020 +0900

    GCSに大きいファイルがアップロードできないのを修正 Fix #6254 (#6648)

commit b5fe4ba9be
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Thu Aug 13 23:02:43 2020 +0900

    WIP: Improve admin dashboard

commit fd9c7d525a
Merge: 080574e13 ee0a44559
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Thu Aug 13 21:27:10 2020 +0900

    Merge branch 'develop' of https://github.com/syuilo/misskey into develop

commit 080574e13d
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Thu Aug 13 21:27:06 2020 +0900

    WIP: Improve admin dashboard

commit ee0a445590
Author: MeiMei <30769358+mei23@users.noreply.github.com>
Date:   Thu Aug 13 20:05:01 2020 +0900

    Option objectStorageSetPublicRead (#6645)

commit bb342c7601
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Thu Aug 13 19:56:46 2020 +0900

    WIP: Improve admin dashboard

commit ed17636fb9
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Thu Aug 13 17:58:16 2020 +0900

    WIP: Improve admin dashboard

commit c59d7d941a
Author: syuilo <Syuilotan@yahoo.co.jp>
Date:   Wed Aug 12 17:42:12 2020 +0900

    Update README.md

    Close #6644

commit 377377595a
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 20:23:51 2020 +0900

    enhance(client): Improve admin page

commit d63aef9963
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 13:55:00 2020 +0900

    chore(client): Fix style

commit e9b28fa3c0
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 13:00:10 2020 +0900

    chore(client): Design tweaks

commit be255dc583
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 12:42:51 2020 +0900

    chore(client): Design tweak

commit 18eb7c6087
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 12:31:22 2020 +0900

    chore(client): Design tweaks

commit cf29e69813
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 12:28:35 2020 +0900

    chore(client): Fix bug

commit 132da7e3c0
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 12:20:58 2020 +0900

    Update ja-JP.yml

commit 26df23bb64
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 12:18:02 2020 +0900

    chore(client): fix style

commit 76389ad619
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 12:15:58 2020 +0900

    chore(client): Design tweaks

commit 7cde8cfbf2
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 11:51:43 2020 +0900

    chore(client): Design tweaks

commit 4eb2ddac4e
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 11:24:30 2020 +0900

    chore(client): Design tweaks

commit dc51eef27c
Merge: bff8a23cb 9c5efb9da
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 10:38:00 2020 +0900

    Merge branch 'develop' of https://github.com/syuilo/misskey into develop

commit bff8a23cbc
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Mon Aug 10 10:37:57 2020 +0900

    chore(client): Design tweaks

commit 9c5efb9da0
Author: rinsuki <428rinsuki+git@gmail.com>
Date:   Mon Aug 10 01:33:01 2020 +0900

    Dockerのビルド時にgitを入れるように (#6639)

    917d3d0bd3 でgitの依存関係が追加されたのにgitが入っていないのでコケていた

commit 48b8320e5e
Author: rinsuki <428rinsuki+git@gmail.com>
Date:   Mon Aug 10 01:32:27 2020 +0900

    Fix #6637 (#6638)

    * Fix #6637

    * fix lint

commit 9b2ed96c1c
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Sun Aug 9 15:59:38 2020 +0900

    chore: Clean up

commit 69d9aa71f2
Author: syuilo <Syuilotan@yahoo.co.jp>
Date:   Sun Aug 9 15:51:02 2020 +0900

    Full view mode (#6636)

    * wuip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * wip

    * Update folder.vue

    * wip

    * Update size.ts

    * wip

    * wip

    * Update index.vue

    * wip

commit 13683780cd
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Sun Aug 9 13:49:44 2020 +0900

    ✌️

commit d780e5b251
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Sun Aug 9 13:46:19 2020 +0900

    enhance(client): ミュートされたノート数を表示するようにしたり

commit 917d3d0bd3
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Sat Aug 8 10:30:38 2020 +0900

    chore: Update dependencies 🚀

commit 4b19c53697
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Sat Aug 8 10:27:37 2020 +0900

    client: テーマコードをコピーできるようにしたり

commit 2d40a15d2b
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Fri Aug 7 11:27:37 2020 +0900

    refactor: Extract well-known services

commit 2bdcd22ad4
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Tue Aug 4 23:09:48 2020 +0900

    enhance(api): アクセストークンを作成する際、createdAtをlastUsedAtを揃えるようにして、未使用かどうかを判定できるように

commit f73a4e1304
Author: MeiMei <30769358+mei23@users.noreply.github.com>
Date:   Tue Aug 4 21:12:55 2020 +0900

    Update .dockerignore (#6620)

commit b265cdbd84
Author: Xeltica <7106976+Xeltica@users.noreply.github.com>
Date:   Mon Aug 3 13:40:32 2020 +0900

    Update CHANGELOG.md

commit a04d8b95c2
Author: Xeltica <7106976+Xeltica@users.noreply.github.com>
Date:   Mon Aug 3 13:40:13 2020 +0900

    Update CHANGELOG.md

commit 0e9a8c0cd4
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Sun Aug 2 13:59:05 2020 +0900

    fix(client): Message read state is not reactive

commit 5ae8a3c7e8
Author: syuilo <syuilotan@yahoo.co.jp>
Date:   Sun Aug 2 13:49:28 2020 +0900

    refactor

* fix: includeTypes 未指定時に通知が返ってこなくなるバグを修正

* 最適化とバグ修正

* 挙動を修正

* Update ja-JP.yml

* 不要なimportを削除

* ✌

* 不要なコードの削除

* Update notification-setting-window.vue

* Update notification-setting-window.vue

* 🎨

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2020-08-22 10:06:17 +09:00

309 lines
8.6 KiB
TypeScript

import $ from 'cafy';
import { ID } from '../../../../misc/cafy-id';
import { publishMainStream } from '../../../../services/stream';
import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
import { publishToFollowers } from '../../../../services/i/update';
import define from '../../define';
import { parse, parsePlain } from '../../../../mfm/parse';
import extractEmojis from '../../../../misc/extract-emojis';
import extractHashtags from '../../../../misc/extract-hashtags';
import * as langmap from 'langmap';
import { updateUsertags } from '../../../../services/update-hashtag';
import { ApiError } from '../../error';
import { Users, DriveFiles, UserProfiles, Pages } from '../../../../models';
import { User } from '../../../../models/entities/user';
import { UserProfile } from '../../../../models/entities/user-profile';
import { ensure } from '../../../../prelude/ensure';
import { notificationTypes } from '../../../../types';
export const meta = {
desc: {
'ja-JP': 'アカウント情報を更新します。',
'en-US': 'Update myself'
},
tags: ['account'],
requireCredential: true as const,
kind: 'write:account',
params: {
name: {
validator: $.optional.nullable.use(Users.validateName),
desc: {
'ja-JP': '名前(ハンドルネームやニックネーム)'
}
},
description: {
validator: $.optional.nullable.use(Users.validateDescription),
desc: {
'ja-JP': 'アカウントの説明や自己紹介'
}
},
lang: {
validator: $.optional.nullable.str.or(Object.keys(langmap)),
desc: {
'ja-JP': '言語'
}
},
location: {
validator: $.optional.nullable.use(Users.validateLocation),
desc: {
'ja-JP': '住んでいる地域、所在'
}
},
birthday: {
validator: $.optional.nullable.use(Users.validateBirthday),
desc: {
'ja-JP': '誕生日 (YYYY-MM-DD形式)'
}
},
avatarId: {
validator: $.optional.nullable.type(ID),
desc: {
'ja-JP': 'アバターに設定する画像のドライブファイルID'
}
},
bannerId: {
validator: $.optional.nullable.type(ID),
desc: {
'ja-JP': 'バナーに設定する画像のドライブファイルID'
}
},
fields: {
validator: $.optional.arr($.object()).range(1, 4),
desc: {
'ja-JP': 'プロフィール補足情報'
}
},
isLocked: {
validator: $.optional.bool,
desc: {
'ja-JP': '鍵アカウントか否か'
}
},
carefulBot: {
validator: $.optional.bool,
desc: {
'ja-JP': 'Botからのフォローを承認制にするか'
}
},
autoAcceptFollowed: {
validator: $.optional.bool,
desc: {
'ja-JP': 'フォローしているユーザーからのフォローリクエストを自動承認するか'
}
},
isBot: {
validator: $.optional.bool,
desc: {
'ja-JP': 'Botか否か'
}
},
isCat: {
validator: $.optional.bool,
desc: {
'ja-JP': '猫か否か'
}
},
autoWatch: {
validator: $.optional.bool,
desc: {
'ja-JP': '投稿の自動ウォッチをするか否か'
}
},
injectFeaturedNote: {
validator: $.optional.bool,
},
alwaysMarkNsfw: {
validator: $.optional.bool,
desc: {
'ja-JP': 'アップロードするメディアをデフォルトで「閲覧注意」として設定するか'
}
},
pinnedPageId: {
validator: $.optional.nullable.type(ID),
desc: {
'ja-JP': 'ピン留めするページID'
}
},
mutedWords: {
validator: $.optional.arr($.arr($.str))
},
includingNotificationTypes: {
validator: $.optional.arr($.str.or(notificationTypes as unknown as string[]))
},
},
errors: {
noSuchAvatar: {
message: 'No such avatar file.',
code: 'NO_SUCH_AVATAR',
id: '539f3a45-f215-4f81-a9a8-31293640207f'
},
noSuchBanner: {
message: 'No such banner file.',
code: 'NO_SUCH_BANNER',
id: '0d8f5629-f210-41c2-9433-735831a58595'
},
avatarNotAnImage: {
message: 'The file specified as an avatar is not an image.',
code: 'AVATAR_NOT_AN_IMAGE',
id: 'f419f9f8-2f4d-46b1-9fb4-49d3a2fd7191'
},
bannerNotAnImage: {
message: 'The file specified as a banner is not an image.',
code: 'BANNER_NOT_AN_IMAGE',
id: '75aedb19-2afd-4e6d-87fc-67941256fa60'
},
noSuchPage: {
message: 'No such page.',
code: 'NO_SUCH_PAGE',
id: '8e01b590-7eb9-431b-a239-860e086c408e'
},
}
};
export default define(meta, async (ps, user, token) => {
const isSecure = token == null;
const updates = {} as Partial<User>;
const profileUpdates = {} as Partial<UserProfile>;
const profile = await UserProfiles.findOne(user.id).then(ensure);
if (ps.name !== undefined) updates.name = ps.name;
if (ps.description !== undefined) profileUpdates.description = ps.description;
//if (ps.lang !== undefined) updates.lang = ps.lang;
if (ps.location !== undefined) profileUpdates.location = ps.location;
if (ps.birthday !== undefined) profileUpdates.birthday = ps.birthday;
if (ps.avatarId !== undefined) updates.avatarId = ps.avatarId;
if (ps.bannerId !== undefined) updates.bannerId = ps.bannerId;
if (ps.mutedWords !== undefined) {
profileUpdates.mutedWords = ps.mutedWords;
profileUpdates.enableWordMute = ps.mutedWords.length > 0;
}
if (ps.includingNotificationTypes !== undefined) profileUpdates.includingNotificationTypes = ps.includingNotificationTypes as typeof notificationTypes[number][];
if (typeof ps.isLocked === 'boolean') updates.isLocked = ps.isLocked;
if (typeof ps.isBot === 'boolean') updates.isBot = ps.isBot;
if (typeof ps.carefulBot === 'boolean') profileUpdates.carefulBot = ps.carefulBot;
if (typeof ps.autoAcceptFollowed === 'boolean') profileUpdates.autoAcceptFollowed = ps.autoAcceptFollowed;
if (typeof ps.isCat === 'boolean') updates.isCat = ps.isCat;
if (typeof ps.autoWatch === 'boolean') profileUpdates.autoWatch = ps.autoWatch;
if (typeof ps.injectFeaturedNote === 'boolean') profileUpdates.injectFeaturedNote = ps.injectFeaturedNote;
if (typeof ps.alwaysMarkNsfw === 'boolean') profileUpdates.alwaysMarkNsfw = ps.alwaysMarkNsfw;
if (ps.avatarId) {
const avatar = await DriveFiles.findOne(ps.avatarId);
if (avatar == null || avatar.userId !== user.id) throw new ApiError(meta.errors.noSuchAvatar);
if (!avatar.type.startsWith('image/')) throw new ApiError(meta.errors.avatarNotAnImage);
updates.avatarUrl = DriveFiles.getPublicUrl(avatar, true);
if (avatar.blurhash) {
updates.avatarBlurhash = avatar.blurhash;
}
}
if (ps.bannerId) {
const banner = await DriveFiles.findOne(ps.bannerId);
if (banner == null || banner.userId !== user.id) throw new ApiError(meta.errors.noSuchBanner);
if (!banner.type.startsWith('image/')) throw new ApiError(meta.errors.bannerNotAnImage);
updates.bannerUrl = DriveFiles.getPublicUrl(banner, false);
if (banner.blurhash) {
updates.bannerBlurhash = banner.blurhash;
}
}
if (ps.pinnedPageId) {
const page = await Pages.findOne(ps.pinnedPageId);
if (page == null || page.userId !== user.id) throw new ApiError(meta.errors.noSuchPage);
profileUpdates.pinnedPageId = page.id;
} else if (ps.pinnedPageId === null) {
profileUpdates.pinnedPageId = null;
}
if (ps.fields) {
profileUpdates.fields = ps.fields
.filter(x => typeof x.name === 'string' && x.name !== '' && typeof x.value === 'string' && x.value !== '')
.map(x => {
return { name: x.name, value: x.value };
});
}
//#region emojis/tags
let emojis = [] as string[];
let tags = [] as string[];
const newName = updates.name === undefined ? user.name : updates.name;
const newDescription = profileUpdates.description === undefined ? profile.description : profileUpdates.description;
if (newName != null) {
const tokens = parsePlain(newName);
emojis = emojis.concat(extractEmojis(tokens!));
}
if (newDescription != null) {
const tokens = parse(newDescription);
emojis = emojis.concat(extractEmojis(tokens!));
tags = extractHashtags(tokens!).map(tag => tag.toLowerCase()).splice(0, 32);
}
updates.emojis = emojis;
updates.tags = tags;
// ハッシュタグ更新
updateUsertags(user, tags);
//#endregion
if (Object.keys(updates).length > 0) await Users.update(user.id, updates);
if (Object.keys(profileUpdates).length > 0) await UserProfiles.update(user.id, profileUpdates);
const iObj = await Users.pack(user.id, user, {
detail: true,
includeSecrets: isSecure
});
// Publish meUpdated event
publishMainStream(user.id, 'meUpdated', iObj);
// 鍵垢を解除したとき、溜まっていたフォローリクエストがあるならすべて承認
if (user.isLocked && ps.isLocked === false) {
acceptAllFollowRequests(user);
}
// フォロワーにUpdateを配信
publishToFollowers(user.id);
return iObj;
});