diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2018-06-02 16:28:08 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-02 16:28:08 +0900 |
| commit | e25e1d88d60c4d427635e51609a6ecbfe7b6049b (patch) | |
| tree | b3b9890e83527d0d257c819a2c61981516945e21 /src/server/api/endpoints/i/update.ts | |
| parent | Merge pull request #1672 from Angristan/patch-1 (diff) | |
| parent | wip (diff) | |
| download | misskey-e25e1d88d60c4d427635e51609a6ecbfe7b6049b.tar.gz misskey-e25e1d88d60c4d427635e51609a6ecbfe7b6049b.tar.bz2 misskey-e25e1d88d60c4d427635e51609a6ecbfe7b6049b.zip | |
Merge pull request #1671 from syuilo/locked-account
Locked account
Diffstat (limited to 'src/server/api/endpoints/i/update.ts')
| -rw-r--r-- | src/server/api/endpoints/i/update.ts | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index 6e0c5b8515..b94f073d2c 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -5,6 +5,7 @@ import $ from 'cafy'; import ID from '../../../../cafy-id'; import User, { isValidName, isValidDescription, isValidLocation, isValidBirthday, pack } from '../../../../models/user'; import event from '../../../../publishers/stream'; import DriveFile from '../../../../models/drive-file'; +import acceptAllFollowRequests from '../../../../services/following/requests/accept-all'; /** * Update myself @@ -12,50 +13,57 @@ import DriveFile from '../../../../models/drive-file'; module.exports = async (params, user, app) => new Promise(async (res, rej) => { const isSecure = user != null && app == null; + const updates = {} as any; + // Get 'name' parameter const [name, nameErr] = $.str.optional().nullable().pipe(isValidName).get(params.name); if (nameErr) return rej('invalid name param'); - if (name) user.name = name; + if (name) updates.name = name; // Get 'description' parameter const [description, descriptionErr] = $.str.optional().nullable().pipe(isValidDescription).get(params.description); if (descriptionErr) return rej('invalid description param'); - if (description !== undefined) user.description = description; + if (description !== undefined) updates.description = description; // Get 'location' parameter const [location, locationErr] = $.str.optional().nullable().pipe(isValidLocation).get(params.location); if (locationErr) return rej('invalid location param'); - if (location !== undefined) user.profile.location = location; + if (location !== undefined) updates['profile.location'] = location; // Get 'birthday' parameter const [birthday, birthdayErr] = $.str.optional().nullable().pipe(isValidBirthday).get(params.birthday); if (birthdayErr) return rej('invalid birthday param'); - if (birthday !== undefined) user.profile.birthday = birthday; + if (birthday !== undefined) updates['profile.birthday'] = birthday; // Get 'avatarId' parameter - const [avatarId, avatarIdErr] = $.type(ID).optional().get(params.avatarId); + const [avatarId, avatarIdErr] = $.type(ID).optional().nullable().get(params.avatarId); if (avatarIdErr) return rej('invalid avatarId param'); - if (avatarId) user.avatarId = avatarId; + if (avatarId !== undefined) updates.avatarId = avatarId; // Get 'bannerId' parameter - const [bannerId, bannerIdErr] = $.type(ID).optional().get(params.bannerId); + const [bannerId, bannerIdErr] = $.type(ID).optional().nullable().get(params.bannerId); if (bannerIdErr) return rej('invalid bannerId param'); - if (bannerId) user.bannerId = bannerId; + if (bannerId !== undefined) updates.bannerId = bannerId; + + // Get 'isLocked' parameter + const [isLocked, isLockedErr] = $.bool.optional().get(params.isLocked); + if (isLockedErr) return rej('invalid isLocked param'); + if (isLocked != null) updates.isLocked = isLocked; // Get 'isBot' parameter const [isBot, isBotErr] = $.bool.optional().get(params.isBot); if (isBotErr) return rej('invalid isBot param'); - if (isBot != null) user.isBot = isBot; + if (isBot != null) updates.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; + if (isCat != null) updates.isCat = isCat; // Get 'autoWatch' parameter const [autoWatch, autoWatchErr] = $.bool.optional().get(params.autoWatch); if (autoWatchErr) return rej('invalid autoWatch param'); - if (autoWatch != null) user.settings.autoWatch = autoWatch; + if (autoWatch != null) updates['settings.autoWatch'] = autoWatch; if (avatarId) { const avatar = await DriveFile.findOne({ @@ -63,7 +71,7 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => { }); if (avatar != null && avatar.metadata.properties.avgColor) { - user.avatarColor = avatar.metadata.properties.avgColor; + updates.avatarColor = avatar.metadata.properties.avgColor; } } @@ -73,27 +81,16 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => { }); if (banner != null && banner.metadata.properties.avgColor) { - user.bannerColor = banner.metadata.properties.avgColor; + updates.bannerColor = banner.metadata.properties.avgColor; } } await User.update(user._id, { - $set: { - name: user.name, - description: user.description, - avatarId: user.avatarId, - avatarColor: user.avatarColor, - bannerId: user.bannerId, - bannerColor: user.bannerColor, - profile: user.profile, - isBot: user.isBot, - isCat: user.isCat, - settings: user.settings - } + $set: updates }); // Serialize - const iObj = await pack(user, user, { + const iObj = await pack(user._id, user, { detail: true, includeSecrets: isSecure }); @@ -101,6 +98,11 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => { // Send response res(iObj); - // Publish i updated event - event(user._id, 'i_updated', iObj); + // Publish meUpdated event + event(user._id, 'meUpdated', iObj); + + // 鍵垢を解除したとき、溜まっていたフォローリクエストがあるならすべて承認 + if (user.isLocked && isLocked === false) { + acceptAllFollowRequests(user); + } }); |