diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2018-10-24 04:00:04 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2018-10-24 04:00:04 +0900 |
| commit | daa22d68fa8a55a2e65a1de541f903edb64ff042 (patch) | |
| tree | 6307e3b1ff7a411b96a4213ed4685f9c32b6c3a6 | |
| parent | 10.30.3 (diff) | |
| download | sharkey-daa22d68fa8a55a2e65a1de541f903edb64ff042.tar.gz sharkey-daa22d68fa8a55a2e65a1de541f903edb64ff042.tar.bz2 sharkey-daa22d68fa8a55a2e65a1de541f903edb64ff042.zip | |
Make max allowed text length configurable (#2992)
* Make max allowed text length configurable
* Fix canPost
| -rw-r--r-- | .config/example.yml | 3 | ||||
| -rw-r--r-- | src/client/app/desktop/views/components/post-form.vue | 13 | ||||
| -rw-r--r-- | src/client/app/mobile/views/components/post-form.vue | 13 | ||||
| -rw-r--r-- | src/config/load.ts | 2 | ||||
| -rw-r--r-- | src/config/types.ts | 2 | ||||
| -rw-r--r-- | src/models/note.ts | 3 | ||||
| -rw-r--r-- | src/server/api/endpoints/meta.ts | 1 |
7 files changed, 30 insertions, 7 deletions
diff --git a/.config/example.yml b/.config/example.yml index ea83f9cfb8..48fc360f3f 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -164,3 +164,6 @@ drive: # external: true # engine: http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-misskey-api.cgi?{{host}}+{{user}}+{{limit}}+{{offset}} # timeout: 300000 + +# Max allowed note text length in charactors +maxNoteTextLength: 1000 diff --git a/src/client/app/desktop/views/components/post-form.vue b/src/client/app/desktop/views/components/post-form.vue index 3835f7228e..a703382f38 100644 --- a/src/client/app/desktop/views/components/post-form.vue +++ b/src/client/app/desktop/views/components/post-form.vue @@ -45,7 +45,7 @@ <span v-if="visibility === 'specified'">%fa:envelope%</span> <span v-if="visibility === 'private'">%fa:lock%</span> </button> - <p class="text-count" :class="{ over: this.trimmedLength(text) > 1000 }">{{ 1000 - this.trimmedLength(text) }}</p> + <p class="text-count" :class="{ over: this.trimmedLength(text) > this.maxNoteTextLength }">{{ this.maxNoteTextLength - this.trimmedLength(text) }}</p> <button :class="{ posting }" class="submit" :disabled="!canPost" @click="post"> {{ posting ? '%i18n:@posting%' : submitText }}<mk-ellipsis v-if="posting"/> </button> @@ -107,10 +107,17 @@ export default Vue.extend({ visibleUsers: [], autocomplete: null, draghover: false, - recentHashtags: JSON.parse(localStorage.getItem('hashtags') || '[]') + recentHashtags: JSON.parse(localStorage.getItem('hashtags') || '[]'), + maxNoteTextLength: 1000 }; }, + created() { + (this as any).os.getMeta().then(meta => { + this.maxNoteTextLength = meta.maxNoteTextLength; + }); + }, + computed: { draftId(): string { return this.renote @@ -149,7 +156,7 @@ export default Vue.extend({ canPost(): boolean { return !this.posting && (1 <= this.text.length || 1 <= this.files.length || this.poll || this.renote) && - (length(this.text.trim()) <= 1000); + (length(this.text.trim()) <= this.maxNoteTextLength); } }, diff --git a/src/client/app/mobile/views/components/post-form.vue b/src/client/app/mobile/views/components/post-form.vue index e532430d0f..0c783fded3 100644 --- a/src/client/app/mobile/views/components/post-form.vue +++ b/src/client/app/mobile/views/components/post-form.vue @@ -4,7 +4,7 @@ <header> <button class="cancel" @click="cancel">%fa:times%</button> <div> - <span class="text-count" :class="{ over: trimmedLength(text) > 1000 }">{{ 1000 - trimmedLength(text) }}</span> + <span class="text-count" :class="{ over: trimmedLength(text) > this.maxNoteTextLength }">{{ this.maxNoteTextLength - trimmedLength(text) }}</span> <span class="geo" v-if="geo">%fa:map-marker-alt%</span> <button class="submit" :disabled="!canPost" @click="post">{{ submitText }}</button> </div> @@ -102,10 +102,17 @@ export default Vue.extend({ visibleUsers: [], useCw: false, cw: null, - recentHashtags: JSON.parse(localStorage.getItem('hashtags') || '[]') + recentHashtags: JSON.parse(localStorage.getItem('hashtags') || '[]'), + maxNoteTextLength: 1000 }; }, + created() { + (this as any).os.getMeta().then(meta => { + this.maxNoteTextLength = meta.maxNoteTextLength; + }); + }, + computed: { draftId(): string { return this.renote @@ -144,7 +151,7 @@ export default Vue.extend({ canPost(): boolean { return !this.posting && (1 <= this.text.length || 1 <= this.files.length || this.poll || this.renote) && - (this.text.trim().length <= 1000); + (this.text.trim().length <= this.maxNoteTextLength); } }, diff --git a/src/config/load.ts b/src/config/load.ts index 3a1bac3201..9cdd742c6d 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -49,6 +49,8 @@ export default function load() { if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256; if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8; + if (config.maxNoteTextLength == null) config.maxNoteTextLength = 1000; + if (config.name == null) config.name = 'Misskey'; return Object.assign(config, mixin); diff --git a/src/config/types.ts b/src/config/types.ts index 139ca9e82a..fc3a3afe5f 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -103,6 +103,8 @@ export type Source = { engine: string; timeout: number; }; + + maxNoteTextLength?: number; }; /** diff --git a/src/models/note.ts b/src/models/note.ts index aeec075636..6edf6ec317 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -14,6 +14,7 @@ import NoteReaction from './note-reaction'; import Favorite, { deleteFavorite } from './favorite'; import Notification, { deleteNotification } from './notification'; import Following from './following'; +import config from '../config'; const Note = db.get<INote>('notes'); Note.createIndex('uri', { sparse: true, unique: true }); @@ -29,7 +30,7 @@ Note.createIndex({ export default Note; export function isValidText(text: string): boolean { - return length(text.trim()) <= 1000 && text.trim() != ''; + return length(text.trim()) <= config.maxNoteTextLength && text.trim() != ''; } export function isValidCw(text: string): boolean { diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts index 4ae377ef71..0cd5842312 100644 --- a/src/server/api/endpoints/meta.ts +++ b/src/server/api/endpoints/meta.ts @@ -49,6 +49,7 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => swPublickey: config.sw ? config.sw.public_key : null, hidedTags: (me && me.isAdmin) ? meta.hidedTags : undefined, bannerUrl: meta.bannerUrl, + maxNoteTextLength: config.maxNoteTextLength, features: { registration: !meta.disableRegistration, |