From f4ee222e3c13caf51ad15d820a75665a3f1a51e3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 22 Apr 2018 09:10:10 -0500 Subject: [PATCH 01/26] make nsfw censor image configurable --- src/components/attachment/attachment.js | 2 +- src/main.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/attachment/attachment.js b/src/components/attachment/attachment.js index d9bc44774..ad46d0a1b 100644 --- a/src/components/attachment/attachment.js +++ b/src/components/attachment/attachment.js @@ -11,7 +11,7 @@ const Attachment = { ], data () { return { - nsfwImage, + nsfwImage: this.$store.state.config.nsfwCensorImage || nsfwImage, hideNsfwLocal: this.$store.state.config.hideNsfw, showHidden: false, loading: false, diff --git a/src/main.js b/src/main.js index 6f8c00f04..3d2bcbb03 100644 --- a/src/main.js +++ b/src/main.js @@ -96,6 +96,9 @@ window.fetch('/static/config.json') if (data['chatDisabled']) { store.dispatch('disableChat') } + if (data['nsfwCensorImage']) { + store.dispatch('setOption', { name: 'nsfwCensorImage', value: data['nsfwCensorImage'] }) + } const routes = [ { name: 'root', path: '/', redirect: data['defaultPath'] || '/main/all' }, From 8b1e1b182a63ebfd7a23e09efd964e843e340d81 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 4 Dec 2018 11:04:46 +0300 Subject: [PATCH 02/26] throttle fetching old statuses to prevent spam, especially during scroll --- src/components/timeline/timeline.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index a651f619b..f28b85bdd 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -2,6 +2,7 @@ import Status from '../status/status.vue' import timelineFetcher from '../../services/timeline_fetcher/timeline_fetcher.service.js' import StatusOrConversation from '../status_or_conversation/status_or_conversation.vue' import UserCard from '../user_card/user_card.vue' +import { throttle } from 'lodash' const Timeline = { props: [ @@ -88,7 +89,7 @@ const Timeline = { this.paused = false } }, - fetchOlderStatuses () { + fetchOlderStatuses: throttle(function () { const store = this.$store const credentials = store.state.users.currentUser.credentials store.commit('setLoading', { timeline: this.timelineName, value: true }) @@ -101,7 +102,7 @@ const Timeline = { userId: this.userId, tag: this.tag }).then(() => store.commit('setLoading', { timeline: this.timelineName, value: false })) - }, + }, 1000, this), fetchFollowers () { const id = this.userId this.$store.state.api.backendInteractor.fetchFollowers({ id }) From 403c86e4d1b0067634d1f0f6bd3d6908f8b4481b Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 5 Dec 2018 15:01:56 +0300 Subject: [PATCH 03/26] back button for mobile --- src/App.scss | 48 +++++++++++++++------- src/App.vue | 5 ++- src/components/user_finder/user_finder.vue | 5 +-- src/i18n/en.json | 1 + src/i18n/ru.json | 1 + 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/App.scss b/src/App.scss index 056a235ef..fcab3b1c2 100644 --- a/src/App.scss +++ b/src/App.scss @@ -206,24 +206,23 @@ i[class*=icon-] { padding: 0 10px 0 10px; } -.gaps { - margin: -1em 0 0 -1em; -} - .item { flex: 1; line-height: 50px; height: 50px; overflow: hidden; + display: flex; + flex-wrap: wrap; .nav-icon { font-size: 1.1em; margin-left: 0.4em; } -} -.gaps > .item { - padding: 1em 0 0 1em; + &.right { + justify-content: right; + padding-right: 20px; + } } .auto-size { @@ -271,8 +270,6 @@ nav { } .inner-nav { - padding-left: 20px; - padding-right: 20px; display: flex; align-items: center; flex-basis: 970px; @@ -392,6 +389,23 @@ nav { color: $fallback--faint; color: var(--faint, $fallback--faint); box-shadow: 0px 0px 4px rgba(0,0,0,.6); + + .back-button { + display: block; + max-width: 99px; + transition-property: opacity, max-width; + transition-duration: 300ms; + transition-timing-function: ease-out; + + i { + margin: 0 1em; + } + + &.hidden { + opacity: 0; + max-width: 20px; + } + } } .fade-enter-active, .fade-leave-active { @@ -426,6 +440,7 @@ nav { display: none; width: 100%; height: 46px; + button { display: block; flex: 1; @@ -439,6 +454,16 @@ nav { body { overflow-y: scroll; } + + nav { + .back-button { + display: none; + } + .site-name { + padding-left: 20px; + } + } + .sidebar-bounds { overflow: hidden; max-height: 100vh; @@ -505,11 +530,6 @@ nav { } } -.item.right { - text-align: right; - padding-right: 20px; -} - .visibility-tray { font-size: 1.2em; padding: 3px; diff --git a/src/App.vue b/src/App.vue index 9d66b9d4b..7716ac391 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,7 +7,10 @@
- {{sitename}} + + + + {{sitename}}
diff --git a/src/components/user_finder/user_finder.vue b/src/components/user_finder/user_finder.vue index 8786f6c76..4d9f68420 100644 --- a/src/components/user_finder/user_finder.vue +++ b/src/components/user_finder/user_finder.vue @@ -1,12 +1,12 @@ @@ -15,7 +15,6 @@ @import '../../_variables.scss'; .user-finder-container { - height: 29px; max-width: 100%; } diff --git a/src/i18n/en.json b/src/i18n/en.json index 8fd546efb..398b5dc9c 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -29,6 +29,7 @@ "username": "Username" }, "nav": { + "back": "Back", "chat": "Local Chat", "friend_requests": "Follow Requests", "mentions": "Mentions", diff --git a/src/i18n/ru.json b/src/i18n/ru.json index 9c28ccf4f..09c1a4a9f 100644 --- a/src/i18n/ru.json +++ b/src/i18n/ru.json @@ -19,6 +19,7 @@ "username": "Имя пользователя" }, "nav": { + "back": "Назад", "chat": "Локальный чат", "mentions": "Упоминания", "public_tl": "Публичная лента", From ba188eddab7f6eb8747bc43c179a8478d4f2a5a4 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Sat, 8 Dec 2018 18:23:21 +0300 Subject: [PATCH 04/26] [pleroma#36] Add upload errors --- src/boot/after_store.js | 3 ++- src/components/media_upload/media_upload.js | 4 ++++ src/components/post_status_form/post_status_form.js | 5 +++++ src/components/post_status_form/post_status_form.vue | 2 +- src/i18n/en.json | 2 ++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index a80baaf5e..38810326d 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -21,11 +21,12 @@ const afterStoreSetup = ({store, i18n}) => { window.fetch('/api/statusnet/config.json') .then((res) => res.json()) .then((data) => { - const {name, closed: registrationClosed, textlimit, server} = data.site + const {name, closed: registrationClosed, textlimit, uploadlimit, server} = data.site store.dispatch('setInstanceOption', { name: 'name', value: name }) store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) + store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit) }) store.dispatch('setInstanceOption', { name: 'server', value: server }) var apiConfig = data.site.pleromafe diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 66337c3f8..c2f3c3c71 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -21,6 +21,10 @@ const mediaUpload = { uploadFile (file) { const self = this const store = this.$store + if (file.size > store.state.instance.uploadlimit) { + self.$emit('upload-failed', 'upload_error_file_too_big') + return + } const formData = new FormData() formData.append('media', file) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 789243cf6..f7ba3cd5c 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -262,6 +262,11 @@ const PostStatusForm = { let index = this.newStatus.files.indexOf(fileInfo) this.newStatus.files.splice(index, 1) }, + uploadFailed (errString) { + errString = errString || 'upload_error' + this.error = this.$t('post_status.' + errString) + this.enableSubmit() + }, disableSubmit () { this.submitDisabled = true }, diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue index e4c46b9ac..59ae9af4d 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -64,7 +64,7 @@
- +

{{ charactersLeft }}

{{ charactersLeft }}

diff --git a/src/i18n/en.json b/src/i18n/en.json index 44291ad07..93a247431 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -52,6 +52,8 @@ "account_not_locked_warning": "Your account is not {0}. Anyone can follow you to view your follower-only posts.", "account_not_locked_warning_link": "locked", "attachments_sensitive": "Mark attachments as sensitive", + "upload_error": "Upload failed.", + "upload_error_file_too_big": "Upload failed. File too big", "content_type": { "plain_text": "Plain text" }, From 788383d8a1e10abe7f9848b95bf7eb284f1113cd Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 8 Dec 2018 21:56:00 +0100 Subject: [PATCH 05/26] Make uploadlimit an object that stores upload limits for avatars, banners, backgrounds, general content --- src/boot/after_store.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 38810326d..6a7669cec 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -26,7 +26,10 @@ const afterStoreSetup = ({store, i18n}) => { store.dispatch('setInstanceOption', { name: 'name', value: name }) store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) - store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit) }) + store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) }) + store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) }) + store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) }) + store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) }) store.dispatch('setInstanceOption', { name: 'server', value: server }) var apiConfig = data.site.pleromafe From f69331e49d19a26be27d1188f721703fe04a493d Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 8 Dec 2018 22:36:54 +0100 Subject: [PATCH 06/26] Improve error messages --- src/components/media_upload/media_upload.js | 4 ++-- src/components/post_status_form/post_status_form.js | 6 +++--- src/i18n/en.json | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index c2f3c3c71..91ae36274 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -22,7 +22,7 @@ const mediaUpload = { const self = this const store = this.$store if (file.size > store.state.instance.uploadlimit) { - self.$emit('upload-failed', 'upload_error_file_too_big') + self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: file.size, allowedsize: store.state.instance.uploadlimit}) return } const formData = new FormData() @@ -36,7 +36,7 @@ const mediaUpload = { self.$emit('uploaded', fileData) self.uploading = false }, (error) => { // eslint-disable-line handle-callback-err - self.$emit('upload-failed') + self.$emit('upload-failed', 'upload_error_generic') self.uploading = false }) }, diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index f7ba3cd5c..5f092da35 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -262,9 +262,9 @@ const PostStatusForm = { let index = this.newStatus.files.indexOf(fileInfo) this.newStatus.files.splice(index, 1) }, - uploadFailed (errString) { - errString = errString || 'upload_error' - this.error = this.$t('post_status.' + errString) + uploadFailed (errString, templateArgs) { + templateArgs = templateArgs || {}; + this.error = this.$t('post_status.upload_error') + ' ' + this.$t('post_status.' + errString, templateArgs) this.enableSubmit() }, disableSubmit () { diff --git a/src/i18n/en.json b/src/i18n/en.json index 93a247431..17c28c617 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -53,7 +53,8 @@ "account_not_locked_warning_link": "locked", "attachments_sensitive": "Mark attachments as sensitive", "upload_error": "Upload failed.", - "upload_error_file_too_big": "Upload failed. File too big", + "upload_error_file_too_big": "File too big [{filesize}/{allowedsize}]", + "upload_error_generic": "Try again later", "content_type": { "plain_text": "Plain text" }, From 4fde987e34c6b76c67d73ff1d163e8a5fed53069 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 8 Dec 2018 22:39:58 +0100 Subject: [PATCH 07/26] Fix formating --- src/components/post_status_form/post_status_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 5f092da35..f8225fb24 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -263,7 +263,7 @@ const PostStatusForm = { this.newStatus.files.splice(index, 1) }, uploadFailed (errString, templateArgs) { - templateArgs = templateArgs || {}; + templateArgs = templateArgs || {} this.error = this.$t('post_status.upload_error') + ' ' + this.$t('post_status.' + errString, templateArgs) this.enableSubmit() }, From c69a8dc197c87eb69272c28c1c1501e3c6d6d9aa Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Mon, 10 Dec 2018 09:50:04 +0300 Subject: [PATCH 08/26] Add file size formating --- src/components/media_upload/media_upload.js | 4 +++- src/i18n/en.json | 7 +++++++ .../file_size_format/.file_size_format.js.swp | Bin 0 -> 12288 bytes .../file_size_format/file_size_format.js | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/services/file_size_format/.file_size_format.js.swp create mode 100644 src/services/file_size_format/file_size_format.js diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 91ae36274..1927a1948 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -1,5 +1,7 @@ /* eslint-env browser */ import statusPosterService from '../../services/status_poster/status_poster.service.js' +import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' + const mediaUpload = { mounted () { @@ -22,7 +24,7 @@ const mediaUpload = { const self = this const store = this.$store if (file.size > store.state.instance.uploadlimit) { - self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: file.size, allowedsize: store.state.instance.uploadlimit}) + self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: fileSizeFormatService.fileSizeFormat(file.size, self.$t), allowedsize: fileSizeFormatService.fileSizeFormat(store.state.instance.uploadlimit, self.$t)}) return } const formData = new FormData() diff --git a/src/i18n/en.json b/src/i18n/en.json index 17c28c617..885974e42 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -229,5 +229,12 @@ "reply": "Reply", "favorite": "Favorite", "user_settings": "User Settings" + }, + "file_size_units": { + "B": "B", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB" } } diff --git a/src/services/file_size_format/.file_size_format.js.swp b/src/services/file_size_format/.file_size_format.js.swp new file mode 100644 index 0000000000000000000000000000000000000000..ec2e601a88a5a48a3ac815db974cb0346e64ff92 GIT binary patch literal 12288 zcmeI2&2G~`5XaX@hyyfyJpe-yicK5aDH6(|0Tn?JLOGy9F9B61S+_>EH(IYt1pT#gg(Kc`eW#ilFE+EYG&fsJAOHd&00JNY0w4eaAOHd&00JNY0{m19*`)p%k zfB*=900@8p2!H?xfB*=900{hD0UVufx_jc;=$KLN3F@D2a~ literal 0 HcmV?d00001 diff --git a/src/services/file_size_format/file_size_format.js b/src/services/file_size_format/file_size_format.js new file mode 100644 index 000000000..5d22b4734 --- /dev/null +++ b/src/services/file_size_format/file_size_format.js @@ -0,0 +1,17 @@ +const fileSizeFormat = (num, t) => { + var exponent + var unit + var units = [t('file_size_units.B'), t('file_size_units.KB'), t('file_size_units.MB'), t('file_size_units.GB'), t('file_size_units.TB')] + if (num < 1) { + return num + ' ' + units[0] + } + + exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1) + num = (num / Math.pow(1000, exponent)).toFixed(2) * 1 + unit = units[exponent] + return num + ' ' + unit +} +const fileSizeFormatService = { + fileSizeFormat +} +export default fileSizeFormatService From 5c7a316df96ef81dde37d27a816616017192a415 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Mon, 10 Dec 2018 09:56:07 +0300 Subject: [PATCH 09/26] Lint --- src/components/media_upload/media_upload.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 1927a1948..37dab32bf 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -2,7 +2,6 @@ import statusPosterService from '../../services/status_poster/status_poster.service.js' import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' - const mediaUpload = { mounted () { const input = this.$el.querySelector('input') From 88145c5934c08e3fcfac03c148c16299c3697109 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Mon, 10 Dec 2018 10:04:42 +0300 Subject: [PATCH 10/26] Add a space between filesizes --- src/i18n/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/en.json b/src/i18n/en.json index 885974e42..ace0a315c 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -53,7 +53,7 @@ "account_not_locked_warning_link": "locked", "attachments_sensitive": "Mark attachments as sensitive", "upload_error": "Upload failed.", - "upload_error_file_too_big": "File too big [{filesize}/{allowedsize}]", + "upload_error_file_too_big": "File too big [{filesize} / {allowedsize}]", "upload_error_generic": "Try again later", "content_type": { "plain_text": "Plain text" From 6a008541898e354fbd98857787020640407b1dd3 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Mon, 10 Dec 2018 17:06:32 +0300 Subject: [PATCH 11/26] Count in binary bytes and remove i18 from file size format service --- src/components/media_upload/media_upload.js | 4 +++- src/i18n/en.json | 10 +++++----- .../file_size_format/.file_size_format.js.swp | Bin 12288 -> 0 bytes .../file_size_format/file_size_format.js | 10 +++++----- 4 files changed, 13 insertions(+), 11 deletions(-) delete mode 100644 src/services/file_size_format/.file_size_format.js.swp diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 37dab32bf..31d364877 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -23,7 +23,9 @@ const mediaUpload = { const self = this const store = this.$store if (file.size > store.state.instance.uploadlimit) { - self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: fileSizeFormatService.fileSizeFormat(file.size, self.$t), allowedsize: fileSizeFormatService.fileSizeFormat(store.state.instance.uploadlimit, self.$t)}) + const filesize = fileSizeFormatService.fileSizeFormat(file.size) + const allowedsize = fileSizeFormatService.fileSizeFormat(store.state.instance.uploadlimit) + self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}) return } const formData = new FormData() diff --git a/src/i18n/en.json b/src/i18n/en.json index ace0a315c..5697bae70 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -53,7 +53,7 @@ "account_not_locked_warning_link": "locked", "attachments_sensitive": "Mark attachments as sensitive", "upload_error": "Upload failed.", - "upload_error_file_too_big": "File too big [{filesize} / {allowedsize}]", + "upload_error_file_too_big": "File too big [{filesize}{filesizeunit} / {allowedsize}{allowedsizeunit}]", "upload_error_generic": "Try again later", "content_type": { "plain_text": "Plain text" @@ -232,9 +232,9 @@ }, "file_size_units": { "B": "B", - "KB": "KB", - "MB": "MB", - "GB": "GB", - "TB": "TB" + "KiB": "KiB", + "MiB": "MiB", + "GiB": "GiB", + "TiB": "TiB" } } diff --git a/src/services/file_size_format/.file_size_format.js.swp b/src/services/file_size_format/.file_size_format.js.swp deleted file mode 100644 index ec2e601a88a5a48a3ac815db974cb0346e64ff92..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2&2G~`5XaX@hyyfyJpe-yicK5aDH6(|0Tn?JLOGy9F9B61S+_>EH(IYt1pT#gg(Kc`eW#ilFE+EYG&fsJAOHd&00JNY0w4eaAOHd&00JNY0{m19*`)p%k zfB*=900@8p2!H?xfB*=900{hD0UVufx_jc;=$KLN3F@D2a~ diff --git a/src/services/file_size_format/file_size_format.js b/src/services/file_size_format/file_size_format.js index 5d22b4734..add56ee03 100644 --- a/src/services/file_size_format/file_size_format.js +++ b/src/services/file_size_format/file_size_format.js @@ -1,15 +1,15 @@ -const fileSizeFormat = (num, t) => { +const fileSizeFormat = (num) => { var exponent var unit - var units = [t('file_size_units.B'), t('file_size_units.KB'), t('file_size_units.MB'), t('file_size_units.GB'), t('file_size_units.TB')] + var units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'] if (num < 1) { return num + ' ' + units[0] } - exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1) - num = (num / Math.pow(1000, exponent)).toFixed(2) * 1 + exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1) + num = (num / Math.pow(1024, exponent)).toFixed(2) * 1 unit = units[exponent] - return num + ' ' + unit + return {num: num, unit: unit} } const fileSizeFormatService = { fileSizeFormat From 25a04f2294a4ed4d9cf527d8ee2d2899400447dd Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Tue, 11 Dec 2018 16:02:35 +0300 Subject: [PATCH 12/26] Avatar, background, banner filesize errors --- src/components/user_settings/user_settings.js | 40 +++++++++++++++++++ .../user_settings/user_settings.vue | 12 ++++++ 2 files changed, 52 insertions(+) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 761e674ad..ed9178fa7 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -1,9 +1,13 @@ import TabSwitcher from '../tab_switcher/tab_switcher.jsx' import StyleSwitcher from '../style_switcher/style_switcher.vue' +import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' const UserSettings = { data () { return { + avataruploaderror: null, + backgrounduploaderror: null, + banneruploaderror: null, newname: this.$store.state.users.currentUser.name, newbio: this.$store.state.users.currentUser.description, newlocked: this.$store.state.users.currentUser.locked, @@ -69,6 +73,29 @@ const UserSettings = { uploadFile (slot, e) { const file = e.target.files[0] if (!file) { return } + var limit = 0 + var error = () => {} + switch (slot) { + case 0: + limit = this.$store.state.instance.avatarlimit + error = (error) => { this.avataruploaderror = error } + break + case 1: + limit = this.$store.state.instance.bannerlimit + error = (error) => { this.banneruploaderror = error } + break + case 2: + limit = this.$store.state.instance.backgroundlimit + error = (error) => { this.backgrounduploaderror = error } + } + console.log(this.$store) + console.log(file.size + ' ' + slot + ' ' + limit) + if (file.size > limit) { + const filesize = fileSizeFormatService.fileSizeFormat(file.size) + const allowedsize = fileSizeFormatService.fileSizeFormat(limit) + error(this.$t('post_status.upload_error_file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})) + return + } // eslint-disable-next-line no-undef const reader = new FileReader() reader.onload = ({target}) => { @@ -107,6 +134,19 @@ const UserSettings = { this.uploading[0] = false }) }, + clearUploadError (slot) { + switch (slot) { + case 0: + this.avataruploaderror = null + break + case 1: + this.banneruploaderror = null + break + case 2: + this.backgrounduploaderror = null + break + } + }, submitBanner () { if (!this.previews[1]) { return } diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 234a7d862..12bc953e6 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -43,6 +43,10 @@
+
+ Error: {{ avataruploaderror }} + +

{{$t('settings.profile_banner')}}

@@ -56,6 +60,10 @@
+
+ Error: {{ banneruploaderror }} + +

{{$t('settings.profile_background')}}

@@ -67,6 +75,10 @@
+
+ Error: {{ backgrounduploaderror }} + +
From bf8bb9ce134c8712885e52d005c6d130fca4e553 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Wed, 12 Dec 2018 16:38:01 +0300 Subject: [PATCH 13/26] Moved upload errors in user_settings to an array. Moved upload error strings to its separate section in i18n --- src/components/media_upload/media_upload.js | 4 +- .../post_status_form/post_status_form.js | 2 +- src/components/user_settings/user_settings.js | 41 ++++--------------- .../user_settings/user_settings.vue | 12 +++--- src/i18n/en.json | 22 ++++++---- 5 files changed, 29 insertions(+), 52 deletions(-) diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 31d364877..42d900d35 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -25,7 +25,7 @@ const mediaUpload = { if (file.size > store.state.instance.uploadlimit) { const filesize = fileSizeFormatService.fileSizeFormat(file.size) const allowedsize = fileSizeFormatService.fileSizeFormat(store.state.instance.uploadlimit) - self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}) + self.$emit('upload-failed', 'file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}) return } const formData = new FormData() @@ -39,7 +39,7 @@ const mediaUpload = { self.$emit('uploaded', fileData) self.uploading = false }, (error) => { // eslint-disable-line handle-callback-err - self.$emit('upload-failed', 'upload_error_generic') + self.$emit('upload-failed', 'default') self.uploading = false }) }, diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index f8225fb24..3899027f3 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -264,7 +264,7 @@ const PostStatusForm = { }, uploadFailed (errString, templateArgs) { templateArgs = templateArgs || {} - this.error = this.$t('post_status.upload_error') + ' ' + this.$t('post_status.' + errString, templateArgs) + this.error = this.$t('upload.error.base') + ' ' + this.$t('upload.error.' + errString, templateArgs) this.enableSubmit() }, disableSubmit () { diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index ed9178fa7..424d0b858 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -5,9 +5,7 @@ import fileSizeFormatService from '../../services/file_size_format/file_size_for const UserSettings = { data () { return { - avataruploaderror: null, - backgrounduploaderror: null, - banneruploaderror: null, + uploaderror: [null, null, null], newname: this.$store.state.users.currentUser.name, newbio: this.$store.state.users.currentUser.description, newlocked: this.$store.state.users.currentUser.locked, @@ -73,27 +71,12 @@ const UserSettings = { uploadFile (slot, e) { const file = e.target.files[0] if (!file) { return } - var limit = 0 - var error = () => {} - switch (slot) { - case 0: - limit = this.$store.state.instance.avatarlimit - error = (error) => { this.avataruploaderror = error } - break - case 1: - limit = this.$store.state.instance.bannerlimit - error = (error) => { this.banneruploaderror = error } - break - case 2: - limit = this.$store.state.instance.backgroundlimit - error = (error) => { this.backgrounduploaderror = error } - } - console.log(this.$store) - console.log(file.size + ' ' + slot + ' ' + limit) - if (file.size > limit) { + var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit] + console.log(file.size, limit) + if (file.size > limit[slot]) { const filesize = fileSizeFormatService.fileSizeFormat(file.size) - const allowedsize = fileSizeFormatService.fileSizeFormat(limit) - error(this.$t('post_status.upload_error_file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})) + const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot]) + this.$set(this.uploaderror, slot, this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})) return } // eslint-disable-next-line no-undef @@ -135,17 +118,7 @@ const UserSettings = { }) }, clearUploadError (slot) { - switch (slot) { - case 0: - this.avataruploaderror = null - break - case 1: - this.banneruploaderror = null - break - case 2: - this.backgrounduploaderror = null - break - } + this.$set(this.uploaderror, slot, null) }, submitBanner () { if (!this.previews[1]) { return } diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 12bc953e6..22c4fe413 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -43,8 +43,8 @@ -
- Error: {{ avataruploaderror }} +
+ Error: {{ uploaderror[0] }}
@@ -60,8 +60,8 @@ -
- Error: {{ banneruploaderror }} +
+ Error: {{ uploaderror[1] }}
@@ -75,8 +75,8 @@ -
- Error: {{ backgrounduploaderror }} +
+ Error: {{ uploaderror[2] }}
diff --git a/src/i18n/en.json b/src/i18n/en.json index 5697bae70..dae2f2867 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -52,9 +52,6 @@ "account_not_locked_warning": "Your account is not {0}. Anyone can follow you to view your follower-only posts.", "account_not_locked_warning_link": "locked", "attachments_sensitive": "Mark attachments as sensitive", - "upload_error": "Upload failed.", - "upload_error_file_too_big": "File too big [{filesize}{filesizeunit} / {allowedsize}{allowedsizeunit}]", - "upload_error_generic": "Try again later", "content_type": { "plain_text": "Plain text" }, @@ -230,11 +227,18 @@ "favorite": "Favorite", "user_settings": "User Settings" }, - "file_size_units": { - "B": "B", - "KiB": "KiB", - "MiB": "MiB", - "GiB": "GiB", - "TiB": "TiB" + "upload":{ + "error": { + "base": "Upload failed.", + "file_too_big": "File too big [{filesize}{filesizeunit} / {allowedsize}{allowedsizeunit}]", + "default": "Try again later" + }, + "file_size_units": { + "B": "B", + "KiB": "KiB", + "MiB": "MiB", + "GiB": "GiB", + "TiB": "TiB" + } } } From 5ca2e75df36f3848f6003da2525051c8e9e275b1 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Wed, 12 Dec 2018 19:31:16 +0300 Subject: [PATCH 14/26] Handle errors from server --- src/components/user_settings/user_settings.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 424d0b858..cf37e71a2 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -113,6 +113,8 @@ const UserSettings = { this.$store.commit('addNewUsers', [user]) this.$store.commit('setCurrentUser', user) this.previews[0] = null + } else { + this.$set(this.uploaderror, 0, this.$t('upload.error.base') + user.error) } this.uploading[0] = false }) @@ -141,6 +143,8 @@ const UserSettings = { this.$store.commit('addNewUsers', [clone]) this.$store.commit('setCurrentUser', clone) this.previews[1] = null + } else { + this.$set(this.uploaderror, 1, this.$t('upload.error.base') + data.error) } this.uploading[1] = false }) @@ -165,6 +169,8 @@ const UserSettings = { this.$store.commit('addNewUsers', [clone]) this.$store.commit('setCurrentUser', clone) this.previews[2] = null + } else { + this.$set(this.uploaderror, 2, this.$t('upload.error.base') + data.error) } this.uploading[2] = false }) From 9c24ac1d050914861891bd1f5137159e91890d86 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Wed, 12 Dec 2018 20:01:37 +0300 Subject: [PATCH 15/26] I am dumb --- src/components/user_settings/user_settings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index cf37e71a2..504976a5a 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -72,7 +72,6 @@ const UserSettings = { const file = e.target.files[0] if (!file) { return } var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit] - console.log(file.size, limit) if (file.size > limit[slot]) { const filesize = fileSizeFormatService.fileSizeFormat(file.size) const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot]) From fa7fbe05decc7b5f3a52560b1f8ebe1f9b3f91ef Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Wed, 12 Dec 2018 20:41:12 +0300 Subject: [PATCH 16/26] Write a unit test for fileSizeFormatService --- .../file_size_format/file_size_format.spec.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/unit/specs/services/file_size_format/file_size_format.spec.js diff --git a/test/unit/specs/services/file_size_format/file_size_format.spec.js b/test/unit/specs/services/file_size_format/file_size_format.spec.js new file mode 100644 index 000000000..0a5a82b7f --- /dev/null +++ b/test/unit/specs/services/file_size_format/file_size_format.spec.js @@ -0,0 +1,34 @@ + import fileSizeFormatService from '../../../../../src/services/file_size_format/file_size_format.js' + describe('fileSizeFormat', () => { + it('Formats file size', () => { + const values = [1, 1024, 1048576, 1073741824, 1099511627776] + const expected = [ + { + num: 1, + unit: 'B' + }, + { + num: 1, + unit: 'KiB' + }, + { + num: 1, + unit: 'MiB' + }, + { + num: 1, + unit: 'GiB' + }, + { + num: 1, + unit: 'TiB' + } + ] + + var res = [] + for (var value in values) { + res.push(fileSizeFormatService.fileSizeFormat(values[value])) + } + expect(res).to.eql(expected) + }) + }) From 33c2d21bb7ca21ed0e7358aac7721c48d13aa03c Mon Sep 17 00:00:00 2001 From: link0ff Date: Wed, 12 Dec 2018 22:00:04 +0200 Subject: [PATCH 17/26] Reset enableFollowsExport to true after 2 sec when an export file is available to download --- src/components/user_settings/user_settings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 761e674ad..1712e64c1 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -198,6 +198,7 @@ const UserSettings = { .fetchFriends({id: this.$store.state.users.currentUser.id}) .then((friendList) => { this.exportPeople(friendList, 'friends.csv') + setTimeout(() => { this.enableFollowsExport = true }, 2000) }) }, followListChange () { From 48edc0c8fcc6c63e432c9b6d78f14af086b56900 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Thu, 13 Dec 2018 11:25:03 +0300 Subject: [PATCH 18/26] Refactor arrays to individual options --- src/components/user_settings/user_settings.js | 94 +++++++++++++------ .../user_settings/user_settings.vue | 32 +++---- 2 files changed, 83 insertions(+), 43 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 504976a5a..0f3f08595 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -5,7 +5,6 @@ import fileSizeFormatService from '../../services/file_size_format/file_size_for const UserSettings = { data () { return { - uploaderror: [null, null, null], newname: this.$store.state.users.currentUser.name, newbio: this.$store.state.users.currentUser.description, newlocked: this.$store.state.users.currentUser.locked, @@ -15,8 +14,16 @@ const UserSettings = { followImportError: false, followsImported: false, enableFollowsExport: true, - uploading: [ false, false, false, false ], - previews: [ null, null, null ], + avatarUploading: false, + bannerUploading: false, + backgroundUploading: false, + followListUploading: false, + avatarPreview: null, + bannerPreview: null, + backgroundPreview: null, + avatarUploadError: null, + bannerUploadError: null, + backgroundUploadError: null, deletingAccount: false, deleteAccountConfirmPasswordInput: '', deleteAccountError: false, @@ -71,26 +78,49 @@ const UserSettings = { uploadFile (slot, e) { const file = e.target.files[0] if (!file) { return } + var error = () => {} + switch (slot) { + case 0: + error = (error) => { this.avatarUploadError = error } + break + case 1: + error = (error) => { this.bannerUploadError = error } + break + case 2: + error = (error) => { this.backgroundUploadError = error } + break + } var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit] if (file.size > limit[slot]) { const filesize = fileSizeFormatService.fileSizeFormat(file.size) const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot]) - this.$set(this.uploaderror, slot, this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})) + error(this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})) return } // eslint-disable-next-line no-undef const reader = new FileReader() reader.onload = ({target}) => { const img = target.result - this.previews[slot] = img - this.$forceUpdate() // just changing the array with the index doesn't update the view + var preview = () => {} + switch (slot) { + case 0: + preview = (preview) => { this.avatarPreview = preview } + break + case 1: + preview = (preview) => { this.bannerPreview = preview } + break + case 2: + preview = (preview) => { this.backgroundPreview = preview } + break + } + preview(img) } reader.readAsDataURL(file) }, submitAvatar () { - if (!this.previews[0]) { return } + if (!this.avatarPreview) { return } - let img = this.previews[0] + let img = this.avatarPreview // eslint-disable-next-line no-undef let imginfo = new Image() let cropX, cropY, cropW, cropH @@ -106,25 +136,35 @@ const UserSettings = { cropX = Math.floor((imginfo.width - imginfo.height) / 2) cropW = imginfo.height } - this.uploading[0] = true + this.avatarUploading = true this.$store.state.api.backendInteractor.updateAvatar({params: {img, cropX, cropY, cropW, cropH}}).then((user) => { if (!user.error) { this.$store.commit('addNewUsers', [user]) this.$store.commit('setCurrentUser', user) - this.previews[0] = null + this.avatarPreview = null } else { - this.$set(this.uploaderror, 0, this.$t('upload.error.base') + user.error) + this.avatarUploadError = this.$t('upload.error.base') + user.error } - this.uploading[0] = false + this.avatarUploading = false }) }, clearUploadError (slot) { - this.$set(this.uploaderror, slot, null) + switch (slot) { + case 0: + this.avatarUploadError = null + break + case 1: + this.bannerUploadError = null + break + case 2: + this.backgroundUploadError = null + break + } }, submitBanner () { - if (!this.previews[1]) { return } + if (!this.bannerPreview) { return } - let banner = this.previews[1] + let banner = this.bannerPreview // eslint-disable-next-line no-undef let imginfo = new Image() /* eslint-disable camelcase */ @@ -134,24 +174,24 @@ const UserSettings = { height = imginfo.height offset_top = 0 offset_left = 0 - this.uploading[1] = true + this.bannerUploading = true this.$store.state.api.backendInteractor.updateBanner({params: {banner, offset_top, offset_left, width, height}}).then((data) => { if (!data.error) { let clone = JSON.parse(JSON.stringify(this.$store.state.users.currentUser)) clone.cover_photo = data.url this.$store.commit('addNewUsers', [clone]) this.$store.commit('setCurrentUser', clone) - this.previews[1] = null + this.bannerPreview = null } else { - this.$set(this.uploaderror, 1, this.$t('upload.error.base') + data.error) + this.bannerUploadError = this.$t('upload.error.base') + data.error } - this.uploading[1] = false + this.bannerUploading = false }) /* eslint-enable camelcase */ }, submitBg () { - if (!this.previews[2]) { return } - let img = this.previews[2] + if (!this.backgroundPreview) { return } + let img = this.backgroundPreview // eslint-disable-next-line no-undef let imginfo = new Image() let cropX, cropY, cropW, cropH @@ -160,22 +200,22 @@ const UserSettings = { cropY = 0 cropW = imginfo.width cropH = imginfo.width - this.uploading[2] = true + this.backgroundUploading = true this.$store.state.api.backendInteractor.updateBg({params: {img, cropX, cropY, cropW, cropH}}).then((data) => { if (!data.error) { let clone = JSON.parse(JSON.stringify(this.$store.state.users.currentUser)) clone.background_image = data.url this.$store.commit('addNewUsers', [clone]) this.$store.commit('setCurrentUser', clone) - this.previews[2] = null + this.backgroundPreview = null } else { - this.$set(this.uploaderror, 2, this.$t('upload.error.base') + data.error) + this.backgroundUploadError = this.$t('upload.error.base') + data.error } - this.uploading[2] = false + this.backgroundUploading = false }) }, importFollows () { - this.uploading[3] = true + this.followListUploading = true const followList = this.followList this.$store.state.api.backendInteractor.followImport({params: followList}) .then((status) => { @@ -184,7 +224,7 @@ const UserSettings = { } else { this.followImportError = true } - this.uploading[3] = false + this.followListUploading = false }) }, /* This function takes an Array of Users diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 22c4fe413..5883775c5 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -36,15 +36,15 @@

{{$t('settings.current_avatar')}}

{{$t('settings.set_new_avatar')}}

- +
- - -
- Error: {{ uploaderror[0] }} + + +
+ Error: {{ avatarUploadError }}
@@ -53,30 +53,30 @@

{{$t('settings.current_profile_banner')}}

{{$t('settings.set_new_profile_banner')}}

- +
- - -
- Error: {{ uploaderror[1] }} + + +
+ Error: {{ bannerUploadError }}

{{$t('settings.profile_background')}}

{{$t('settings.set_new_profile_background')}}

- +
- - -
- Error: {{ uploaderror[2] }} + + +
+ Error: {{ backgroundUploadError }}
@@ -125,7 +125,7 @@
- +
From 42bb34821908430cdfdbad827567049e3bf22b22 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 13 Dec 2018 15:34:51 +0300 Subject: [PATCH 19/26] Fix fetching new users, add storing local users in usersObjects with their screen_name as well as id, so that they could be fetched zero-state with screen-name link. --- src/components/user_profile/user_profile.vue | 18 ++++++++++++++++++ src/modules/users.js | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index 91d4acd29..4d2853a63 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -3,6 +3,16 @@ +
@@ -21,4 +31,12 @@ align-items: stretch; } } +.user-profile-placeholder { + .panel-body { + display: flex; + justify-content: center; + align-items: middle; + padding: 7em; + } +} diff --git a/src/modules/users.js b/src/modules/users.js index 6d966c3bb..97e1a3187 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -16,6 +16,9 @@ export const mergeOrAdd = (arr, obj, item) => { // This is a new item, prepare it arr.push(item) obj[item.id] = item + if (item.screen_name && !item.screen_name.includes('@')) { + obj[item.screen_name] = item + } return {item, new: true} } } @@ -78,7 +81,7 @@ const users = { actions: { fetchUser (store, id) { store.rootState.api.backendInteractor.fetchUser({id}) - .then((user) => store.commit('addNewUsers', user)) + .then((user) => store.commit('addNewUsers', [user])) }, addNewStatuses (store, { statuses }) { const users = map(statuses, 'user') From c52b8019ae6a248a392f925c8ec5086289ce679e Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 13 Dec 2018 15:58:38 +0300 Subject: [PATCH 20/26] added hide_network option, fixed properties naming --- src/components/user_settings/user_settings.js | 55 ++++++++++++------- .../user_settings/user_settings.vue | 14 +++-- src/i18n/en.json | 1 + src/i18n/ru.json | 1 + 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 761e674ad..8e57894cf 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -4,11 +4,12 @@ import StyleSwitcher from '../style_switcher/style_switcher.vue' const UserSettings = { data () { return { - newname: this.$store.state.users.currentUser.name, - newbio: this.$store.state.users.currentUser.description, - newlocked: this.$store.state.users.currentUser.locked, - newnorichtext: this.$store.state.users.currentUser.no_rich_text, - newdefaultScope: this.$store.state.users.currentUser.default_scope, + newName: this.$store.state.users.currentUser.name, + newBio: this.$store.state.users.currentUser.description, + newLocked: this.$store.state.users.currentUser.locked, + newNoRichText: this.$store.state.users.currentUser.no_rich_text, + newDefaultScope: this.$store.state.users.currentUser.default_scope, + newHideNetwork: this.$store.state.users.currentUser.hide_network, followList: null, followImportError: false, followsImported: false, @@ -40,31 +41,45 @@ const UserSettings = { }, vis () { return { - public: { selected: this.newdefaultScope === 'public' }, - unlisted: { selected: this.newdefaultScope === 'unlisted' }, - private: { selected: this.newdefaultScope === 'private' }, - direct: { selected: this.newdefaultScope === 'direct' } + public: { selected: this.newDefaultScope === 'public' }, + unlisted: { selected: this.newDefaultScope === 'unlisted' }, + private: { selected: this.newDefaultScope === 'private' }, + direct: { selected: this.newDefaultScope === 'direct' } } } }, methods: { updateProfile () { const name = this.newname - const description = this.newbio - const locked = this.newlocked + const description = this.newBio + const locked = this.newLocked + // Backend notation. /* eslint-disable camelcase */ - const default_scope = this.newdefaultScope - const no_rich_text = this.newnorichtext - this.$store.state.api.backendInteractor.updateProfile({params: {name, description, locked, default_scope, no_rich_text}}).then((user) => { - if (!user.error) { - this.$store.commit('addNewUsers', [user]) - this.$store.commit('setCurrentUser', user) - } - }) + const default_scope = this.newDefaultScope + const no_rich_text = this.newNoRichText + const hide_network = this.newHideNetwork /* eslint-enable camelcase */ + this.$store.state.api.backendInteractor + .updateProfile({ + params: { + name, + description, + locked, + // Backend notation. + /* eslint-disable camelcase */ + default_scope, + no_rich_text, + hide_network + /* eslint-enable camelcase */ + }}).then((user) => { + if (!user.error) { + this.$store.commit('addNewUsers', [user]) + this.$store.commit('setCurrentUser', user) + } + }) }, changeVis (visibility) { - this.newdefaultScope = visibility + this.newDefaultScope = visibility }, uploadFile (slot, e) { const file = e.target.files[0] diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 234a7d862..116294400 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -9,11 +9,11 @@

{{$t('settings.name_bio')}}

{{$t('settings.name')}}

- +

{{$t('settings.bio')}}

- +

- +

@@ -26,10 +26,14 @@

- +

- +

+ + +

+

{{$t('settings.avatar')}}

diff --git a/src/i18n/en.json b/src/i18n/en.json index 92429e4b1..b094e9b8b 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -151,6 +151,7 @@ "notification_visibility_mentions": "Mentions", "notification_visibility_repeats": "Repeats", "no_rich_text_description": "Strip rich text formatting from all posts", + "hide_network_description": "Don't show who I'm following and who's following me", "nsfw_clickthrough": "Enable clickthrough NSFW attachment hiding", "panelRadius": "Panels", "pause_on_unfocused": "Pause streaming when tab is not focused", diff --git a/src/i18n/ru.json b/src/i18n/ru.json index c764005a5..13c7fec3f 100644 --- a/src/i18n/ru.json +++ b/src/i18n/ru.json @@ -126,6 +126,7 @@ "notification_visibility_mentions": "Упоминания", "notification_visibility_repeats": "Повторы", "no_rich_text_description": "Убрать форматирование из всех постов", + "hide_network_description": "Не показывать кого я читаю и кто меня читает", "nsfw_clickthrough": "Включить скрытие NSFW вложений", "panelRadius": "Панели", "pause_on_unfocused": "Приостановить загрузку когда вкладка не в фокусе", From 457132fb378b70a630fd4dc1b723488901b95c83 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 13 Dec 2018 15:44:37 +0100 Subject: [PATCH 21/26] get rid of slots --- src/components/user_settings/user_settings.js | 40 ++----------------- .../user_settings/user_settings.vue | 12 +++--- 2 files changed, 9 insertions(+), 43 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 0f3f08595..88cdb3bfe 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -78,42 +78,18 @@ const UserSettings = { uploadFile (slot, e) { const file = e.target.files[0] if (!file) { return } - var error = () => {} - switch (slot) { - case 0: - error = (error) => { this.avatarUploadError = error } - break - case 1: - error = (error) => { this.bannerUploadError = error } - break - case 2: - error = (error) => { this.backgroundUploadError = error } - break - } var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit] if (file.size > limit[slot]) { const filesize = fileSizeFormatService.fileSizeFormat(file.size) const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot]) - error(this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})) + this[slot + 'UploadError'] = this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}) return } // eslint-disable-next-line no-undef const reader = new FileReader() reader.onload = ({target}) => { const img = target.result - var preview = () => {} - switch (slot) { - case 0: - preview = (preview) => { this.avatarPreview = preview } - break - case 1: - preview = (preview) => { this.bannerPreview = preview } - break - case 2: - preview = (preview) => { this.backgroundPreview = preview } - break - } - preview(img) + this[slot + 'Preview'] = img } reader.readAsDataURL(file) }, @@ -149,17 +125,7 @@ const UserSettings = { }) }, clearUploadError (slot) { - switch (slot) { - case 0: - this.avatarUploadError = null - break - case 1: - this.bannerUploadError = null - break - case 2: - this.backgroundUploadError = null - break - } + this[slot + 'UploadError'] = null }, submitBanner () { if (!this.bannerPreview) { return } diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 5883775c5..1a98b788d 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -39,13 +39,13 @@
- +
Error: {{ avatarUploadError }} - +
@@ -56,13 +56,13 @@
- +
Error: {{ bannerUploadError }} - +
@@ -71,13 +71,13 @@
- +
Error: {{ backgroundUploadError }} - +
From dd6a9ae6458784b36ffe2376492284ae4e79fece Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Thu, 13 Dec 2018 17:51:29 +0300 Subject: [PATCH 22/26] oof --- src/components/user_settings/user_settings.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 88cdb3bfe..43e39b139 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -78,10 +78,9 @@ const UserSettings = { uploadFile (slot, e) { const file = e.target.files[0] if (!file) { return } - var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit] - if (file.size > limit[slot]) { + if (file.size > this.$store.state.instance[slot + 'limit']) { const filesize = fileSizeFormatService.fileSizeFormat(file.size) - const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot]) + const allowedsize = fileSizeFormatService.fileSizeFormat(this.$store.state.instance[slot + 'limit']) this[slot + 'UploadError'] = this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}) return } From f87001c22f8c85bddb78c975f0bc22b8bfdcd27c Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 13 Dec 2018 20:25:46 +0300 Subject: [PATCH 23/26] fix old MR --- src/boot/after_store.js | 4 ++++ src/main.js | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 07337595f..a8594a643 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -28,6 +28,10 @@ const afterStoreSetup = ({ store, i18n }) => { store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) store.dispatch('setInstanceOption', { name: 'server', value: server }) + if (data.nsfwCensorImage) { + store.dispatch('setInstanceOption', { name: 'nsfwCensorImage', value: data.nsfwCensorImage }) + } + if (vapidPublicKey) { store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey }) } diff --git a/src/main.js b/src/main.js index 6ce2df135..bf92e78e9 100644 --- a/src/main.js +++ b/src/main.js @@ -60,9 +60,6 @@ const registerPushNotifications = store => { if (isUserMutation && vapidPublicKey && permission) { return store.dispatch('registerPushNotifications') } - if (data['nsfwCensorImage']) { - store.dispatch('setOption', { name: 'nsfwCensorImage', value: data['nsfwCensorImage'] }) - } const user = state.users.currentUser const isVapidMutation = mutation.type === 'setInstanceOption' && mutation.payload.name === 'vapidPublicKey' From e1b523016b9172af695fd8a1f02c457d49d16067 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 13 Dec 2018 20:41:01 +0300 Subject: [PATCH 24/26] keep track of new instance options --- src/modules/instance.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/instance.js b/src/modules/instance.js index 7c27d52ad..ab88306f3 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -25,6 +25,8 @@ const defaultState = { scopeCopy: true, subjectLineBehavior: 'email', loginMethod: 'password', + nsfwCensorImage: undefined, + vapidPublicKey: undefined, // Nasty stuff pleromaBackend: true, From cc259411a79c6752f2e71917d58d625fc6028db9 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 13 Dec 2018 20:41:23 +0300 Subject: [PATCH 25/26] fix gradients and minor artifacts --- .../user_card_content/user_card_content.js | 12 +++++++++++- .../user_card_content/user_card_content.vue | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/user_card_content/user_card_content.js b/src/components/user_card_content/user_card_content.js index e7f199536..be7a23492 100644 --- a/src/components/user_card_content/user_card_content.js +++ b/src/components/user_card_content/user_card_content.js @@ -20,10 +20,20 @@ export default { if (color) { const rgb = (typeof color === 'string') ? hex2rgb(color) : color const tintColor = `rgba(${Math.floor(rgb.r)}, ${Math.floor(rgb.g)}, ${Math.floor(rgb.b)}, .5)` + + const gradient = [ + [tintColor, this.hideBio ? '60%' : ''], + this.hideBio ? [ + color, '100%' + ] : [ + tintColor, '' + ] + ].map(_ => _.join(' ')).join(', ') + return { backgroundColor: `rgb(${Math.floor(rgb.r * 0.53)}, ${Math.floor(rgb.g * 0.56)}, ${Math.floor(rgb.b * 0.59)})`, backgroundImage: [ - `linear-gradient(to bottom, ${tintColor}, ${tintColor})`, + `linear-gradient(to bottom, ${gradient})`, `url(${this.user.cover_photo})` ].join(', ') } diff --git a/src/components/user_card_content/user_card_content.vue b/src/components/user_card_content/user_card_content.vue index 185042776..08b255956 100644 --- a/src/components/user_card_content/user_card_content.vue +++ b/src/components/user_card_content/user_card_content.vue @@ -90,7 +90,7 @@ -
+
{{ $t('user_card.statuses') }}
@@ -122,6 +122,9 @@ border-radius: var(--panelRadius, $fallback--panelRadius); overflow: hidden; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; + .panel-heading { padding: 0.6em 0em; text-align: center; From e2f825266a967029ef163ecc8cfb8e5d26a5e635 Mon Sep 17 00:00:00 2001 From: ValD Date: Thu, 13 Dec 2018 23:11:36 +0530 Subject: [PATCH 26/26] added condition to check for logined user --- src/components/user_card/user_card.js | 3 +++ src/components/user_card/user_card.vue | 4 ++-- src/i18n/en.json | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index a019627a8..b8eb28e3d 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -14,6 +14,9 @@ const UserCard = { components: { UserCardContent }, + computed: { + currentUser () { return this.$store.state.users.currentUser } + }, methods: { toggleUserExpanded () { this.userExpanded = !this.userExpanded diff --git a/src/components/user_card/user_card.vue b/src/components/user_card/user_card.vue index 5a8e55319..eb0d7576c 100644 --- a/src/components/user_card/user_card.vue +++ b/src/components/user_card/user_card.vue @@ -10,13 +10,13 @@
- {{ $t('user_card.follows_you') }} + {{ currentUser.id == user.id ? $t('user_card.its_you') : $t('user_card.follows_you') }}
{{ user.name }} - {{ $t('user_card.follows_you') }} + {{ currentUser.id == user.id ? $t('user_card.its_you') : $t('user_card.follows_you') }}
diff --git a/src/i18n/en.json b/src/i18n/en.json index 9101c9939..1c43794ae 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -324,6 +324,7 @@ "followers": "Followers", "following": "Following!", "follows_you": "Follows you!", + "its_you": "It's you!", "mute": "Mute", "muted": "Muted", "per_day": "per day",