diff --git a/src/components/chat/chat.js b/src/components/chat/chat.js index caeb2aea7..8295e6bcb 100644 --- a/src/components/chat/chat.js +++ b/src/components/chat/chat.js @@ -17,6 +17,7 @@ import { } from './chat_layout_utils.js' import { useInterfaceStore } from 'src/stores/interface.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import { library } from '@fortawesome/fontawesome-svg-core' import { faChevronDown, faChevronLeft } from '@fortawesome/free-solid-svg-icons' @@ -109,11 +110,11 @@ const Chat = { 'currentChat', 'currentChatMessageService', 'findOpenedChatByRecipientId', - 'mergedConfig', ]), ...mapPiniaState(useInterfaceStore, { mobileLayout: (store) => store.layoutType === 'mobile', }), + ...mapPiniaState(useSyncConfigStore, ['mergedConfig']), ...mapState({ backendInteractor: (state) => state.api.backendInteractor, mastoUserSocketStatus: (state) => state.api.mastoUserSocketStatus, diff --git a/src/components/chat_message/chat_message.js b/src/components/chat_message/chat_message.js index d84286e80..2ab3a60d1 100644 --- a/src/components/chat_message/chat_message.js +++ b/src/components/chat_message/chat_message.js @@ -10,7 +10,8 @@ import Popover from '../popover/popover.vue' import StatusContent from '../status_content/status_content.vue' import UserAvatar from '../user_avatar/user_avatar.vue' -import { useInterfaceStore } from 'src/stores/interface' +import { useInterfaceStore } from 'src/stores/interface.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import { library } from '@fortawesome/fontawesome-svg-core' import { faEllipsisH, faTimes } from '@fortawesome/free-solid-svg-icons' @@ -84,7 +85,8 @@ const ChatMessage = { return { left: 50 } } }, - ...mapGetters(['mergedConfig', 'findUser']), + ...mapGetters(['findUser']), + ...mapState(useSyncConfigStore, ['mergedConfig']), }, data() { return { diff --git a/src/components/confirm_modal/mute_confirm.js b/src/components/confirm_modal/mute_confirm.js index c486ad7e4..888aa017b 100644 --- a/src/components/confirm_modal/mute_confirm.js +++ b/src/components/confirm_modal/mute_confirm.js @@ -1,8 +1,10 @@ -import { mapGetters } from 'vuex' +import { mapState } from 'pinia' import Select from 'src/components/select/select.vue' import ConfirmModal from './confirm_modal.vue' +import { useSyncConfigStore } from 'src/stores/sync_config.js' + export default { props: ['type', 'user', 'status'], emits: ['hide', 'show', 'muted'], @@ -43,7 +45,7 @@ export default { } } }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), }, methods: { optionallyPrompt() { diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js index 85db541e3..5d5b933e1 100644 --- a/src/components/conversation/conversation.js +++ b/src/components/conversation/conversation.js @@ -394,7 +394,7 @@ const conversation = { maybeHighlight() { return this.isExpanded ? this.highlight : null }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), ...mapState({ mastoUserSocketStatus: (state) => state.api.mastoUserSocketStatus, }), diff --git a/src/components/link-preview/link-preview.js b/src/components/link-preview/link-preview.js index ac91f916d..a465cc213 100644 --- a/src/components/link-preview/link-preview.js +++ b/src/components/link-preview/link-preview.js @@ -1,4 +1,6 @@ -import { mapGetters } from 'vuex' +import { mapState } from 'pinia' + +import { useSyncConfigStore } from 'src/stores/sync_config.js' const LinkPreview = { name: 'LinkPreview', @@ -24,7 +26,7 @@ const LinkPreview = { hideNsfwConfig() { return this.mergedConfig.hideNsfw }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), }, created() { if (this.useImage) { diff --git a/src/components/mention_link/mention_link.js b/src/components/mention_link/mention_link.js index 5fa12392e..cd392f131 100644 --- a/src/components/mention_link/mention_link.js +++ b/src/components/mention_link/mention_link.js @@ -1,6 +1,6 @@ import { mapState as mapPiniaState } from 'pinia' import { defineAsyncComponent } from 'vue' -import { mapGetters, mapState } from 'vuex' +import { mapState } from 'vuex' import { highlightClass, diff --git a/src/components/mentions_line/mentions_line.js b/src/components/mentions_line/mentions_line.js index e6aa392a0..bd3882866 100644 --- a/src/components/mentions_line/mentions_line.js +++ b/src/components/mentions_line/mentions_line.js @@ -1,7 +1,9 @@ -import { mapGetters } from 'vuex' +import { mapState } from 'pinia' import MentionLink from 'src/components/mention_link/mention_link.vue' +import { useSyncConfigStore } from 'src/stores/sync_config.js' + export const MENTIONS_LIMIT = 5 const MentionsLine = { @@ -26,7 +28,7 @@ const MentionsLine = { manyMentions() { return this.extraMentions.length > 0 }, - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), }, methods: { toggleShowMore() { diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index dfcb60e05..6cf482c5f 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -206,13 +206,13 @@ const PostStatusForm = { } if (statusType === 'edit') { - const statusContentType = this.statusContentType || contentType + const statusContentType = this.statusContentType || this.contentType statusParams = { type: statusType, refId, spoilerText: this.subject || '', status: this.statusText || '', - nsfw: this.statusIsSensitive || !!sensitiveByDefault, + nsfw: this.statusIsSensitive || !!this.sensitiveByDefault, files: this.statusFiles || [], poll: this.statusPoll || {}, hasPoll: false, diff --git a/src/components/quick_filter_settings/quick_filter_settings.js b/src/components/quick_filter_settings/quick_filter_settings.js index dbb237e74..7e50fd023 100644 --- a/src/components/quick_filter_settings/quick_filter_settings.js +++ b/src/components/quick_filter_settings/quick_filter_settings.js @@ -1,9 +1,9 @@ import { mapState } from 'pinia' -import { mapGetters } from 'vuex' import Popover from '../popover/popover.vue' import { useInterfaceStore } from 'src/stores/interface' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import { library } from '@fortawesome/fontawesome-svg-core' import { faFilter, faFont, faWrench } from '@fortawesome/free-solid-svg-icons' @@ -31,7 +31,7 @@ const QuickFilterSettings = { }, }, computed: { - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), ...mapState(useInterfaceStore, { mobileLayout: (state) => state.layoutType === 'mobile', }), diff --git a/src/components/quick_view_settings/quick_view_settings.js b/src/components/quick_view_settings/quick_view_settings.js index c305893a0..e671a4964 100644 --- a/src/components/quick_view_settings/quick_view_settings.js +++ b/src/components/quick_view_settings/quick_view_settings.js @@ -5,6 +5,7 @@ import Popover from 'src/components/popover/popover.vue' import QuickFilterSettings from 'src/components/quick_filter_settings/quick_filter_settings.vue' import { useInterfaceStore } from 'src/stores/interface' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import { library } from '@fortawesome/fontawesome-svg-core' import { @@ -36,7 +37,7 @@ const QuickViewSettings = { }, }, computed: { - ...mapGetters(['mergedConfig']), + ...mapState(useSyncConfigStore, ['mergedConfig']), ...mapState(useInterfaceStore, { mobileLayout: (state) => state.layoutType === 'mobile', }), diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js index 729c7eedf..9173603cb 100644 --- a/src/components/settings_modal/helpers/setting.js +++ b/src/components/settings_modal/helpers/setting.js @@ -273,7 +273,10 @@ export default { } const revert = () => { - useSyncConfigStore().setPreference({ path: writePath, value: oldValue }) + useSyncConfigStore().setPreference({ + path: writePath, + value: oldValue, + }) useInterfaceStore().clearTemporaryChanges() } diff --git a/src/components/settings_modal/tabs/appearance_tab.js b/src/components/settings_modal/tabs/appearance_tab.js index 25ad6b665..7c900cfa6 100644 --- a/src/components/settings_modal/tabs/appearance_tab.js +++ b/src/components/settings_modal/tabs/appearance_tab.js @@ -336,16 +336,10 @@ const AppearanceTab = { } }, isThemeActive(key) { - return ( - key === - (useSyncConfigStore().mergedConfig.theme) - ) + return key === useSyncConfigStore().mergedConfig.theme }, isStyleActive(key) { - return ( - key === - (useSyncConfigStore().mergedConfig.style) - ) + return key === useSyncConfigStore().mergedConfig.style }, isPaletteActive(key) { return ( diff --git a/src/components/status_body/status_body.js b/src/components/status_body/status_body.js index 217e7e29c..a8402a7ed 100644 --- a/src/components/status_body/status_body.js +++ b/src/components/status_body/status_body.js @@ -1,5 +1,4 @@ import { mapState } from 'pinia' -import { mapGetters } from 'vuex' import RichContent from 'src/components/rich_content/rich_content.jsx' diff --git a/src/components/status_content/status_content.js b/src/components/status_content/status_content.js index a8493eef4..e37bb3461 100644 --- a/src/components/status_content/status_content.js +++ b/src/components/status_content/status_content.js @@ -106,9 +106,6 @@ const StatusContent = { } return true }, - localCollapseSubjectDefault() { - return this.mergedConfig.collapseMessageWithSubject - }, attachmentSize() { if (this.compact) { return 'small' @@ -121,13 +118,14 @@ const StatusContent = { } return 'normal' }, - ...mapGetters(['mergedConfig']), ...mapState({ currentUser: (state) => state.users.currentUser, }), ...mapPiniaState(useSyncConfigStore, { - maxThumbnails: (store) => store.prefsStorage.simple.maxThumbnails, - hideAttachments: (store) => store.prefsStorage.simple.hideAttachments, + localCollapseSubjectDefault: (store) => + store.mergedConfig.collapseMessageWithSubject, + maxThumbnails: (store) => store.mergedConfig.maxThumbnails, + hideAttachments: (store) => store.mergedConfig.hideAttachments, hideAttachmentsInConv: (store) => store.prefsStorage.simple.hideAttachmentsInConv, }), diff --git a/src/lib/style.js b/src/lib/style.js index c2b0bdbd5..96603925a 100644 --- a/src/lib/style.js +++ b/src/lib/style.js @@ -19,7 +19,7 @@ export const piniaStylePlugin = ({ store, options }) => { if (store.$id === 'sync_config') { store.$onAction(({ name, args, after }) => { if (name === 'setPreference') { - const { path, value } = args[0] + const { path } = args[0] if (APPEARANCE_SETTINGS_KEYS.has(path)) { after(() => applyStyleConfig(store.mergedConfig)) } diff --git a/src/modules/instance.js b/src/modules/instance.js deleted file mode 100644 index 880a5f675..000000000 --- a/src/modules/instance.js +++ /dev/null @@ -1,314 +0,0 @@ -// See build/emojis_plugin for more details - -import apiService from '../services/api/api.service.js' -import { instanceDefaultProperties } from './config.js' -import { - instanceDefaultConfig, - staticOrApiConfigDefault, -} from './default_config_state.js' - -import { useInterfaceStore } from 'src/stores/interface.js' - -import { ensureFinalFallback } from 'src/i18n/languages.js' - -import { annotationsLoader } from 'virtual:pleroma-fe/emoji-annotations' - -const SORTED_EMOJI_GROUP_IDS = [ - 'smileys-and-emotion', - 'people-and-body', - 'animals-and-nature', - 'food-and-drink', - 'travel-and-places', - 'activities', - 'objects', - 'symbols', - 'flags', -] - -const REGIONAL_INDICATORS = (() => { - const start = 0x1f1e6 - const end = 0x1f1ff - const A = 'A'.codePointAt(0) - const res = new Array(end - start + 1) - for (let i = start; i <= end; ++i) { - const letter = String.fromCodePoint(A + i - start) - res[i - start] = { - replacement: String.fromCodePoint(i), - imageUrl: false, - displayText: 'regional_indicator_' + letter, - displayTextI18n: { - key: 'emoji.regional_indicator', - args: { letter }, - }, - } - } - return res -})() - -const REMOTE_INTERACTION_URL = '/main/ostatus' - -const defaultState = { - // Stuff from apiConfig - name: 'Pleroma FE', - registrationOpen: true, - server: 'http://localhost:4040/', - textlimit: 5000, - themesIndex: undefined, - stylesIndex: undefined, - palettesIndex: undefined, - themeData: undefined, // used for theme editor v2 - vapidPublicKey: undefined, - - // Stuff from static/config.json - loginMethod: 'password', - disableUpdateNotification: false, - - fontsOverride: {}, - - // Instance-wide configurations that should not be changed by individual users - ...staticOrApiConfigDefault, - // Instance admins can override default settings for the whole instance - ...instanceDefaultConfig, - - // Nasty stuff - customEmoji: [], - customEmojiFetched: false, - emoji: {}, - emojiFetched: false, - unicodeEmojiAnnotations: {}, - pleromaExtensionsAvailable: true, - postFormats: [], - restrictedNicknames: [], - safeDM: true, - knownDomains: [], - birthdayRequired: false, - birthdayMinAge: 0, - - // Feature-set, apparently, not everything here is reported... - shoutAvailable: false, - pleromaChatMessagesAvailable: false, - pleromaCustomEmojiReactionsAvailable: false, - pleromaBookmarkFoldersAvailable: false, - pleromaPublicFavouritesAvailable: true, - statusNotificationTypeAvailable: true, - gopherAvailable: false, - mediaProxyAvailable: false, - suggestionsEnabled: false, - suggestionsWeb: '', - quotingAvailable: false, - groupActorAvailable: false, - blockExpiration: false, - localBubbleInstances: [], // Akkoma - - // Html stuff - instanceSpecificPanelContent: '', - tos: '', - - // Version Information - backendVersion: '', - backendRepository: '', - frontendVersion: '', - - pollsAvailable: false, - pollLimits: { - max_options: 4, - max_option_chars: 255, - min_expiration: 60, - max_expiration: 60 * 60 * 24, - }, -} - -const loadAnnotations = (lang) => { - return annotationsLoader[lang]().then((k) => k.default) -} - -const injectAnnotations = (emoji, annotations) => { - const availableLangs = Object.keys(annotations) - - return { - ...emoji, - annotations: availableLangs.reduce((acc, cur) => { - acc[cur] = annotations[cur][emoji.replacement] - return acc - }, {}), - } -} - -const injectRegionalIndicators = (groups) => { - groups.symbols.push(...REGIONAL_INDICATORS) - return groups -} - -const instance = { - state: defaultState, - mutations: { - setInstanceOption(state, { name, value }) { - if (typeof value !== 'undefined') { - state[name] = value - } - }, - setKnownDomains(state, domains) { - state.knownDomains = domains - }, - setUnicodeEmojiAnnotations(state, { lang, annotations }) { - state.unicodeEmojiAnnotations[lang] = annotations - }, - }, - getters: { - instanceDefaultConfig(state) { - return instanceDefaultProperties - .map((key) => [key, state[key]]) - .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}) - }, - instanceDomain(state) { - return new URL(state.server).hostname - }, - remoteInteractionLink(state) { - const server = state.server.endsWith('/') - ? state.server.slice(0, -1) - : state.server - const link = server + REMOTE_INTERACTION_URL - - return ({ statusId, nickname }) => { - if (statusId) { - return `${link}?status_id=${statusId}` - } else { - return `${link}?nickname=${nickname}` - } - } - }, - }, - actions: { - setInstanceOption({ commit, dispatch }, { name, value }) { - commit('setInstanceOption', { name, value }) - switch (name) { - case 'name': - useInterfaceStore().setPageTitle() - break - case 'shoutAvailable': - if (value) { - dispatch('initializeSocket') - } - break - } - }, - async getStaticEmoji({ commit }) { - try { - const values = (await import('/src/assets/emoji.json')).default - - const emoji = Object.keys(values).reduce((res, groupId) => { - res[groupId] = values[groupId].map((e) => ({ - displayText: e.slug, - imageUrl: false, - replacement: e.emoji, - })) - return res - }, {}) - commit('setInstanceOption', { - name: 'emoji', - value: injectRegionalIndicators(emoji), - }) - } catch (e) { - console.warn("Can't load static emoji\n", e) - } - }, - - loadUnicodeEmojiData({ commit, state }, language) { - const langList = ensureFinalFallback(language) - - return Promise.all( - langList.map(async (lang) => { - if (!state.unicodeEmojiAnnotations[lang]) { - try { - const annotations = await loadAnnotations(lang) - commit('setUnicodeEmojiAnnotations', { lang, annotations }) - } catch (e) { - console.warn( - `Error loading unicode emoji annotations for ${lang}: `, - e, - ) - // ignore - } - } - }), - ) - }, - - async getCustomEmoji({ commit, state }) { - try { - let res = await window.fetch('/api/v1/pleroma/emoji') - if (!res.ok) { - res = await window.fetch('/api/pleroma/emoji.json') - } - if (res.ok) { - const result = await res.json() - const values = Array.isArray(result) - ? Object.assign({}, ...result) - : result - const caseInsensitiveStrCmp = (a, b) => { - const la = a.toLowerCase() - const lb = b.toLowerCase() - return la > lb ? 1 : la < lb ? -1 : 0 - } - const noPackLast = (a, b) => { - const aNull = a === '' - const bNull = b === '' - if (aNull === bNull) { - return 0 - } else if (aNull && !bNull) { - return 1 - } else { - return -1 - } - } - const byPackThenByName = (a, b) => { - const packOf = (emoji) => - (emoji.tags.filter((k) => k.startsWith('pack:'))[0] || '').slice( - 5, - ) - const packOfA = packOf(a) - const packOfB = packOf(b) - return ( - noPackLast(packOfA, packOfB) || - caseInsensitiveStrCmp(packOfA, packOfB) || - caseInsensitiveStrCmp(a.displayText, b.displayText) - ) - } - - const emoji = Object.entries(values) - .map(([key, value]) => { - const imageUrl = value.image_url - return { - displayText: key, - imageUrl: imageUrl ? state.server + imageUrl : value, - tags: imageUrl - ? value.tags.sort((a, b) => (a > b ? 1 : 0)) - : ['utf'], - replacement: `:${key}: `, - } - // Technically could use tags but those are kinda useless right now, - // should have been "pack" field, that would be more useful - }) - .sort(byPackThenByName) - commit('setInstanceOption', { name: 'customEmoji', value: emoji }) - } else { - throw res - } - } catch (e) { - console.warn("Can't load custom emojis\n", e) - } - }, - async getKnownDomains({ commit, rootState }) { - try { - const result = await apiService.fetchKnownDomains({ - credentials: rootState.users.currentUser.credentials, - }) - commit('setKnownDomains', result) - } catch (e) { - console.warn("Can't load known domains\n", e) - } - }, - }, -} - -export default instance