feat: respect current server's char limit

This commit is contained in:
Daniel Roe 2022-11-25 14:01:28 +00:00
parent b8ce2fc62b
commit f7dff673ad
No known key found for this signature in database
GPG key ID: 22D5008E4F5D9B55
4 changed files with 11 additions and 8 deletions

View file

@ -10,7 +10,6 @@ import { Plugin } from 'prosemirror-state'
import type { Ref } from 'vue'
import { HashSuggestion, MentionSuggestion } from './tiptap/suggestion'
import { POST_CHARS_LIMIT } from '~/constants'
export interface UseTiptapOptions {
content: Ref<string | undefined>
@ -44,7 +43,7 @@ export function useTiptap(options: UseTiptapOptions) {
placeholder,
}),
CharacterCount.configure({
limit: POST_CHARS_LIMIT,
limit: characterLimit.value,
}),
CodeBlock,
Extension.create({

View file

@ -1,7 +1,7 @@
import type { AccountCredentials } from 'masto'
import { login as loginMasto } from 'masto'
import type { AccountCredentials, Instance } from 'masto'
import type { UserLogin } from '~/types'
import { DEFAULT_SERVER, STORAGE_KEY_CURRENT_USER, STORAGE_KEY_USERS } from '~/constants'
import { DEFAULT_POST_CHARS_LIMIT, DEFAULT_SERVER, STORAGE_KEY_CURRENT_USER, STORAGE_KEY_SERVER, STORAGE_KEY_USERS } from '~/constants'
const users = useLocalStorage<UserLogin[]>(STORAGE_KEY_USERS, [], { deep: true })
const currentUserId = useLocalStorage<string>(STORAGE_KEY_CURRENT_USER, '')
@ -21,6 +21,10 @@ export const currentServer = computed<string>(() => currentUser.value?.server ||
export const useUsers = () => users
export const currentInstance = useLocalStorage<Partial<Instance>>(STORAGE_KEY_SERVER, {}, { deep: true })
export const characterLimit = computed(() => currentInstance.value.configuration?.statuses.maxCharacters ?? DEFAULT_POST_CHARS_LIMIT)
export async function loginTo(user: UserLogin & { account?: AccountCredentials }) {
const existing = users.value.findIndex(u => u.server === user.server && u.token === user.token)
if (existing !== -1) {
@ -37,6 +41,7 @@ export async function loginTo(user: UserLogin & { account?: AccountCredentials }
})
const me = await masto.accounts.verifyCredentials()
user.account = me
currentInstance.value = await masto.instances.fetch()
users.value.push(user)
currentUserId.value = me.id