2018-03-03 21:23:26 +00:00
|
|
|
function computeForInstance (store, computedKey, key, defaultValue) {
|
|
|
|
store.compute(computedKey,
|
|
|
|
[key, 'currentInstance'],
|
|
|
|
(instanceData, currentInstance) => (currentInstance && instanceData[currentInstance]) || defaultValue)
|
|
|
|
}
|
|
|
|
|
2018-02-09 06:29:29 +00:00
|
|
|
export function instanceComputations (store) {
|
2018-03-03 21:23:26 +00:00
|
|
|
computeForInstance(store, 'currentTheme', 'instanceThemes', 'default')
|
|
|
|
computeForInstance(store, 'currentVerifyCredentials', 'verifyCredentials', null)
|
|
|
|
computeForInstance(store, 'currentInstanceInfo', 'instanceInfos', null)
|
|
|
|
computeForInstance(store, 'pinnedPage', 'pinnedPages', '/local')
|
|
|
|
computeForInstance(store, 'lists', 'instanceLists', [])
|
|
|
|
computeForInstance(store, 'currentStatusModifications', 'statusModifications', null)
|
|
|
|
computeForInstance(store, 'currentCustomEmoji', 'customEmoji', [])
|
2018-03-03 22:15:50 +00:00
|
|
|
computeForInstance(store, 'currentComposeData', 'composeData', {})
|
2018-03-03 21:23:26 +00:00
|
|
|
|
2018-01-28 21:09:39 +00:00
|
|
|
store.compute(
|
|
|
|
'isUserLoggedIn',
|
|
|
|
['currentInstance', 'loggedInInstances'],
|
|
|
|
(currentInstance, loggedInInstances) => !!(currentInstance && Object.keys(loggedInInstances).includes(currentInstance))
|
|
|
|
)
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'loggedInInstancesAsList',
|
|
|
|
['currentInstance', 'loggedInInstances', 'loggedInInstancesInOrder'],
|
|
|
|
(currentInstance, loggedInInstances, loggedInInstancesInOrder) => {
|
|
|
|
return loggedInInstancesInOrder.map(instanceName => {
|
|
|
|
return Object.assign({
|
|
|
|
current: currentInstance === instanceName,
|
|
|
|
name: instanceName
|
|
|
|
}, loggedInInstances[instanceName])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'currentInstanceData',
|
|
|
|
['currentInstance', 'loggedInInstances'],
|
|
|
|
(currentInstance, loggedInInstances) => {
|
|
|
|
return Object.assign({
|
|
|
|
name: currentInstance
|
|
|
|
}, loggedInInstances[currentInstance])
|
|
|
|
})
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'accessToken',
|
|
|
|
['currentInstanceData'],
|
2018-01-28 23:44:33 +00:00
|
|
|
(currentInstanceData) => currentInstanceData && currentInstanceData.access_token
|
2018-01-28 21:09:39 +00:00
|
|
|
)
|
2018-08-26 19:14:16 +00:00
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'maxStatusChars',
|
|
|
|
['currentInstanceInfo'],
|
|
|
|
(currentInstanceInfo) => (
|
|
|
|
// unofficial api used in glitch-soc and pleroma
|
|
|
|
(currentInstanceInfo && currentInstanceInfo.max_toot_chars) || 500
|
|
|
|
)
|
|
|
|
)
|
2018-02-09 06:29:29 +00:00
|
|
|
}
|