MASSIVE refactor, replacing instance module with store, separating emoji stuff into its own store, making sure everything refers to new stores (WIP)
This commit is contained in:
parent
dc7308766c
commit
5bdf341560
95 changed files with 801 additions and 833 deletions
|
|
@ -342,7 +342,7 @@ const api = {
|
|||
// Set up websocket connection
|
||||
const token = state.wsToken
|
||||
if (
|
||||
rootState.instance.shoutAvailable &&
|
||||
useInstanceStore().featureSet.shoutAvailable &&
|
||||
typeof token !== 'undefined' &&
|
||||
state.socket === null
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -42,27 +42,6 @@ export const instanceDefaultProperties = Object.keys(instanceDefaultConfig)
|
|||
|
||||
const config = {
|
||||
state: { ...defaultState },
|
||||
getters: {
|
||||
defaultConfig(state, getters, rootState) {
|
||||
const { instance } = rootState
|
||||
return {
|
||||
...defaultState,
|
||||
...Object.fromEntries(
|
||||
instanceDefaultProperties.map((key) => [key, instance[key]]),
|
||||
),
|
||||
}
|
||||
},
|
||||
mergedConfig(state, getters, rootState, rootGetters) {
|
||||
const { defaultConfig } = rootGetters
|
||||
return {
|
||||
...defaultConfig,
|
||||
// Do not override with undefined
|
||||
...Object.fromEntries(
|
||||
Object.entries(state).filter(([, v]) => v !== undefined),
|
||||
),
|
||||
}
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
setOptionTemporarily(state, { name, value }) {
|
||||
set(state, name, value)
|
||||
|
|
@ -84,47 +63,6 @@ const config = {
|
|||
},
|
||||
},
|
||||
actions: {
|
||||
loadSettings({ dispatch }, data) {
|
||||
const knownKeys = new Set(Object.keys(defaultState))
|
||||
const presentKeys = new Set(Object.keys(data))
|
||||
const intersection = new Set()
|
||||
for (const elem of presentKeys) {
|
||||
if (knownKeys.has(elem)) {
|
||||
intersection.add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
intersection.forEach((name) =>
|
||||
dispatch('setOption', { name, value: data[name] }),
|
||||
)
|
||||
},
|
||||
setHighlight({ commit }, { user, color, type }) {
|
||||
commit('setHighlight', { user, color, type })
|
||||
},
|
||||
setOptionTemporarily({ commit, dispatch, state }, { name, value }) {
|
||||
if (useInterfaceStore().temporaryChangesTimeoutId !== null) {
|
||||
console.warn("Can't track more than one temporary change")
|
||||
return
|
||||
}
|
||||
const oldValue = state[name]
|
||||
|
||||
commit('setOptionTemporarily', { name, value })
|
||||
|
||||
const confirm = () => {
|
||||
dispatch('setOption', { name, value })
|
||||
useInterfaceStore().clearTemporaryChanges()
|
||||
}
|
||||
|
||||
const revert = () => {
|
||||
commit('setOptionTemporarily', { name, value: oldValue })
|
||||
useInterfaceStore().clearTemporaryChanges()
|
||||
}
|
||||
|
||||
useInterfaceStore().setTemporaryChanges({
|
||||
confirm,
|
||||
revert,
|
||||
})
|
||||
},
|
||||
setThemeV2({ commit, dispatch }, { customTheme, customThemeSource }) {
|
||||
commit('setOption', { name: 'theme', value: 'custom' })
|
||||
commit('setOption', { name: 'customTheme', value: customTheme })
|
||||
|
|
|
|||
|
|
@ -3,14 +3,12 @@ import api from './api.js'
|
|||
import chats from './chats.js'
|
||||
import config from './config.js'
|
||||
import drafts from './drafts.js'
|
||||
import instance from './instance.js'
|
||||
import notifications from './notifications.js'
|
||||
import profileConfig from './profileConfig.js'
|
||||
import statuses from './statuses.js'
|
||||
import users from './users.js'
|
||||
|
||||
export default {
|
||||
instance,
|
||||
statuses,
|
||||
notifications,
|
||||
users,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// See build/emojis_plugin for more details
|
||||
|
||||
import { ensureFinalFallback } from 'src/i18n/languages.js'
|
||||
import { useInterfaceStore } from 'src/stores/interface.js'
|
||||
import { ensureFinalFallback } from '../i18n/languages.js'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
import { instanceDefaultProperties } from './config.js'
|
||||
import {
|
||||
|
|
@ -158,59 +158,6 @@ const instance = {
|
|||
.map((key) => [key, state[key]])
|
||||
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {})
|
||||
},
|
||||
groupedCustomEmojis(state) {
|
||||
const packsOf = (emoji) => {
|
||||
const packs = emoji.tags
|
||||
.filter((k) => k.startsWith('pack:'))
|
||||
.map((k) => {
|
||||
const packName = k.slice(5) // remove 'pack:' prefix
|
||||
return {
|
||||
id: `custom-${packName}`,
|
||||
text: packName,
|
||||
}
|
||||
})
|
||||
|
||||
if (!packs.length) {
|
||||
return [
|
||||
{
|
||||
id: 'unpacked',
|
||||
},
|
||||
]
|
||||
} else {
|
||||
return packs
|
||||
}
|
||||
}
|
||||
|
||||
return state.customEmoji.reduce((res, emoji) => {
|
||||
packsOf(emoji).forEach(({ id: packId, text: packName }) => {
|
||||
if (!res[packId]) {
|
||||
res[packId] = {
|
||||
id: packId,
|
||||
text: packName,
|
||||
image: emoji.imageUrl,
|
||||
emojis: [],
|
||||
}
|
||||
}
|
||||
res[packId].emojis.push(emoji)
|
||||
})
|
||||
return res
|
||||
}, {})
|
||||
},
|
||||
standardEmojiList(state) {
|
||||
return SORTED_EMOJI_GROUP_IDS.map((groupId) =>
|
||||
(state.emoji[groupId] || []).map((k) =>
|
||||
injectAnnotations(k, state.unicodeEmojiAnnotations),
|
||||
),
|
||||
).reduce((a, b) => a.concat(b), [])
|
||||
},
|
||||
standardEmojiGroupList(state) {
|
||||
return SORTED_EMOJI_GROUP_IDS.map((groupId) => ({
|
||||
id: groupId,
|
||||
emojis: (state.emoji[groupId] || []).map((k) =>
|
||||
injectAnnotations(k, state.unicodeEmojiAnnotations),
|
||||
),
|
||||
}))
|
||||
},
|
||||
instanceDomain(state) {
|
||||
return new URL(state.server).hostname
|
||||
},
|
||||
|
|
@ -349,17 +296,6 @@ const instance = {
|
|||
console.warn("Can't load custom emojis\n", e)
|
||||
}
|
||||
},
|
||||
fetchEmoji({ dispatch, state }) {
|
||||
if (!state.customEmojiFetched) {
|
||||
state.customEmojiFetched = true
|
||||
dispatch('getCustomEmoji')
|
||||
}
|
||||
if (!state.emojiFetched) {
|
||||
state.emojiFetched = true
|
||||
dispatch('getStaticEmoji')
|
||||
}
|
||||
},
|
||||
|
||||
async getKnownDomains({ commit, rootState }) {
|
||||
try {
|
||||
const result = await apiService.fetchKnownDomains({
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { useReportsStore } from 'src/stores/reports.js'
|
||||
import { useServerSideStorageStore } from 'src/stores/serverSideStorage'
|
||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
import {
|
||||
closeAllDesktopNotifications,
|
||||
|
|
@ -118,9 +118,7 @@ export const notifications = {
|
|||
|
||||
maybeShowNotification(
|
||||
store,
|
||||
Object.values(
|
||||
useServerSideStorageStore().prefsStorage.simple.muteFilters,
|
||||
),
|
||||
Object.values(useSyncConfigStore().prefsStorage.simple.muteFilters),
|
||||
notification,
|
||||
)
|
||||
} else if (notification.seen) {
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ import {
|
|||
} from 'lodash'
|
||||
|
||||
import { declarations } from 'src/modules/config_declaration'
|
||||
import { useInstanceStore } from 'src/stores/instance.js'
|
||||
import { useInterfaceStore } from 'src/stores/interface.js'
|
||||
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||
import { useServerSideStorageStore } from 'src/stores/serverSideStorage'
|
||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||
import { useEmojiStore } from 'src/stores/emoji.js'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||
import oauthApi from '../services/new_api/oauth.js'
|
||||
|
|
@ -678,14 +680,14 @@ const users = {
|
|||
useInterfaceStore().setLastTimeline('public-timeline')
|
||||
useInterfaceStore().setLayoutWidth(windowWidth())
|
||||
useInterfaceStore().setLayoutHeight(windowHeight())
|
||||
store.commit('clearServerSideStorage')
|
||||
store.commit('clearSyncConfig')
|
||||
})
|
||||
},
|
||||
loginUser(store, accessToken) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const commit = store.commit
|
||||
const dispatch = store.dispatch
|
||||
const rootState = store.rootState
|
||||
|
||||
commit('beginLogin')
|
||||
store.rootState.api.backendInteractor
|
||||
.verifyCredentials(accessToken)
|
||||
|
|
@ -699,10 +701,10 @@ const users = {
|
|||
user.domainMutes = []
|
||||
commit('setCurrentUser', user)
|
||||
|
||||
useServerSideStorageStore().setServerSideStorage(user)
|
||||
useSyncConfigStore().setSyncConfig(user)
|
||||
commit('addNewUsers', [user])
|
||||
|
||||
dispatch('fetchEmoji')
|
||||
useEmojiStore().fetchEmoji()
|
||||
|
||||
getNotificationPermission().then((permission) =>
|
||||
useInterfaceStore().setNotificationPermission(permission),
|
||||
|
|
@ -720,17 +722,16 @@ const users = {
|
|||
/*
|
||||
// Reset wordfilter
|
||||
Object.keys(
|
||||
useServerSideStorageStore().prefsStorage.simple.muteFilters
|
||||
useSyncConfigStore().prefsStorage.simple.muteFilters
|
||||
).forEach(key => {
|
||||
useServerSideStorageStore().unsetPreference({ path: 'simple.muteFilters.' + key, value: null })
|
||||
useSyncConfigStore().unsetPreference({ path: 'simple.muteFilters.' + key, value: null })
|
||||
})
|
||||
|
||||
// Reset flag to 0 to re-run migrations
|
||||
useServerSideStorageStore().setFlag({ flag: 'configMigration', value: 0 })
|
||||
useSyncConfigStore().setFlag({ flag: 'configMigration', value: 0 })
|
||||
/**/
|
||||
|
||||
const { configMigration } =
|
||||
useServerSideStorageStore().flagStorage
|
||||
const { configMigration } = useSyncConfigStore().flagStorage
|
||||
declarations
|
||||
.filter((x) => {
|
||||
return (
|
||||
|
|
@ -741,12 +742,12 @@ const users = {
|
|||
})
|
||||
.toSorted((a, b) => a.configMigration - b.configMigration)
|
||||
.forEach((value) => {
|
||||
value.migration(useServerSideStorageStore(), store.rootState)
|
||||
useServerSideStorageStore().setFlag({
|
||||
value.migration(useSyncConfigStore(), store.rootState)
|
||||
useSyncConfigStore().setFlag({
|
||||
flag: 'configMigration',
|
||||
value: value.migrationNum,
|
||||
})
|
||||
useServerSideStorageStore().pushServerSideStorage()
|
||||
useSyncConfigStore().pushSyncConfig()
|
||||
})
|
||||
|
||||
if (user.token) {
|
||||
|
|
@ -763,7 +764,9 @@ const users = {
|
|||
// Start fetching notifications
|
||||
dispatch('startFetchingNotifications')
|
||||
|
||||
if (rootState.instance.pleromaChatMessagesAvailable) {
|
||||
if (
|
||||
useInstanceStore().featureSet.pleromaChatMessagesAvailable
|
||||
) {
|
||||
// Start fetching chats
|
||||
dispatch('startFetchingChats')
|
||||
}
|
||||
|
|
@ -776,7 +779,7 @@ const users = {
|
|||
dispatch('startFetchingFollowRequests')
|
||||
}
|
||||
|
||||
if (store.getters.mergedConfig.useStreamingApi) {
|
||||
if (useSyncConfigStore().mergedConfig.useStreamingApi) {
|
||||
dispatch('fetchTimeline', { timeline: 'friends', since: null })
|
||||
dispatch('fetchNotifications', { since: null })
|
||||
dispatch('enableMastoSockets', true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue