2024-01-08 10:57:40 +00:00
|
|
|
import { createSelector } from '@reduxjs/toolkit';
|
2022-06-30 08:39:29 +00:00
|
|
|
import { List as ImmutableList, Map as ImmutableMap } from 'immutable';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
2022-08-25 02:27:47 +00:00
|
|
|
import { toServerSideType } from 'mastodon/utils/filters';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
2018-08-19 16:44:18 +00:00
|
|
|
import { me } from '../initial_state';
|
2016-10-07 22:01:22 +00:00
|
|
|
|
2023-11-03 15:00:03 +00:00
|
|
|
export { makeGetAccount } from "./accounts";
|
2016-10-07 22:01:22 +00:00
|
|
|
|
2024-09-12 08:16:07 +00:00
|
|
|
const getFilters = createSelector([state => state.get('filters'), (_, { contextType }) => contextType], (filters, contextType) => {
|
|
|
|
if (!contextType) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-06-29 22:12:38 +00:00
|
|
|
|
Revamp post filtering system (#18058)
* Add model for custom filter keywords
* Use CustomFilterKeyword internally
Does not change the API
* Fix /filters/edit and /filters/new
* Add migration tests
* Remove whole_word column from custom_filters (covered by custom_filter_keywords)
* Redesign /filters
Instead of a list, present a card that displays more information and handles
multiple keywords per filter.
* Redesign /filters/new and /filters/edit to add and remove keywords
This adds a new gem dependency: cocoon, as well as a npm dependency:
cocoon-js-vanilla. Those are used to easily populate and remove form fields
from the user interface when manipulating multiple keyword filters at once.
* Add /api/v2/filters to edit filter with multiple keywords
Entities:
- `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context`
`keywords`
- `FilterKeyword`: `id`, `keyword`, `whole_word`
API endpoits:
- `GET /api/v2/filters` to list filters (including keywords)
- `POST /api/v2/filters` to create a new filter
`keywords_attributes` can also be passed to create keywords in one request
- `GET /api/v2/filters/:id` to read a particular filter
- `PUT /api/v2/filters/:id` to update a new filter
`keywords_attributes` can also be passed to edit, delete or add keywords in
one request
- `DELETE /api/v2/filters/:id` to delete a particular filter
- `GET /api/v2/filters/:id/keywords` to list keywords for a filter
- `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a
filter
- `GET /api/v2/filter_keywords/:id` to read a particular keyword
- `PUT /api/v2/filter_keywords/:id` to edit a particular keyword
- `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword
* Change from `irreversible` boolean to `action` enum
* Remove irrelevent `irreversible_must_be_within_context` check
* Fix /filters/new and /filters/edit with update for filter_action
* Fix Rubocop/Codeclimate complaining about task names
* Refactor FeedManager#phrase_filtered?
This moves regexp building and filter caching to the `CustomFilter` class.
This does not change the functional behavior yet, but this changes how the
cache is built, doing per-custom_filter regexps so that filters can be matched
independently, while still offering caching.
* Perform server-side filtering and output result in REST API
* Fix numerous filters_changed events being sent when editing multiple keywords at once
* Add some tests
* Use the new API in the WebUI
- use client-side logic for filters we have fetched rules for.
This is so that filter changes can be retroactively applied without
reloading the UI.
- use server-side logic for filters we haven't fetched rules for yet
(e.g. network error, or initial timeline loading)
* Minor optimizations and refactoring
* Perform server-side filtering on the streaming server
* Change the wording of filter action labels
* Fix issues pointed out by linter
* Change design of “Show anyway” link in accordence to review comments
* Drop “irreversible” filtering behavior
* Move /api/v2/filter_keywords to /api/v1/filters/keywords
* Rename `filter_results` attribute to `filtered`
* Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer
* Fix systemChannelId value in streaming server
* Simplify code by removing client-side filtering code
The simplifcation comes at a cost though: filters aren't retroactively
applied anymore.
2022-06-28 07:42:13 +00:00
|
|
|
const now = new Date();
|
2024-09-12 08:16:07 +00:00
|
|
|
const serverSideType = toServerSideType(contextType);
|
2019-06-29 22:12:38 +00:00
|
|
|
|
2024-09-12 08:16:07 +00:00
|
|
|
return filters.filter(filter => filter.get('context').includes(serverSideType) && (filter.get('expires_at') === null || filter.get('expires_at') > now));
|
|
|
|
});
|
2019-06-29 22:12:38 +00:00
|
|
|
|
2016-10-24 15:11:02 +00:00
|
|
|
export const makeGetStatus = () => {
|
2017-02-22 15:30:09 +00:00
|
|
|
return createSelector(
|
|
|
|
[
|
2018-06-29 13:34:36 +00:00
|
|
|
(state, { id }) => state.getIn(['statuses', id]),
|
|
|
|
(state, { id }) => state.getIn(['statuses', state.getIn(['statuses', id, 'reblog'])]),
|
|
|
|
(state, { id }) => state.getIn(['accounts', state.getIn(['statuses', id, 'account'])]),
|
|
|
|
(state, { id }) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'reblog']), 'account'])]),
|
Revamp post filtering system (#18058)
* Add model for custom filter keywords
* Use CustomFilterKeyword internally
Does not change the API
* Fix /filters/edit and /filters/new
* Add migration tests
* Remove whole_word column from custom_filters (covered by custom_filter_keywords)
* Redesign /filters
Instead of a list, present a card that displays more information and handles
multiple keywords per filter.
* Redesign /filters/new and /filters/edit to add and remove keywords
This adds a new gem dependency: cocoon, as well as a npm dependency:
cocoon-js-vanilla. Those are used to easily populate and remove form fields
from the user interface when manipulating multiple keyword filters at once.
* Add /api/v2/filters to edit filter with multiple keywords
Entities:
- `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context`
`keywords`
- `FilterKeyword`: `id`, `keyword`, `whole_word`
API endpoits:
- `GET /api/v2/filters` to list filters (including keywords)
- `POST /api/v2/filters` to create a new filter
`keywords_attributes` can also be passed to create keywords in one request
- `GET /api/v2/filters/:id` to read a particular filter
- `PUT /api/v2/filters/:id` to update a new filter
`keywords_attributes` can also be passed to edit, delete or add keywords in
one request
- `DELETE /api/v2/filters/:id` to delete a particular filter
- `GET /api/v2/filters/:id/keywords` to list keywords for a filter
- `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a
filter
- `GET /api/v2/filter_keywords/:id` to read a particular keyword
- `PUT /api/v2/filter_keywords/:id` to edit a particular keyword
- `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword
* Change from `irreversible` boolean to `action` enum
* Remove irrelevent `irreversible_must_be_within_context` check
* Fix /filters/new and /filters/edit with update for filter_action
* Fix Rubocop/Codeclimate complaining about task names
* Refactor FeedManager#phrase_filtered?
This moves regexp building and filter caching to the `CustomFilter` class.
This does not change the functional behavior yet, but this changes how the
cache is built, doing per-custom_filter regexps so that filters can be matched
independently, while still offering caching.
* Perform server-side filtering and output result in REST API
* Fix numerous filters_changed events being sent when editing multiple keywords at once
* Add some tests
* Use the new API in the WebUI
- use client-side logic for filters we have fetched rules for.
This is so that filter changes can be retroactively applied without
reloading the UI.
- use server-side logic for filters we haven't fetched rules for yet
(e.g. network error, or initial timeline loading)
* Minor optimizations and refactoring
* Perform server-side filtering on the streaming server
* Change the wording of filter action labels
* Fix issues pointed out by linter
* Change design of “Show anyway” link in accordence to review comments
* Drop “irreversible” filtering behavior
* Move /api/v2/filter_keywords to /api/v1/filters/keywords
* Rename `filter_results` attribute to `filtered`
* Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer
* Fix systemChannelId value in streaming server
* Simplify code by removing client-side filtering code
The simplifcation comes at a cost though: filters aren't retroactively
applied anymore.
2022-06-28 07:42:13 +00:00
|
|
|
getFilters,
|
2017-02-22 15:30:09 +00:00
|
|
|
],
|
|
|
|
|
Revamp post filtering system (#18058)
* Add model for custom filter keywords
* Use CustomFilterKeyword internally
Does not change the API
* Fix /filters/edit and /filters/new
* Add migration tests
* Remove whole_word column from custom_filters (covered by custom_filter_keywords)
* Redesign /filters
Instead of a list, present a card that displays more information and handles
multiple keywords per filter.
* Redesign /filters/new and /filters/edit to add and remove keywords
This adds a new gem dependency: cocoon, as well as a npm dependency:
cocoon-js-vanilla. Those are used to easily populate and remove form fields
from the user interface when manipulating multiple keyword filters at once.
* Add /api/v2/filters to edit filter with multiple keywords
Entities:
- `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context`
`keywords`
- `FilterKeyword`: `id`, `keyword`, `whole_word`
API endpoits:
- `GET /api/v2/filters` to list filters (including keywords)
- `POST /api/v2/filters` to create a new filter
`keywords_attributes` can also be passed to create keywords in one request
- `GET /api/v2/filters/:id` to read a particular filter
- `PUT /api/v2/filters/:id` to update a new filter
`keywords_attributes` can also be passed to edit, delete or add keywords in
one request
- `DELETE /api/v2/filters/:id` to delete a particular filter
- `GET /api/v2/filters/:id/keywords` to list keywords for a filter
- `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a
filter
- `GET /api/v2/filter_keywords/:id` to read a particular keyword
- `PUT /api/v2/filter_keywords/:id` to edit a particular keyword
- `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword
* Change from `irreversible` boolean to `action` enum
* Remove irrelevent `irreversible_must_be_within_context` check
* Fix /filters/new and /filters/edit with update for filter_action
* Fix Rubocop/Codeclimate complaining about task names
* Refactor FeedManager#phrase_filtered?
This moves regexp building and filter caching to the `CustomFilter` class.
This does not change the functional behavior yet, but this changes how the
cache is built, doing per-custom_filter regexps so that filters can be matched
independently, while still offering caching.
* Perform server-side filtering and output result in REST API
* Fix numerous filters_changed events being sent when editing multiple keywords at once
* Add some tests
* Use the new API in the WebUI
- use client-side logic for filters we have fetched rules for.
This is so that filter changes can be retroactively applied without
reloading the UI.
- use server-side logic for filters we haven't fetched rules for yet
(e.g. network error, or initial timeline loading)
* Minor optimizations and refactoring
* Perform server-side filtering on the streaming server
* Change the wording of filter action labels
* Fix issues pointed out by linter
* Change design of “Show anyway” link in accordence to review comments
* Drop “irreversible” filtering behavior
* Move /api/v2/filter_keywords to /api/v1/filters/keywords
* Rename `filter_results` attribute to `filtered`
* Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer
* Fix systemChannelId value in streaming server
* Simplify code by removing client-side filtering code
The simplifcation comes at a cost though: filters aren't retroactively
applied anymore.
2022-06-28 07:42:13 +00:00
|
|
|
(statusBase, statusReblog, accountBase, accountReblog, filters) => {
|
2022-10-20 12:35:29 +00:00
|
|
|
if (!statusBase || statusBase.get('isLoading')) {
|
2017-02-22 15:30:09 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statusReblog) {
|
|
|
|
statusReblog = statusReblog.set('account', accountReblog);
|
|
|
|
} else {
|
|
|
|
statusReblog = null;
|
|
|
|
}
|
|
|
|
|
Revamp post filtering system (#18058)
* Add model for custom filter keywords
* Use CustomFilterKeyword internally
Does not change the API
* Fix /filters/edit and /filters/new
* Add migration tests
* Remove whole_word column from custom_filters (covered by custom_filter_keywords)
* Redesign /filters
Instead of a list, present a card that displays more information and handles
multiple keywords per filter.
* Redesign /filters/new and /filters/edit to add and remove keywords
This adds a new gem dependency: cocoon, as well as a npm dependency:
cocoon-js-vanilla. Those are used to easily populate and remove form fields
from the user interface when manipulating multiple keyword filters at once.
* Add /api/v2/filters to edit filter with multiple keywords
Entities:
- `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context`
`keywords`
- `FilterKeyword`: `id`, `keyword`, `whole_word`
API endpoits:
- `GET /api/v2/filters` to list filters (including keywords)
- `POST /api/v2/filters` to create a new filter
`keywords_attributes` can also be passed to create keywords in one request
- `GET /api/v2/filters/:id` to read a particular filter
- `PUT /api/v2/filters/:id` to update a new filter
`keywords_attributes` can also be passed to edit, delete or add keywords in
one request
- `DELETE /api/v2/filters/:id` to delete a particular filter
- `GET /api/v2/filters/:id/keywords` to list keywords for a filter
- `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a
filter
- `GET /api/v2/filter_keywords/:id` to read a particular keyword
- `PUT /api/v2/filter_keywords/:id` to edit a particular keyword
- `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword
* Change from `irreversible` boolean to `action` enum
* Remove irrelevent `irreversible_must_be_within_context` check
* Fix /filters/new and /filters/edit with update for filter_action
* Fix Rubocop/Codeclimate complaining about task names
* Refactor FeedManager#phrase_filtered?
This moves regexp building and filter caching to the `CustomFilter` class.
This does not change the functional behavior yet, but this changes how the
cache is built, doing per-custom_filter regexps so that filters can be matched
independently, while still offering caching.
* Perform server-side filtering and output result in REST API
* Fix numerous filters_changed events being sent when editing multiple keywords at once
* Add some tests
* Use the new API in the WebUI
- use client-side logic for filters we have fetched rules for.
This is so that filter changes can be retroactively applied without
reloading the UI.
- use server-side logic for filters we haven't fetched rules for yet
(e.g. network error, or initial timeline loading)
* Minor optimizations and refactoring
* Perform server-side filtering on the streaming server
* Change the wording of filter action labels
* Fix issues pointed out by linter
* Change design of “Show anyway” link in accordence to review comments
* Drop “irreversible” filtering behavior
* Move /api/v2/filter_keywords to /api/v1/filters/keywords
* Rename `filter_results` attribute to `filtered`
* Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer
* Fix systemChannelId value in streaming server
* Simplify code by removing client-side filtering code
The simplifcation comes at a cost though: filters aren't retroactively
applied anymore.
2022-06-28 07:42:13 +00:00
|
|
|
let filtered = false;
|
|
|
|
if ((accountReblog || accountBase).get('id') !== me && filters) {
|
|
|
|
let filterResults = statusReblog?.get('filtered') || statusBase.get('filtered') || ImmutableList();
|
|
|
|
if (filterResults.some((result) => filters.getIn([result.get('filter'), 'filter_action']) === 'hide')) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-08-25 02:27:47 +00:00
|
|
|
filterResults = filterResults.filter(result => filters.has(result.get('filter')));
|
Revamp post filtering system (#18058)
* Add model for custom filter keywords
* Use CustomFilterKeyword internally
Does not change the API
* Fix /filters/edit and /filters/new
* Add migration tests
* Remove whole_word column from custom_filters (covered by custom_filter_keywords)
* Redesign /filters
Instead of a list, present a card that displays more information and handles
multiple keywords per filter.
* Redesign /filters/new and /filters/edit to add and remove keywords
This adds a new gem dependency: cocoon, as well as a npm dependency:
cocoon-js-vanilla. Those are used to easily populate and remove form fields
from the user interface when manipulating multiple keyword filters at once.
* Add /api/v2/filters to edit filter with multiple keywords
Entities:
- `Filter`: `id`, `title`, `filter_action` (either `hide` or `warn`), `context`
`keywords`
- `FilterKeyword`: `id`, `keyword`, `whole_word`
API endpoits:
- `GET /api/v2/filters` to list filters (including keywords)
- `POST /api/v2/filters` to create a new filter
`keywords_attributes` can also be passed to create keywords in one request
- `GET /api/v2/filters/:id` to read a particular filter
- `PUT /api/v2/filters/:id` to update a new filter
`keywords_attributes` can also be passed to edit, delete or add keywords in
one request
- `DELETE /api/v2/filters/:id` to delete a particular filter
- `GET /api/v2/filters/:id/keywords` to list keywords for a filter
- `POST /api/v2/filters/:filter_id/keywords/:id` to add a new keyword to a
filter
- `GET /api/v2/filter_keywords/:id` to read a particular keyword
- `PUT /api/v2/filter_keywords/:id` to edit a particular keyword
- `DELETE /api/v2/filter_keywords/:id` to delete a particular keyword
* Change from `irreversible` boolean to `action` enum
* Remove irrelevent `irreversible_must_be_within_context` check
* Fix /filters/new and /filters/edit with update for filter_action
* Fix Rubocop/Codeclimate complaining about task names
* Refactor FeedManager#phrase_filtered?
This moves regexp building and filter caching to the `CustomFilter` class.
This does not change the functional behavior yet, but this changes how the
cache is built, doing per-custom_filter regexps so that filters can be matched
independently, while still offering caching.
* Perform server-side filtering and output result in REST API
* Fix numerous filters_changed events being sent when editing multiple keywords at once
* Add some tests
* Use the new API in the WebUI
- use client-side logic for filters we have fetched rules for.
This is so that filter changes can be retroactively applied without
reloading the UI.
- use server-side logic for filters we haven't fetched rules for yet
(e.g. network error, or initial timeline loading)
* Minor optimizations and refactoring
* Perform server-side filtering on the streaming server
* Change the wording of filter action labels
* Fix issues pointed out by linter
* Change design of “Show anyway” link in accordence to review comments
* Drop “irreversible” filtering behavior
* Move /api/v2/filter_keywords to /api/v1/filters/keywords
* Rename `filter_results` attribute to `filtered`
* Rename REST::LegacyFilterSerializer to REST::V1::FilterSerializer
* Fix systemChannelId value in streaming server
* Simplify code by removing client-side filtering code
The simplifcation comes at a cost though: filters aren't retroactively
applied anymore.
2022-06-28 07:42:13 +00:00
|
|
|
if (!filterResults.isEmpty()) {
|
|
|
|
filtered = filterResults.map(result => filters.getIn([result.get('filter'), 'title']));
|
|
|
|
}
|
2019-06-18 16:23:08 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 15:30:09 +00:00
|
|
|
return statusBase.withMutations(map => {
|
|
|
|
map.set('reblog', statusReblog);
|
|
|
|
map.set('account', accountBase);
|
2022-06-30 07:51:55 +00:00
|
|
|
map.set('matched_filters', filtered);
|
2017-02-22 15:30:09 +00:00
|
|
|
});
|
2020-03-08 15:02:36 +00:00
|
|
|
},
|
2017-02-22 15:30:09 +00:00
|
|
|
);
|
2016-10-07 22:01:22 +00:00
|
|
|
};
|
|
|
|
|
2020-12-07 18:36:36 +00:00
|
|
|
export const makeGetPictureInPicture = () => {
|
|
|
|
return createSelector([
|
2024-03-27 15:19:33 +00:00
|
|
|
(state, { id }) => state.picture_in_picture.statusId === id,
|
2020-12-07 18:36:36 +00:00
|
|
|
(state) => state.getIn(['meta', 'layout']) !== 'mobile',
|
|
|
|
], (inUse, available) => ImmutableMap({
|
|
|
|
inUse: inUse && available,
|
|
|
|
available,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2023-07-08 18:01:08 +00:00
|
|
|
const ALERT_DEFAULTS = {
|
|
|
|
dismissAfter: 5000,
|
|
|
|
style: false,
|
|
|
|
};
|
2016-10-07 22:01:22 +00:00
|
|
|
|
2024-09-12 08:16:07 +00:00
|
|
|
const formatIfNeeded = (intl, message, values) => {
|
|
|
|
if (typeof message === 'object') {
|
|
|
|
return intl.formatMessage(message, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getAlerts = createSelector([state => state.get('alerts'), (_, { intl }) => intl], (alerts, intl) =>
|
2023-07-08 18:01:08 +00:00
|
|
|
alerts.map(item => ({
|
|
|
|
...ALERT_DEFAULTS,
|
|
|
|
...item,
|
2024-09-12 08:16:07 +00:00
|
|
|
action: formatIfNeeded(intl, item.action, item.values),
|
|
|
|
title: formatIfNeeded(intl, item.title, item.values),
|
|
|
|
message: formatIfNeeded(intl, item.message, item.values),
|
2023-07-08 18:01:08 +00:00
|
|
|
})).toArray());
|
2016-11-20 18:39:18 +00:00
|
|
|
|
2022-06-27 07:30:15 +00:00
|
|
|
export const makeGetNotification = () => createSelector([
|
|
|
|
(_, base) => base,
|
|
|
|
(state, _, accountId) => state.getIn(['accounts', accountId]),
|
|
|
|
], (base, account) => base.set('account', account));
|
|
|
|
|
|
|
|
export const makeGetReport = () => createSelector([
|
|
|
|
(_, base) => base,
|
|
|
|
(state, _, targetAccountId) => state.getIn(['accounts', targetAccountId]),
|
|
|
|
], (base, targetAccount) => base.set('target_account', targetAccount));
|
2017-05-19 23:28:25 +00:00
|
|
|
|
|
|
|
export const getAccountGallery = createSelector([
|
2017-07-10 23:00:14 +00:00
|
|
|
(state, id) => state.getIn(['timelines', `account:${id}:media`, 'items'], ImmutableList()),
|
2017-05-19 23:28:25 +00:00
|
|
|
state => state.get('statuses'),
|
2020-07-10 20:09:28 +00:00
|
|
|
(state, id) => state.getIn(['accounts', id]),
|
|
|
|
], (statusIds, statuses, account) => {
|
2017-07-10 23:00:14 +00:00
|
|
|
let medias = ImmutableList();
|
2017-05-19 23:28:25 +00:00
|
|
|
|
|
|
|
statusIds.forEach(statusId => {
|
2023-03-23 04:17:29 +00:00
|
|
|
const status = statuses.get(statusId).set('account', account);
|
|
|
|
medias = medias.concat(status.get('media_attachments').map(media => media.set('status', status)));
|
2017-05-19 23:28:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return medias;
|
|
|
|
});
|
2022-05-10 07:44:35 +00:00
|
|
|
|
|
|
|
export const getAccountHidden = createSelector([
|
|
|
|
(state, id) => state.getIn(['accounts', id, 'hidden']),
|
|
|
|
(state, id) => state.getIn(['relationships', id, 'following']) || state.getIn(['relationships', id, 'requested']),
|
|
|
|
(state, id) => id === me,
|
|
|
|
], (hidden, followingOrRequested, isSelf) => {
|
|
|
|
return hidden && !(isSelf || followingOrRequested);
|
|
|
|
});
|
2023-06-22 15:54:43 +00:00
|
|
|
|
|
|
|
export const getStatusList = createSelector([
|
|
|
|
(state, type) => state.getIn(['status_lists', type, 'items']),
|
|
|
|
], (items) => items.toList());
|