refactor: refactor timeline filtering logic (#1667)
This commit is contained in:
parent
4f9fb5f253
commit
47ade12167
|
@ -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',
|
||||||
[
|
[
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue