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.
Merge pull request #2883 from ClearlyClaire/glitch-soc/backports-4.3
Port changes from upstream to stable-4.3
- Loading branch information
Showing
8 changed files
with
119 additions
and
62 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
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
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
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