1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-02 08:48:39 +09:00

Change filter logic to keep filtered toots, but not mark them as unread

Keeping them in the TL fixes the front-end not being able to properly keep
track of pagination. Furthermore, filtered toots are not counted as unread
content, whether they are dropped or not.
This commit is contained in:
Thibaut Girka 2019-10-24 17:47:19 +02:00 committed by ThibG
parent 069e0520c9
commit 984fce613e
2 changed files with 20 additions and 15 deletions

View File

@ -30,12 +30,14 @@ export function updateTimeline(timeline, status, accept) {
return; return;
} }
const dropRegex = getFiltersRegex(getState(), { contextType: timeline })[0]; const filters = getFiltersRegex(getState(), { contextType: timeline });
const dropRegex = filters[0];
const regex = filters[1];
const text = searchTextFromRawStatus(status);
let filtered = false;
if (dropRegex && status.account.id !== me) { if (status.account.id !== me) {
if (dropRegex.test(searchTextFromRawStatus(status))) { filtered = (dropRegex && dropRegex.test(text)) || (regex && regex.test(text));
return;
}
} }
dispatch(importFetchedStatus(status)); dispatch(importFetchedStatus(status));
@ -45,6 +47,7 @@ export function updateTimeline(timeline, status, accept) {
timeline, timeline,
status, status,
usePendingItems: preferPendingItems, usePendingItems: preferPendingItems,
filtered
}); });
}; };
}; };
@ -107,12 +110,8 @@ export function expandTimeline(timelineId, path, params = {}, done = noOp) {
api(getState).get(path, { params }).then(response => { api(getState).get(path, { params }).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next'); const next = getLinks(response).refs.find(link => link.rel === 'next');
const dropRegex = getFiltersRegex(getState(), { contextType: timelineId })[0]; dispatch(importFetchedStatuses(response.data));
dispatch(expandTimelineSuccess(timelineId, response.data, next ? next.uri : null, response.status === 206, isLoadingRecent, isLoadingMore, isLoadingRecent && preferPendingItems));
const statuses = dropRegex ? response.data.filter(status => status.account.id === me || !dropRegex.test(searchTextFromRawStatus(status))) : response.data;
dispatch(importFetchedStatuses(statuses));
dispatch(expandTimelineSuccess(timelineId, statuses, next ? next.uri : null, response.status === 206, isLoadingRecent, isLoadingMore, isLoadingRecent && preferPendingItems));
done(); done();
}).catch(error => { }).catch(error => {
dispatch(expandTimelineFail(timelineId, error, isLoadingMore)); dispatch(expandTimelineFail(timelineId, error, isLoadingMore));

View File

@ -60,7 +60,7 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is
})); }));
}; };
const updateTimeline = (state, timeline, status, usePendingItems) => { const updateTimeline = (state, timeline, status, usePendingItems, filtered) => {
const top = state.getIn([timeline, 'top']); const top = state.getIn([timeline, 'top']);
if (usePendingItems || !state.getIn([timeline, 'pendingItems']).isEmpty()) { if (usePendingItems || !state.getIn([timeline, 'pendingItems']).isEmpty()) {
@ -68,7 +68,13 @@ const updateTimeline = (state, timeline, status, usePendingItems) => {
return state; return state;
} }
return state.update(timeline, initialTimeline, map => map.update('pendingItems', list => list.unshift(status.get('id'))).update('unread', unread => unread + 1)); state = state.update(timeline, initialTimeline, map => map.update('pendingItems', list => list.unshift(status.get('id'))));
if (!filtered) {
state = state.update('unread', unread => unread + 1);
}
return state;
} }
const ids = state.getIn([timeline, 'items'], ImmutableList()); const ids = state.getIn([timeline, 'items'], ImmutableList());
@ -82,7 +88,7 @@ const updateTimeline = (state, timeline, status, usePendingItems) => {
let newIds = ids; let newIds = ids;
return state.update(timeline, initialTimeline, map => map.withMutations(mMap => { return state.update(timeline, initialTimeline, map => map.withMutations(mMap => {
if (!top) mMap.set('unread', unread + 1); if (!top && !filtered) mMap.set('unread', unread + 1);
if (top && ids.size > 40) newIds = newIds.take(20); if (top && ids.size > 40) newIds = newIds.take(20);
mMap.set('items', newIds.unshift(status.get('id'))); mMap.set('items', newIds.unshift(status.get('id')));
})); }));
@ -147,7 +153,7 @@ export default function timelines(state = initialState, action) {
case TIMELINE_EXPAND_SUCCESS: case TIMELINE_EXPAND_SUCCESS:
return expandNormalizedTimeline(state, action.timeline, fromJS(action.statuses), action.next, action.partial, action.isLoadingRecent, action.usePendingItems); return expandNormalizedTimeline(state, action.timeline, fromJS(action.statuses), action.next, action.partial, action.isLoadingRecent, action.usePendingItems);
case TIMELINE_UPDATE: case TIMELINE_UPDATE:
return updateTimeline(state, action.timeline, fromJS(action.status), action.usePendingItems); return updateTimeline(state, action.timeline, fromJS(action.status), action.usePendingItems, action.filtered);
case TIMELINE_DELETE: case TIMELINE_DELETE:
return deleteStatus(state, action.id, action.accountId, action.references, action.reblogOf); return deleteStatus(state, action.id, action.accountId, action.references, action.reblogOf);
case TIMELINE_CLEAR: case TIMELINE_CLEAR: