summaryrefslogtreecommitdiff
path: root/src/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-02-23 02:13:40 +0900
committerGitHub <noreply@github.com>2018-02-23 02:13:40 +0900
commitd1785848289397b9e8242edd9bd87c5906fe5eb7 (patch)
tree8cb4ff23a694f95bc8f4895698b6202090c26554 /src/api/endpoints
parentMerge pull request #1097 from syuilo/refactor (diff)
parentwip (diff)
downloadmisskey-d1785848289397b9e8242edd9bd87c5906fe5eb7.tar.gz
misskey-d1785848289397b9e8242edd9bd87c5906fe5eb7.tar.bz2
misskey-d1785848289397b9e8242edd9bd87c5906fe5eb7.zip
Merge pull request #1116 from syuilo/vue-#972
Migrate to Vue
Diffstat (limited to 'src/api/endpoints')
-rw-r--r--src/api/endpoints/i/update.ts8
-rw-r--r--src/api/endpoints/i/update_client_setting.ts43
2 files changed, 44 insertions, 7 deletions
diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts
index 7bbbf95900..43c5245044 100644
--- a/src/api/endpoints/i/update.ts
+++ b/src/api/endpoints/i/update.ts
@@ -46,19 +46,13 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
if (bannerIdErr) return rej('invalid banner_id param');
if (bannerId) user.banner_id = bannerId;
- // Get 'show_donation' parameter
- const [showDonation, showDonationErr] = $(params.show_donation).optional.boolean().$;
- if (showDonationErr) return rej('invalid show_donation param');
- if (showDonation) user.client_settings.show_donation = showDonation;
-
await User.update(user._id, {
$set: {
name: user.name,
description: user.description,
avatar_id: user.avatar_id,
banner_id: user.banner_id,
- profile: user.profile,
- 'client_settings.show_donation': user.client_settings.show_donation
+ profile: user.profile
}
});
diff --git a/src/api/endpoints/i/update_client_setting.ts b/src/api/endpoints/i/update_client_setting.ts
new file mode 100644
index 0000000000..b817ff354c
--- /dev/null
+++ b/src/api/endpoints/i/update_client_setting.ts
@@ -0,0 +1,43 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import User, { pack } from '../../models/user';
+import event from '../../event';
+
+/**
+ * Update myself
+ *
+ * @param {any} params
+ * @param {any} user
+ * @return {Promise<any>}
+ */
+module.exports = async (params, user) => new Promise(async (res, rej) => {
+ // Get 'name' parameter
+ const [name, nameErr] = $(params.name).string().$;
+ if (nameErr) return rej('invalid name param');
+
+ // Get 'value' parameter
+ const [value, valueErr] = $(params.value).nullable.any().$;
+ if (valueErr) return rej('invalid value param');
+
+ const x = {};
+ x[`client_settings.${name}`] = value;
+
+ await User.update(user._id, {
+ $set: x
+ });
+
+ // Serialize
+ user.client_settings[name] = value;
+ const iObj = await pack(user, user, {
+ detail: true,
+ includeSecrets: true
+ });
+
+ // Send response
+ res(iObj);
+
+ // Publish i updated event
+ event(user._id, 'i_updated', iObj);
+});