diff --git a/src/routes/_store/computations/timelineComputations.js b/src/routes/_store/computations/timelineComputations.js index e2e13832..1705c814 100644 --- a/src/routes/_store/computations/timelineComputations.js +++ b/src/routes/_store/computations/timelineComputations.js @@ -9,6 +9,7 @@ import { NOTIFICATION_POLLS, NOTIFICATION_MENTIONS } from '../../_static/instanceSettings' +import { createFilterFunction } from '../../_utils/createFilterFunction' import { mark, stop } from '../../_utils/marks' function computeForTimeline (store, key, defaultValue) { @@ -90,30 +91,6 @@ export function timelineComputations (store) { 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', [ diff --git a/src/routes/_utils/createFilterFunction.js b/src/routes/_utils/createFilterFunction.js new file mode 100644 index 00000000..96b0dc21 --- /dev/null +++ b/src/routes/_utils/createFilterFunction.js @@ -0,0 +1,32 @@ +// create a function for filtering timeline item summaries + +function noFilter () { + return true +} + +export function createFilterFunction (showReblogs, showReplies, showFollows, showFavs, showMentions, showPolls) { + if (showReblogs && showReplies && showFollows && showFavs && showMentions && showPolls) { + return noFilter // fast path for the default setting + } + 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 + } + } +}