Skip to content

Commit 5df7e36

Browse files
Merge pull request glitch-soc#2856 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes up to 7098851
2 parents 6551129 + ba7b1f0 commit 5df7e36

File tree

109 files changed

+458
-273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+458
-273
lines changed

Gemfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ GEM
101101
awrence (1.2.1)
102102
aws-eventstream (1.3.0)
103103
aws-partitions (1.977.0)
104-
aws-sdk-core (3.207.0)
104+
aws-sdk-core (3.208.0)
105105
aws-eventstream (~> 1, >= 1.3.0)
106106
aws-partitions (~> 1, >= 1.651.0)
107107
aws-sigv4 (~> 1.9)
108108
jmespath (~> 1, >= 1.6.1)
109-
aws-sdk-kms (1.92.0)
109+
aws-sdk-kms (1.93.0)
110110
aws-sdk-core (~> 3, >= 3.207.0)
111111
aws-sigv4 (~> 1.5)
112-
aws-sdk-s3 (1.164.0)
112+
aws-sdk-s3 (1.165.0)
113113
aws-sdk-core (~> 3, >= 3.207.0)
114114
aws-sdk-kms (~> 1)
115115
aws-sigv4 (~> 1.5)
@@ -893,7 +893,7 @@ GEM
893893
rack-proxy (>= 0.6.1)
894894
railties (>= 5.2)
895895
semantic_range (>= 2.3.0)
896-
webrick (1.8.1)
896+
webrick (1.8.2)
897897
websocket (1.2.11)
898898
websocket-driver (0.7.6)
899899
websocket-extensions (>= 0.1.0)

app/javascript/flavours/glitch/actions/accounts.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { browserHistory } from 'flavours/glitch/components/router';
2+
import { debounceWithDispatchAndArguments } from 'flavours/glitch/utils/debounce';
23

34
import api, { getLinks } from '../api';
45

@@ -462,6 +463,20 @@ export function expandFollowingFail(id, error) {
462463
};
463464
}
464465

466+
const debouncedFetchRelationships = debounceWithDispatchAndArguments((dispatch, ...newAccountIds) => {
467+
if (newAccountIds.length === 0) {
468+
return;
469+
}
470+
471+
dispatch(fetchRelationshipsRequest(newAccountIds));
472+
473+
api().get(`/api/v1/accounts/relationships?with_suspended=true&${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
474+
dispatch(fetchRelationshipsSuccess({ relationships: response.data }));
475+
}).catch(error => {
476+
dispatch(fetchRelationshipsFail(error));
477+
});
478+
}, { delay: 500 });
479+
465480
export function fetchRelationships(accountIds) {
466481
return (dispatch, getState) => {
467482
const state = getState();
@@ -473,13 +488,7 @@ export function fetchRelationships(accountIds) {
473488
return;
474489
}
475490

476-
dispatch(fetchRelationshipsRequest(newAccountIds));
477-
478-
api().get(`/api/v1/accounts/relationships?with_suspended=true&${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
479-
dispatch(fetchRelationshipsSuccess({ relationships: response.data }));
480-
}).catch(error => {
481-
dispatch(fetchRelationshipsFail(error));
482-
});
491+
debouncedFetchRelationships(dispatch, ...newAccountIds);
483492
};
484493
}
485494

app/javascript/flavours/glitch/actions/notification_policies.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export const updateNotificationsPolicy = createDataLoadingThunk(
1717
(policy: Partial<NotificationPolicy>) => apiUpdateNotificationsPolicy(policy),
1818
);
1919

20-
export const decreasePendingNotificationsCount = createAction<number>(
21-
'notificationPolicy/decreasePendingNotificationCount',
20+
export const decreasePendingRequestsCount = createAction<number>(
21+
'notificationPolicy/decreasePendingRequestsCount',
2222
);

app/javascript/flavours/glitch/actions/notification_requests.ts

+10-30
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import type {
1313
ApiNotificationJSON,
1414
} from 'flavours/glitch/api_types/notifications';
1515
import type { ApiStatusJSON } from 'flavours/glitch/api_types/statuses';
16-
import type { AppDispatch, RootState } from 'flavours/glitch/store';
16+
import type { AppDispatch } from 'flavours/glitch/store';
1717
import { createDataLoadingThunk } from 'flavours/glitch/store/typed_functions';
1818

1919
import { importFetchedAccounts, importFetchedStatuses } from './importer';
20-
import { decreasePendingNotificationsCount } from './notification_policies';
20+
import { decreasePendingRequestsCount } from './notification_policies';
2121

2222
// TODO: refactor with notification_groups
2323
function dispatchAssociatedRecords(
@@ -169,19 +169,11 @@ export const expandNotificationsForRequest = createDataLoadingThunk(
169169
},
170170
);
171171

172-
const selectNotificationCountForRequest = (state: RootState, id: string) => {
173-
const requests = state.notificationRequests.items;
174-
const thisRequest = requests.find((request) => request.id === id);
175-
return thisRequest ? thisRequest.notifications_count : 0;
176-
};
177-
178172
export const acceptNotificationRequest = createDataLoadingThunk(
179173
'notificationRequest/accept',
180174
({ id }: { id: string }) => apiAcceptNotificationRequest(id),
181-
(_data, { dispatch, getState, discardLoadData, actionArg: { id } }) => {
182-
const count = selectNotificationCountForRequest(getState(), id);
183-
184-
dispatch(decreasePendingNotificationsCount(count));
175+
(_data, { dispatch, discardLoadData }) => {
176+
dispatch(decreasePendingRequestsCount(1));
185177

186178
// The payload is not used in any functions
187179
return discardLoadData;
@@ -191,10 +183,8 @@ export const acceptNotificationRequest = createDataLoadingThunk(
191183
export const dismissNotificationRequest = createDataLoadingThunk(
192184
'notificationRequest/dismiss',
193185
({ id }: { id: string }) => apiDismissNotificationRequest(id),
194-
(_data, { dispatch, getState, discardLoadData, actionArg: { id } }) => {
195-
const count = selectNotificationCountForRequest(getState(), id);
196-
197-
dispatch(decreasePendingNotificationsCount(count));
186+
(_data, { dispatch, discardLoadData }) => {
187+
dispatch(decreasePendingRequestsCount(1));
198188

199189
// The payload is not used in any functions
200190
return discardLoadData;
@@ -204,13 +194,8 @@ export const dismissNotificationRequest = createDataLoadingThunk(
204194
export const acceptNotificationRequests = createDataLoadingThunk(
205195
'notificationRequests/acceptBulk',
206196
({ ids }: { ids: string[] }) => apiAcceptNotificationRequests(ids),
207-
(_data, { dispatch, getState, discardLoadData, actionArg: { ids } }) => {
208-
const count = ids.reduce(
209-
(count, id) => count + selectNotificationCountForRequest(getState(), id),
210-
0,
211-
);
212-
213-
dispatch(decreasePendingNotificationsCount(count));
197+
(_data, { dispatch, discardLoadData, actionArg: { ids } }) => {
198+
dispatch(decreasePendingRequestsCount(ids.length));
214199

215200
// The payload is not used in any functions
216201
return discardLoadData;
@@ -220,13 +205,8 @@ export const acceptNotificationRequests = createDataLoadingThunk(
220205
export const dismissNotificationRequests = createDataLoadingThunk(
221206
'notificationRequests/dismissBulk',
222207
({ ids }: { ids: string[] }) => apiDismissNotificationRequests(ids),
223-
(_data, { dispatch, getState, discardLoadData, actionArg: { ids } }) => {
224-
const count = ids.reduce(
225-
(count, id) => count + selectNotificationCountForRequest(getState(), id),
226-
0,
227-
);
228-
229-
dispatch(decreasePendingNotificationsCount(count));
208+
(_data, { dispatch, discardLoadData, actionArg: { ids } }) => {
209+
dispatch(decreasePendingRequestsCount(ids.length));
230210

231211
// The payload is not used in any functions
232212
return discardLoadData;

app/javascript/flavours/glitch/actions/notifications.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import api, { getLinks } from '../api';
1010
import { unescapeHTML } from '../utils/html';
1111
import { requestNotificationPermission } from '../utils/notifications';
1212

13-
import { fetchFollowRequests, fetchRelationships } from './accounts';
13+
import { fetchFollowRequests } from './accounts';
1414
import {
1515
importFetchedAccount,
1616
importFetchedAccounts,
@@ -68,14 +68,6 @@ defineMessages({
6868
mention: { id: 'notification.mention', defaultMessage: '{name} mentioned you' },
6969
});
7070

71-
const fetchRelatedRelationships = (dispatch, notifications) => {
72-
const accountIds = notifications.filter(item => ['follow', 'follow_request', 'admin.sign_up'].indexOf(item.type) !== -1).map(item => item.account.id);
73-
74-
if (accountIds.length > 0) {
75-
dispatch(fetchRelationships(accountIds));
76-
}
77-
};
78-
7971
export const loadPending = () => ({
8072
type: NOTIFICATIONS_LOAD_PENDING,
8173
});
@@ -118,8 +110,6 @@ export function updateNotifications(notification, intlMessages, intlLocale) {
118110

119111

120112
dispatch(notificationsUpdate({ notification, preferPendingItems, playSound: playSound && !filtered}));
121-
122-
fetchRelatedRelationships(dispatch, [notification]);
123113
} else if (playSound && !filtered) {
124114
dispatch({
125115
type: NOTIFICATIONS_UPDATE_NOOP,
@@ -211,7 +201,6 @@ export function expandNotifications({ maxId = undefined, forceLoad = false }) {
211201
dispatch(importFetchedAccounts(response.data.filter(item => item.report).map(item => item.report.target_account)));
212202

213203
dispatch(expandNotificationsSuccess(response.data, next ? next.uri : null, isLoadingMore, isLoadingRecent, isLoadingRecent && preferPendingItems));
214-
fetchRelatedRelationships(dispatch, response.data);
215204
dispatch(submitMarkers());
216205
} catch(error) {
217206
dispatch(expandNotificationsFail(error, isLoadingMore));

app/javascript/flavours/glitch/api/notifications.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ export const apiAcceptNotificationRequests = async (id: string[]) => {
9191
};
9292

9393
export const apiDismissNotificationRequests = async (id: string[]) => {
94-
return apiRequestPost('v1/notifications/dismiss/dismiss', { id });
94+
return apiRequestPost('v1/notifications/requests/dismiss', { id });
9595
};

app/javascript/flavours/glitch/features/notifications/components/filtered_notifications_banner.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const FilteredNotificationsIconButton: React.FC<{
3131
history.push('/notifications/requests');
3232
}, [history]);
3333

34-
if (policy === null || policy.summary.pending_notifications_count === 0) {
34+
if (policy === null || policy.summary.pending_requests_count <= 0) {
3535
return null;
3636
}
3737

@@ -70,7 +70,7 @@ export const FilteredNotificationsBanner: React.FC = () => {
7070
};
7171
}, [dispatch]);
7272

73-
if (policy === null || policy.summary.pending_notifications_count === 0) {
73+
if (policy === null || policy.summary.pending_requests_count <= 0) {
7474
return null;
7575
}
7676

app/javascript/flavours/glitch/reducers/notification_policy.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ import { createReducer, isAnyOf } from '@reduxjs/toolkit';
22

33
import {
44
fetchNotificationPolicy,
5-
decreasePendingNotificationsCount,
5+
decreasePendingRequestsCount,
66
updateNotificationsPolicy,
77
} from 'flavours/glitch/actions/notification_policies';
88
import type { NotificationPolicy } from 'flavours/glitch/models/notification_policy';
99

1010
export const notificationPolicyReducer =
1111
createReducer<NotificationPolicy | null>(null, (builder) => {
1212
builder
13-
.addCase(decreasePendingNotificationsCount, (state, action) => {
13+
.addCase(decreasePendingRequestsCount, (state, action) => {
1414
if (state) {
15-
state.summary.pending_notifications_count -= action.payload;
16-
state.summary.pending_requests_count -= 1;
15+
state.summary.pending_requests_count -= action.payload;
1716
}
1817
})
1918
.addMatcher(

app/javascript/flavours/glitch/styles/components.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -7392,7 +7392,7 @@ img.modal-warning {
73927392

73937393
.media-gallery__actions {
73947394
position: absolute;
7395-
bottom: 6px;
7395+
top: 6px;
73967396
inset-inline-end: 6px;
73977397
display: flex;
73987398
gap: 2px;
@@ -7415,7 +7415,7 @@ img.modal-warning {
74157415
.media-gallery__item__badges {
74167416
position: absolute;
74177417
bottom: 8px;
7418-
inset-inline-start: 8px;
7418+
inset-inline-end: 8px;
74197419
display: flex;
74207420
gap: 2px;
74217421

app/javascript/flavours/glitch/styles/dashboard.scss

+1-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@
8686
color: $primary-text-color;
8787
transition: all 100ms ease-in;
8888
font-size: 14px;
89-
padding: 0 16px;
90-
line-height: 36px;
91-
height: 36px;
89+
padding: 8px 16px;
9290
text-decoration: none;
9391
margin-bottom: 4px;
9492

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { debounce } from 'lodash';
2+
3+
import type { AppDispatch } from 'flavours/glitch/store';
4+
5+
export const debounceWithDispatchAndArguments = <T>(
6+
fn: (dispatch: AppDispatch, ...args: T[]) => void,
7+
{ delay = 100 },
8+
) => {
9+
let argumentBuffer: T[] = [];
10+
let dispatchBuffer: AppDispatch;
11+
12+
const wrapped = debounce(() => {
13+
const tmpBuffer = argumentBuffer;
14+
argumentBuffer = [];
15+
fn(dispatchBuffer, ...tmpBuffer);
16+
}, delay);
17+
18+
return (dispatch: AppDispatch, ...args: T[]) => {
19+
dispatchBuffer = dispatch;
20+
argumentBuffer.push(...args);
21+
wrapped();
22+
};
23+
};

app/javascript/mastodon/actions/accounts.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { browserHistory } from 'mastodon/components/router';
2+
import { debounceWithDispatchAndArguments } from 'mastodon/utils/debounce';
23

34
import api, { getLinks } from '../api';
45

@@ -449,6 +450,20 @@ export function expandFollowingFail(id, error) {
449450
};
450451
}
451452

453+
const debouncedFetchRelationships = debounceWithDispatchAndArguments((dispatch, ...newAccountIds) => {
454+
if (newAccountIds.length === 0) {
455+
return;
456+
}
457+
458+
dispatch(fetchRelationshipsRequest(newAccountIds));
459+
460+
api().get(`/api/v1/accounts/relationships?with_suspended=true&${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
461+
dispatch(fetchRelationshipsSuccess({ relationships: response.data }));
462+
}).catch(error => {
463+
dispatch(fetchRelationshipsFail(error));
464+
});
465+
}, { delay: 500 });
466+
452467
export function fetchRelationships(accountIds) {
453468
return (dispatch, getState) => {
454469
const state = getState();
@@ -460,13 +475,7 @@ export function fetchRelationships(accountIds) {
460475
return;
461476
}
462477

463-
dispatch(fetchRelationshipsRequest(newAccountIds));
464-
465-
api().get(`/api/v1/accounts/relationships?with_suspended=true&${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
466-
dispatch(fetchRelationshipsSuccess({ relationships: response.data }));
467-
}).catch(error => {
468-
dispatch(fetchRelationshipsFail(error));
469-
});
478+
debouncedFetchRelationships(dispatch, ...newAccountIds);
470479
};
471480
}
472481

app/javascript/mastodon/actions/notification_policies.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export const updateNotificationsPolicy = createDataLoadingThunk(
1717
(policy: Partial<NotificationPolicy>) => apiUpdateNotificationsPolicy(policy),
1818
);
1919

20-
export const decreasePendingNotificationsCount = createAction<number>(
21-
'notificationPolicy/decreasePendingNotificationCount',
20+
export const decreasePendingRequestsCount = createAction<number>(
21+
'notificationPolicy/decreasePendingRequestsCount',
2222
);

0 commit comments

Comments
 (0)