diff --git a/src/components/mention_link/mention_link.js b/src/components/mention_link/mention_link.js index ce537663f..7d0113d35 100644 --- a/src/components/mention_link/mention_link.js +++ b/src/components/mention_link/mention_link.js @@ -10,6 +10,7 @@ import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_i import UserAvatar from '../user_avatar/user_avatar.vue' import { useSyncConfigStore } from 'src/stores/sync_config.js' +import { useUserHighlightStore } from 'src/stores/user_highlight.js' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' @@ -100,23 +101,23 @@ const MentionLink = { userNameFullUi() { return this.user && this.user.screen_name_ui }, - highlight() { - return this.user && this.mergedConfig.highlight[this.user.screen_name] + highlightData() { + return this.highlight[this.user?.screen_name] }, highlightType() { - return this.highlight && '-' + this.highlight.type + return this.highlightData && '-' + this.highlightData.type }, highlightClass() { - if (this.highlight) return highlightClass(this.user) + return this.highlightData && highlightClass(this.user) }, style() { - if (this.highlight) { + if (this.highlightData) { const { backgroundColor, backgroundPosition, backgroundImage, ...rest - } = highlightStyle(this.highlight) + } = highlightStyle(this.highlightData) return rest } }, @@ -124,7 +125,7 @@ const MentionLink = { return [ { '-you': this.isYou && this.shouldBoldenYou, - '-highlighted': this.highlight, + '-highlighted': !!this.highlightData, '-has-selection': this.hasSelection, }, this.highlightType, @@ -160,6 +161,7 @@ const MentionLink = { return this.mergedConfig.mentionLinkFadeDomain }, ...mapPiniaState(useSyncConfigStore, ['mergedConfig']), + ...mapPiniaState(useUserHighlightStore, ['highlight']), ...mapState({ currentUser: (state) => state.users.currentUser, }), diff --git a/src/components/settings_modal/settings_modal.js b/src/components/settings_modal/settings_modal.js index a99067f36..ea1b56212 100644 --- a/src/components/settings_modal/settings_modal.js +++ b/src/components/settings_modal/settings_modal.js @@ -9,12 +9,10 @@ import PanelLoading from 'src/components/panel_loading/panel_loading.vue' import Popover from '../popover/popover.vue' import { useInterfaceStore } from 'src/stores/interface.js' -import { - LOCAL_ONLY_KEYS, - useLocalConfigStore, -} from 'src/stores/local_config.js' +import { useLocalConfigStore } from 'src/stores/local_config.js' import { useSyncConfigStore } from 'src/stores/sync_config.js' +import { LOCAL_ONLY_KEYS } from 'src/modules/default_config_state.js' import { newExporter, newImporter, diff --git a/src/components/settings_modal/tabs/filtering_tab.js b/src/components/settings_modal/tabs/filtering_tab.js index 3598de757..c447595ff 100644 --- a/src/components/settings_modal/tabs/filtering_tab.js +++ b/src/components/settings_modal/tabs/filtering_tab.js @@ -36,7 +36,7 @@ const FilteringTab = { label: this.$t(`user_card.mute_block_${mode}`), })), muteFiltersDraftObject: cloneDeep( - useSyncConfigStore().prefsStorage.simple.muteFilters, + useSyncConfigStore().mergedConfig.muteFilters, ), muteFiltersDraftDirty: Object.fromEntries( Object.entries( @@ -259,9 +259,8 @@ const FilteringTab = { this.$store.dispatch('queueFlushAll') }, muteFiltersObject() { - console.log('UPDATE') this.muteFiltersDraftObject = cloneDeep( - useSyncConfigStore().prefsStorage.simple.muteFilters, + useSyncConfigStore().mergedConfig.muteFilters, ) }, }, diff --git a/src/modules/default_config_state.js b/src/modules/default_config_state.js index a391e9b21..7823777a9 100644 --- a/src/modules/default_config_state.js +++ b/src/modules/default_config_state.js @@ -182,6 +182,7 @@ export const defaultConfigLocal = { imageCompression: true, useStreamingApi: false, } +export const LOCAL_ONLY_KEYS = new Set(Object.keys(defaultConfigLocal)) export const makeUndefined = (c) => Object.fromEntries(Object.keys(c).map((key) => [key, undefined])) diff --git a/src/stores/interface.js b/src/stores/interface.js index 2fe4d4f0c..5840d6b34 100644 --- a/src/stores/interface.js +++ b/src/stores/interface.js @@ -350,7 +350,6 @@ export const useInterfaceStore = defineStore('interface', { path: 'simple.styleCustomData', value: null, }) - useSyncConfigStore().pushSyncConfig() }, resetThemeV3Palette() { useSyncConfigStore().setPreference({ @@ -361,7 +360,6 @@ export const useInterfaceStore = defineStore('interface', { path: 'simple.paletteCustomData', value: null, }) - useSyncConfigStore().pushSyncConfig() }, resetThemeV2() { useSyncConfigStore().setPreference({ path: 'simple.theme', value: null }) @@ -373,7 +371,6 @@ export const useInterfaceStore = defineStore('interface', { path: 'simple.customThemeSource', value: null, }) - useSyncConfigStore().pushSyncConfig() }, async getThemeData() { const getData = async (resource, index, customData, name) => { diff --git a/src/stores/local_config.js b/src/stores/local_config.js index 3611b559e..73ea1d7d4 100644 --- a/src/stores/local_config.js +++ b/src/stores/local_config.js @@ -6,8 +6,6 @@ import { useInstanceStore } from 'src/stores/instance' import { defaultState as configDefaultState } from 'src/modules/default_config_state' -export const LOCAL_ONLY_KEYS = new Set(Object.keys(configDefaultState)) - export const defaultState = { prefsStorage: { ...configDefaultState, diff --git a/src/stores/sync_config.js b/src/stores/sync_config.js index 996f32979..8b6bc0913 100644 --- a/src/stores/sync_config.js +++ b/src/stores/sync_config.js @@ -1,7 +1,9 @@ +import sum from 'hash-sum' import { merge as _merge, clamp, cloneDeep, + debounce, findLastIndex, flatten, get, @@ -18,16 +20,14 @@ import { toRaw } from 'vue' import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/update_notification.js' import { useInstanceStore } from 'src/stores/instance.js' -import { - LOCAL_ONLY_KEYS, - useLocalConfigStore, -} from 'src/stores/local_config.js' +import { useLocalConfigStore } from 'src/stores/local_config.js' import { storage } from 'src/lib/storage.js' import { defaultState as configDefaultState, defaultConfigLocal, instanceDefaultConfig, + LOCAL_ONLY_KEYS, } from 'src/modules/default_config_state.js' import { defaultConfigSync } from 'src/modules/old_default_config_state.js' @@ -395,7 +395,7 @@ export const _resetFlags = ( return result } -export const _resetPrefs = ( +const _resetPrefs = ( totalPrefs, totalFlags, knownKeys = defaultState.flagStorage, @@ -419,7 +419,7 @@ export const _resetPrefs = ( return totalPrefs } -export const _doMigrations = async (data, setPreference) => { +const _doMigrations = async (data, setPreference) => { if (data._version < VERSION) { console.debug( 'Data has older version, seeing if there any migrations that can be applied', @@ -447,6 +447,18 @@ export const _doMigrations = async (data, setPreference) => { return data } +const _pushSyncConfig = debounce((force, root) => { + const needPush = root.dirty || force + if (!needPush) return + root.updateCache({ username: window.vuex.state.users.currentUser.fqn }) + const params = { pleroma_settings_store: { 'pleroma-fe': root.cache } } + window.vuex.state.api.backendInteractor + .updateProfileJSON({ params }) + .then((user) => { + root.initSyncConfig(user) + root.dirty = false + }) +}, 5000) export const useSyncConfigStore = defineStore('sync_config', { state() { @@ -666,12 +678,7 @@ export const useSyncConfigStore = defineStore('sync_config', { // discarding timestamps and versions const { _timestamp: _0, _version: _1, ...recentData } = recent const { _timestamp: _2, _version: _3, ...staleData } = stale - dirty = !isEqual( - // Something wrong happens if we compare both objects directly - // or with cloneDeep() - JSON.parse(JSON.stringify(recentData)), - JSON.parse(JSON.stringify(staleData)), - ) + dirty = sum(recentData) !== sum(staleData) console.debug(`Data ${dirty ? 'needs' : "doesn't need"} merging`) } @@ -707,16 +714,7 @@ export const useSyncConfigStore = defineStore('sync_config', { this.pushSyncConfig() }, pushSyncConfig({ force = false } = {}) { - const needPush = this.dirty || force - if (!needPush) return - this.updateCache({ username: window.vuex.state.users.currentUser.fqn }) - const params = { pleroma_settings_store: { 'pleroma-fe': this.cache } } - window.vuex.state.api.backendInteractor - .updateProfileJSON({ params }) - .then((user) => { - this.initSyncConfig(user) - this.dirty = false - }) + _pushSyncConfig(force, this) }, }, getters: {