From c686a1047248749b21c76fd9f5d867c9324cdd82 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 23 Feb 2018 02:06:35 +0900 Subject: [PATCH] wip --- src/api/endpoints.ts | 5 ++ src/api/endpoints/i/update.ts | 8 +-- src/api/endpoints/i/update_client_setting.ts | 43 +++++++++++++++ .../app/common/views/components/post-html.ts | 6 ++- src/web/app/desktop/views/components/home.vue | 54 +++++++++++-------- .../views/components/settings-window.vue | 12 +++-- .../app/desktop/views/components/settings.vue | 33 +++++++++++- 7 files changed, 127 insertions(+), 34 deletions(-) create mode 100644 src/api/endpoints/i/update_client_setting.ts diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index e84638157..ff214c300 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -194,6 +194,11 @@ const endpoints: Endpoint[] = [ withCredential: true, secure: true }, + { + name: 'i/update_client_setting', + withCredential: true, + secure: true + }, { name: 'i/pin', kind: 'account-write' diff --git a/src/api/endpoints/i/update.ts b/src/api/endpoints/i/update.ts index 7bbbf9590..43c524504 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 000000000..b817ff354 --- /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} + */ +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); +}); diff --git a/src/web/app/common/views/components/post-html.ts b/src/web/app/common/views/components/post-html.ts index afd95f8e3..16d670e85 100644 --- a/src/web/app/common/views/components/post-html.ts +++ b/src/web/app/common/views/components/post-html.ts @@ -33,7 +33,11 @@ export default Vue.component('mk-post-html', { .replace(/(\r\n|\n|\r)/g, '\n'); if ((this as any).shouldBreak) { - return text.split('\n').map(t => [createElement('span', t), createElement('br')]); + if (text.indexOf('\n') != -1) { + return text.split('\n').map(t => [createElement('span', t), createElement('br')]); + } else { + return createElement('span', text); + } } else { return createElement('span', text.replace(/\n/g, ' ')); } diff --git a/src/web/app/desktop/views/components/home.vue b/src/web/app/desktop/views/components/home.vue index eabcc485d..8a61c378e 100644 --- a/src/web/app/desktop/views/components/home.vue +++ b/src/web/app/desktop/views/components/home.vue @@ -1,7 +1,7 @@