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.
[Glitch] Fix “Mention” appearing for otherwise filtered posts
Port f75eb1a to glitch-soc Signed-off-by: Claire <[email protected]>
- Loading branch information
1 parent
1a9be3e
commit 9b3aaa9
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 'flavours/glitch/store'; | ||
import { toServerSideType } from 'flavours/glitch/utils/filters'; | ||
|
||
// TODO: move to `app/javascript/flavours/glitch/models` and use more globally | ||
type Filter = Immutable.Map<string, unknown>; | ||
|
||
// TODO: move to `app/javascript/flavours/glitch/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