forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix “Mention” appearing for otherwise filtered posts (mastodon#32356)
- Loading branch information
1 parent
de4f785
commit f75eb1a
Showing
3 changed files
with
60 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
|
||
import type { RootState } from 'mastodon/store'; | ||
import { toServerSideType } from 'mastodon/utils/filters'; | ||
|
||
// TODO: move to `app/javascript/mastodon/models` and use more globally | ||
type Filter = Immutable.Map<string, unknown>; | ||
|
||
// TODO: move to `app/javascript/mastodon/models` and use more globally | ||
type FilterResult = Immutable.Map<string, unknown>; | ||
|
||
export const getFilters = createSelector( | ||
[ | ||
(state: RootState) => state.filters as Immutable.Map<string, Filter>, | ||
(_, { contextType }: { contextType: string }) => contextType, | ||
], | ||
(filters, contextType) => { | ||
if (!contextType) { | ||
return null; | ||
} | ||
|
||
const now = new Date(); | ||
const serverSideType = toServerSideType(contextType); | ||
|
||
return filters.filter((filter) => { | ||
const context = filter.get('context') as Immutable.List<string>; | ||
const expiration = filter.get('expires_at') as Date | null; | ||
return ( | ||
context.includes(serverSideType) && | ||
(expiration === null || expiration > now) | ||
); | ||
}); | ||
}, | ||
); | ||
|
||
export const getStatusHidden = ( | ||
state: RootState, | ||
{ id, contextType }: { id: string; contextType: string }, | ||
) => { | ||
const filters = getFilters(state, { contextType }); | ||
if (filters === null) return false; | ||
|
||
const filtered = state.statuses.getIn([id, 'filtered']) as | ||
| Immutable.List<FilterResult> | ||
| undefined; | ||
return filtered?.some( | ||
(result) => | ||
filters.getIn([result.get('filter'), 'filter_action']) === 'hide', | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters