Signed-off-by: marcin mikołajczak <git@mkljczk.pl>environments/review-filters-v2-hhz42m/deployments/2751
parent
aad7df89a5
commit
4200fa2df4
@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Filter normalizer:
|
||||||
|
* Converts API filters into our internal format.
|
||||||
|
* @see {@link https://docs.joinmastodon.org/entities/FilterKeyword/}
|
||||||
|
*/
|
||||||
|
import { Map as ImmutableMap, Record as ImmutableRecord, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
// https://docs.joinmastodon.org/entities/FilterKeyword/
|
||||||
|
export const FilterKeywordRecord = ImmutableRecord({
|
||||||
|
id: '',
|
||||||
|
keyword: '',
|
||||||
|
whole_word: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const normalizeFilterKeyword = (filterKeyword: Record<string, any>) =>
|
||||||
|
FilterKeywordRecord(
|
||||||
|
ImmutableMap(fromJS(filterKeyword)),
|
||||||
|
);
|
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Filter normalizer:
|
||||||
|
* Converts API filters into our internal format.
|
||||||
|
* @see {@link https://docs.joinmastodon.org/entities/FilterResult/}
|
||||||
|
*/
|
||||||
|
import { List as ImmutableList, Map as ImmutableMap, Record as ImmutableRecord, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
import { normalizeFilter } from './filter';
|
||||||
|
|
||||||
|
import type { Filter } from 'soapbox/types/entities';
|
||||||
|
|
||||||
|
// https://docs.joinmastodon.org/entities/FilterResult/
|
||||||
|
export const FilterResultRecord = ImmutableRecord({
|
||||||
|
filter: null as Filter | null,
|
||||||
|
keyword_matches: ImmutableList<string>(),
|
||||||
|
status_matches: ImmutableList<string>(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const normalizeFilterResult = (filterResult: Record<string, any>) =>
|
||||||
|
FilterResultRecord(
|
||||||
|
ImmutableMap(fromJS(filterResult)).update('filter', (filter: any) => normalizeFilter(filter) as any),
|
||||||
|
);
|
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Filter normalizer:
|
||||||
|
* Converts API filters into our internal format.
|
||||||
|
* @see {@link https://docs.joinmastodon.org/entities/FilterStatus/}
|
||||||
|
*/
|
||||||
|
import { Map as ImmutableMap, Record as ImmutableRecord, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
// https://docs.joinmastodon.org/entities/FilterStatus/
|
||||||
|
export const FilterStatusRecord = ImmutableRecord({
|
||||||
|
id: '',
|
||||||
|
status_id: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
export const normalizeFilterStatus = (filterStatus: Record<string, any>) =>
|
||||||
|
FilterStatusRecord(
|
||||||
|
ImmutableMap(fromJS(filterStatus)),
|
||||||
|
);
|
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Filter normalizer:
|
||||||
|
* Converts API filters into our internal format.
|
||||||
|
* @see {@link https://docs.joinmastodon.org/entities/V1_Filter/}
|
||||||
|
*/
|
||||||
|
import { List as ImmutableList, Map as ImmutableMap, Record as ImmutableRecord, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
import type { ContextType } from './filter';
|
||||||
|
|
||||||
|
// https://docs.joinmastodon.org/entities/V1_Filter/
|
||||||
|
export const FilterV1Record = ImmutableRecord({
|
||||||
|
id: '',
|
||||||
|
phrase: '',
|
||||||
|
context: ImmutableList<ContextType>(),
|
||||||
|
whole_word: false,
|
||||||
|
expires_at: '',
|
||||||
|
irreversible: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const normalizeFilterV1 = (filter: Record<string, any>) => {
|
||||||
|
return FilterV1Record(
|
||||||
|
ImmutableMap(fromJS(filter)),
|
||||||
|
);
|
||||||
|
};
|
Loading…
Reference in new issue