add support for max_toot_chars > 500 (#495)

This commit is contained in:
Nolan Lawson 2018-08-26 12:14:16 -07:00 committed by GitHub
parent 17b80e5a79
commit 47315c7f6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 9 deletions

View file

@ -109,7 +109,7 @@
import ComposeMedia from './ComposeMedia.html' import ComposeMedia from './ComposeMedia.html'
import ComposeContentWarning from './ComposeContentWarning.html' import ComposeContentWarning from './ComposeContentWarning.html'
import { measureText } from '../../_utils/measureText' import { measureText } from '../../_utils/measureText'
import { CHAR_LIMIT, POST_PRIVACY_OPTIONS } from '../../_static/statuses' import { POST_PRIVACY_OPTIONS } from '../../_static/statuses'
import { store } from '../../_store/store' import { store } from '../../_store/store'
import { slide } from 'svelte-transitions' import { slide } from 'svelte-transitions'
import { postStatus, insertHandleForReply, setReplySpoiler, setReplyVisibility } from '../../_actions/compose' import { postStatus, insertHandleForReply, setReplySpoiler, setReplyVisibility } from '../../_actions/compose'
@ -183,7 +183,7 @@
length: ({ textLength, contentWarningLength, contentWarningShown }) => ( length: ({ textLength, contentWarningLength, contentWarningShown }) => (
textLength + (contentWarningShown ? contentWarningLength : 0) textLength + (contentWarningShown ? contentWarningLength : 0)
), ),
overLimit: ({ length }) => length > CHAR_LIMIT, overLimit: ({ length, $maxStatusChars }) => length > $maxStatusChars,
contentWarningShown: ({ composeData }) => composeData.contentWarningShown, contentWarningShown: ({ composeData }) => composeData.contentWarningShown,
contentWarning: ({ composeData }) => composeData.contentWarning || '', contentWarning: ({ composeData }) => composeData.contentWarning || '',
timelineInitialized: ({ $timelineInitialized }) => $timelineInitialized, timelineInitialized: ({ $timelineInitialized }) => $timelineInitialized,

View file

@ -18,7 +18,6 @@
} }
</style> </style>
<script> <script>
import { CHAR_LIMIT } from '../../_static/statuses'
import { mark, stop } from '../../_utils/marks' import { mark, stop } from '../../_utils/marks'
import { store } from '../../_store/store' import { store } from '../../_store/store'
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask' import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
@ -45,9 +44,9 @@
}), }),
store: () => store, store: () => store,
computed: { computed: {
lengthAsFraction: ({ length }) => { lengthAsFraction: ({ length, $maxStatusChars }) => {
// We don't need to update the gauge for every decimal point, so round it to the nearest 0.02 // We don't need to update the gauge for every decimal point, so round it to the nearest 0.02
let int = Math.round(Math.min(CHAR_LIMIT, length) / CHAR_LIMIT * 100) let int = Math.round(Math.min($maxStatusChars, length) / $maxStatusChars * 100)
return (int - (int % 2)) / 100 return (int - (int % 2)) / 100
} }
}, },

View file

@ -16,7 +16,6 @@
} }
</style> </style>
<script> <script>
import { CHAR_LIMIT } from '../../_static/statuses'
import { mark, stop } from '../../_utils/marks' import { mark, stop } from '../../_utils/marks'
import { store } from '../../_store/store' import { store } from '../../_store/store'
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask' import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
@ -41,7 +40,7 @@
}), }),
store: () => store, store: () => store,
computed: { computed: {
lengthToDisplay: ({ length }) => CHAR_LIMIT - length, lengthToDisplay: ({ length, $maxStatusChars }) => $maxStatusChars - length,
lengthLabel: ({ overLimit, lengthToDisplayDeferred }) => { lengthLabel: ({ overLimit, lengthToDisplayDeferred }) => {
if (overLimit) { if (overLimit) {
return `${lengthToDisplayDeferred} characters over limit` return `${lengthToDisplayDeferred} characters over limit`

View file

@ -1,5 +1,3 @@
export const CHAR_LIMIT = 500
export const POST_PRIVACY_OPTIONS = [ export const POST_PRIVACY_OPTIONS = [
{ {
label: 'Public', label: 'Public',

View file

@ -47,4 +47,13 @@ export function instanceComputations (store) {
['currentInstanceData'], ['currentInstanceData'],
(currentInstanceData) => currentInstanceData && currentInstanceData.access_token (currentInstanceData) => currentInstanceData && currentInstanceData.access_token
) )
store.compute(
'maxStatusChars',
['currentInstanceInfo'],
(currentInstanceInfo) => (
// unofficial api used in glitch-soc and pleroma
(currentInstanceInfo && currentInstanceInfo.max_toot_chars) || 500
)
)
} }