2018-02-09 07:29:29 +01:00
|
|
|
export function instanceComputations (store) {
|
2018-01-28 22:09:39 +01: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-29 00:44:33 +01:00
|
|
|
(currentInstanceData) => currentInstanceData && currentInstanceData.access_token
|
2018-01-28 22:09:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'currentTheme',
|
|
|
|
['currentInstance', 'instanceThemes'],
|
|
|
|
(currentInstance, instanceThemes) => {
|
|
|
|
return instanceThemes[currentInstance] || 'default'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'currentVerifyCredentials',
|
|
|
|
['currentInstance', 'verifyCredentials'],
|
|
|
|
(currentInstance, verifyCredentials) => verifyCredentials && verifyCredentials[currentInstance]
|
|
|
|
)
|
2018-02-08 07:49:50 +01:00
|
|
|
|
2018-02-11 22:46:57 +01:00
|
|
|
store.compute(
|
|
|
|
'currentInstanceInfo',
|
|
|
|
['currentInstance', 'instanceInfos'],
|
|
|
|
(currentInstance, instanceInfos) => instanceInfos && instanceInfos[currentInstance]
|
|
|
|
)
|
|
|
|
|
2018-02-08 07:49:50 +01:00
|
|
|
store.compute(
|
|
|
|
'pinnedPage',
|
|
|
|
['pinnedPages', 'currentInstance'],
|
|
|
|
(pinnedPages, currentInstance) => (currentInstance && pinnedPages[currentInstance]) || '/local')
|
2018-02-08 18:15:25 +01:00
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'lists',
|
|
|
|
['instanceLists', 'currentInstance'],
|
|
|
|
(instanceLists, currentInstance) => (currentInstance && instanceLists[currentInstance]) || []
|
|
|
|
)
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'pinnedListTitle',
|
|
|
|
['lists', 'pinnedPage'],
|
|
|
|
(lists, pinnedPage) => {
|
|
|
|
if (!pinnedPage.startsWith('/lists')) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let listId = pinnedPage.split('/').slice(-1)[0]
|
|
|
|
let list = lists.find(_ => _.id === listId)
|
|
|
|
return list ? list.title : ''
|
|
|
|
}
|
|
|
|
)
|
2018-02-16 17:59:44 +01:00
|
|
|
|
|
|
|
store.compute('numberOfNotifications',
|
|
|
|
['timelines', 'currentInstance', 'currentTimeline'],
|
|
|
|
(timelines, currentInstance, currentTimeline) => {
|
|
|
|
return currentTimeline !== 'notifications' &&
|
|
|
|
timelines &&
|
|
|
|
timelines[currentInstance] &&
|
|
|
|
timelines[currentInstance].notifications &&
|
|
|
|
timelines[currentInstance].notifications.itemIdsToAdd &&
|
|
|
|
timelines[currentInstance].notifications.itemIdsToAdd.length
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
store.compute('hasNotifications',
|
|
|
|
['numberOfNotifications'],
|
|
|
|
(numberOfNotifications) => {
|
|
|
|
return !!numberOfNotifications
|
|
|
|
}
|
|
|
|
)
|
2018-02-24 03:23:36 +01:00
|
|
|
|
|
|
|
store.compute('currentStatusModifications',
|
2018-02-24 23:49:28 +01:00
|
|
|
['statusModifications', 'currentInstance'],
|
|
|
|
(statusModifications, currentInstance) => {
|
|
|
|
return statusModifications[currentInstance]
|
2018-02-24 03:23:36 +01:00
|
|
|
})
|
2018-02-26 01:26:43 +01:00
|
|
|
|
2018-02-28 06:01:01 +01:00
|
|
|
store.compute('currentComposeText',
|
|
|
|
['composeText', 'currentInstance'],
|
|
|
|
(composeText, currentInstance) => (composeText[currentInstance] || '')
|
2018-02-26 01:26:43 +01:00
|
|
|
)
|
2018-02-28 08:18:07 +01:00
|
|
|
|
|
|
|
store.compute('currentCustomEmoji',
|
|
|
|
['customEmoji', 'currentInstance'],
|
|
|
|
(customEmoji, currentInstance) => (customEmoji[currentInstance] || [])
|
|
|
|
)
|
2018-02-09 07:29:29 +01:00
|
|
|
}
|