2018-12-23 10:10:16 -08:00
|
|
|
import { get } from '../../_utils/lodash-lite'
|
2019-03-03 13:24:55 -08:00
|
|
|
import { getFirstIdFromItemSummaries, getLastIdFromItemSummaries } from '../../_utils/getIdFromItemSummaries'
|
2019-05-26 16:01:06 -07:00
|
|
|
import {
|
|
|
|
HOME_REBLOGS,
|
|
|
|
HOME_REPLIES,
|
|
|
|
NOTIFICATION_REBLOGS,
|
|
|
|
NOTIFICATION_FOLLOWS,
|
|
|
|
NOTIFICATION_FAVORITES,
|
|
|
|
NOTIFICATION_POLLS,
|
|
|
|
NOTIFICATION_MENTIONS
|
|
|
|
} from '../../_static/instanceSettings'
|
2018-02-10 13:57:04 -08:00
|
|
|
|
2018-03-04 12:55:45 -08:00
|
|
|
function computeForTimeline (store, key, defaultValue) {
|
|
|
|
store.compute(key,
|
|
|
|
['currentInstance', 'currentTimeline', `timelineData_${key}`],
|
2018-05-06 17:35:22 -07:00
|
|
|
(currentInstance, currentTimeline, root) => (
|
|
|
|
get(root, [currentInstance, currentTimeline], defaultValue)
|
|
|
|
)
|
|
|
|
)
|
2018-02-10 13:57:04 -08:00
|
|
|
}
|
|
|
|
|
2019-05-26 16:01:06 -07:00
|
|
|
// Compute just the boolean, e.g. 'showPolls', so that we can use that boolean as
|
|
|
|
// the input to the timelineFilterFunction computations. This should reduce the need to
|
|
|
|
// re-compute the timelineFilterFunction over and over.
|
|
|
|
function computeTimelineFilter (store, computationName, timelinesToSettingsKeys) {
|
|
|
|
store.compute(
|
|
|
|
computationName,
|
|
|
|
['currentInstance', 'instanceSettings', 'currentTimeline'],
|
|
|
|
(currentInstance, instanceSettings, currentTimeline) => {
|
2019-08-03 13:49:37 -07:00
|
|
|
const settingsKey = timelinesToSettingsKeys[currentTimeline]
|
2019-05-26 16:01:06 -07:00
|
|
|
return settingsKey ? get(instanceSettings, [currentInstance, settingsKey], true) : true
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ditto for notifications, which we always have to keep track of due to the notification count.
|
|
|
|
function computeNotificationFilter (store, computationName, key) {
|
|
|
|
store.compute(
|
|
|
|
computationName,
|
|
|
|
['currentInstance', 'instanceSettings'],
|
|
|
|
(currentInstance, instanceSettings) => {
|
|
|
|
return get(instanceSettings, [currentInstance, key], true)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-02-08 22:29:29 -08:00
|
|
|
export function timelineComputations (store) {
|
2019-03-03 13:24:55 -08:00
|
|
|
computeForTimeline(store, 'timelineItemSummaries', null)
|
|
|
|
computeForTimeline(store, 'timelineItemSummariesToAdd', null)
|
2018-03-04 12:55:45 -08:00
|
|
|
computeForTimeline(store, 'runningUpdate', false)
|
2019-02-23 12:32:00 -08:00
|
|
|
computeForTimeline(store, 'lastFocusedElementId', null)
|
2018-03-04 12:55:45 -08:00
|
|
|
computeForTimeline(store, 'ignoreBlurEvents', false)
|
|
|
|
computeForTimeline(store, 'showHeader', false)
|
|
|
|
computeForTimeline(store, 'shouldShowHeader', false)
|
2019-03-03 13:24:55 -08:00
|
|
|
computeForTimeline(store, 'timelineItemSummariesAreStale', false)
|
2018-03-04 12:55:45 -08:00
|
|
|
|
2019-03-18 09:09:24 -07:00
|
|
|
store.compute('currentTimelineType', ['currentTimeline'], currentTimeline => (
|
|
|
|
currentTimeline && currentTimeline.split('/')[0])
|
|
|
|
)
|
2019-03-30 21:48:49 -07:00
|
|
|
store.compute('currentTimelineValue', ['currentTimeline'], currentTimeline => {
|
|
|
|
if (!currentTimeline) {
|
|
|
|
return void 0
|
|
|
|
}
|
2019-08-03 13:49:37 -07:00
|
|
|
const split = currentTimeline.split('/')
|
|
|
|
const len = split.length
|
2019-03-30 21:48:49 -07:00
|
|
|
if (split[len - 1] === 'with_replies' || split[len - 1] === 'media') {
|
|
|
|
return split[len - 2]
|
|
|
|
}
|
|
|
|
return split[len - 1]
|
|
|
|
})
|
2019-03-03 13:24:55 -08:00
|
|
|
store.compute('firstTimelineItemId', ['timelineItemSummaries'], (timelineItemSummaries) => (
|
|
|
|
getFirstIdFromItemSummaries(timelineItemSummaries)
|
|
|
|
))
|
|
|
|
store.compute('lastTimelineItemId', ['timelineItemSummaries'], (timelineItemSummaries) => (
|
|
|
|
getLastIdFromItemSummaries(timelineItemSummaries)
|
|
|
|
))
|
2018-01-28 13:09:39 -08:00
|
|
|
|
2019-05-26 16:01:06 -07:00
|
|
|
computeTimelineFilter(store, 'timelineShowReblogs', { home: HOME_REBLOGS, notifications: NOTIFICATION_REBLOGS })
|
|
|
|
computeTimelineFilter(store, 'timelineShowReplies', { home: HOME_REPLIES })
|
|
|
|
computeTimelineFilter(store, 'timelineShowFollows', { notifications: NOTIFICATION_FOLLOWS })
|
|
|
|
computeTimelineFilter(store, 'timelineShowFavs', { notifications: NOTIFICATION_FAVORITES })
|
|
|
|
computeTimelineFilter(store, 'timelineShowMentions', { notifications: NOTIFICATION_MENTIONS })
|
|
|
|
computeTimelineFilter(store, 'timelineShowPolls', { notifications: NOTIFICATION_POLLS })
|
|
|
|
|
|
|
|
computeNotificationFilter(store, 'timelineNotificationShowReblogs', NOTIFICATION_REBLOGS)
|
|
|
|
computeNotificationFilter(store, 'timelineNotificationShowFollows', NOTIFICATION_FOLLOWS)
|
|
|
|
computeNotificationFilter(store, 'timelineNotificationShowFavs', NOTIFICATION_FAVORITES)
|
|
|
|
computeNotificationFilter(store, 'timelineNotificationShowMentions', NOTIFICATION_MENTIONS)
|
|
|
|
computeNotificationFilter(store, 'timelineNotificationShowPolls', NOTIFICATION_POLLS)
|
|
|
|
|
|
|
|
function createFilterFunction (showReblogs, showReplies, showFollows, showFavs, showMentions, showPolls) {
|
|
|
|
return item => {
|
|
|
|
switch (item.type) {
|
|
|
|
case 'poll':
|
|
|
|
return showPolls
|
|
|
|
case 'favourite':
|
|
|
|
return showFavs
|
|
|
|
case 'reblog':
|
|
|
|
return showReblogs
|
|
|
|
case 'mention':
|
|
|
|
return showMentions
|
|
|
|
case 'follow':
|
|
|
|
return showFollows
|
|
|
|
}
|
|
|
|
if (item.reblogId) {
|
|
|
|
return showReblogs
|
|
|
|
} else if (item.replyId) {
|
|
|
|
return showReplies
|
|
|
|
} else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'timelineFilterFunction',
|
|
|
|
[
|
|
|
|
'timelineShowReblogs', 'timelineShowReplies', 'timelineShowFollows',
|
|
|
|
'timelineShowFavs', 'timelineShowMentions', 'timelineShowPolls'
|
|
|
|
],
|
|
|
|
(showReblogs, showReplies, showFollows, showFavs, showMentions, showPolls) => (
|
|
|
|
createFilterFunction(showReblogs, showReplies, showFollows, showFavs, showMentions, showPolls)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'timelineNotificationFilterFunction',
|
|
|
|
[
|
|
|
|
'timelineNotificationShowReblogs', 'timelineNotificationShowFollows',
|
|
|
|
'timelineNotificationShowFavs', 'timelineNotificationShowMentions',
|
|
|
|
'timelineNotificationShowPolls'
|
|
|
|
],
|
|
|
|
(showReblogs, showFollows, showFavs, showMentions, showPolls) => (
|
|
|
|
createFilterFunction(showReblogs, true, showFollows, showFavs, showMentions, showPolls)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'filteredTimelineItemSummaries',
|
|
|
|
['timelineItemSummaries', 'timelineFilterFunction'],
|
|
|
|
(timelineItemSummaries, timelineFilterFunction) => {
|
|
|
|
return timelineItemSummaries && timelineItemSummaries.filter(timelineFilterFunction)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2019-05-29 18:48:59 -07:00
|
|
|
store.compute(
|
|
|
|
'filteredTimelineItemSummariesToAdd',
|
|
|
|
['timelineItemSummariesToAdd', 'timelineFilterFunction'],
|
|
|
|
(timelineItemSummariesToAdd, timelineFilterFunction) => {
|
|
|
|
return timelineItemSummariesToAdd && timelineItemSummariesToAdd.filter(timelineFilterFunction)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2019-05-26 16:01:06 -07:00
|
|
|
store.compute('timelineNotificationItemSummaries',
|
|
|
|
[`timelineData_timelineItemSummariesToAdd`, 'timelineFilterFunction', 'currentInstance'],
|
|
|
|
(root, timelineFilterFunction, currentInstance) => (
|
|
|
|
get(root, [currentInstance, 'notifications'])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
store.compute(
|
|
|
|
'filteredTimelineNotificationItemSummaries',
|
|
|
|
['timelineNotificationItemSummaries', 'timelineNotificationFilterFunction'],
|
|
|
|
(timelineNotificationItemSummaries, timelineNotificationFilterFunction) => (
|
|
|
|
timelineNotificationItemSummaries && timelineNotificationItemSummaries.filter(timelineNotificationFilterFunction)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2018-03-04 12:55:45 -08:00
|
|
|
store.compute('numberOfNotifications',
|
2019-06-01 15:51:53 -07:00
|
|
|
['filteredTimelineNotificationItemSummaries', 'disableNotificationBadge'],
|
|
|
|
(filteredTimelineNotificationItemSummaries, disableNotificationBadge) => (
|
|
|
|
(!disableNotificationBadge && filteredTimelineNotificationItemSummaries)
|
|
|
|
? filteredTimelineNotificationItemSummaries.length
|
|
|
|
: 0
|
2019-02-18 16:27:52 -08:00
|
|
|
)
|
2018-03-04 12:55:45 -08:00
|
|
|
)
|
2018-02-10 13:57:04 -08:00
|
|
|
|
2018-03-04 12:55:45 -08:00
|
|
|
store.compute('hasNotifications',
|
2019-06-01 15:51:53 -07:00
|
|
|
['numberOfNotifications', 'currentPage'],
|
|
|
|
(numberOfNotifications, currentPage) => (
|
|
|
|
currentPage !== 'notifications' && !!numberOfNotifications
|
2019-06-01 13:07:31 -07:00
|
|
|
)
|
2018-03-04 12:55:45 -08:00
|
|
|
)
|
2018-02-08 22:29:29 -08:00
|
|
|
}
|