refactor: refactor timeline filtering logic (#1667)

This commit is contained in:
Nolan Lawson 2019-12-08 18:03:39 -08:00 committed by GitHub
parent 4f9fb5f253
commit 47ade12167
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 24 deletions

View file

@ -9,6 +9,7 @@ import {
NOTIFICATION_POLLS, NOTIFICATION_POLLS,
NOTIFICATION_MENTIONS NOTIFICATION_MENTIONS
} from '../../_static/instanceSettings' } from '../../_static/instanceSettings'
import { createFilterFunction } from '../../_utils/createFilterFunction'
import { mark, stop } from '../../_utils/marks' import { mark, stop } from '../../_utils/marks'
function computeForTimeline (store, key, defaultValue) { function computeForTimeline (store, key, defaultValue) {
@ -90,30 +91,6 @@ export function timelineComputations (store) {
computeNotificationFilter(store, 'timelineNotificationShowMentions', NOTIFICATION_MENTIONS) computeNotificationFilter(store, 'timelineNotificationShowMentions', NOTIFICATION_MENTIONS)
computeNotificationFilter(store, 'timelineNotificationShowPolls', NOTIFICATION_POLLS) 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( store.compute(
'timelineFilterFunction', 'timelineFilterFunction',
[ [

View file

@ -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
}
}
}