Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream changes up to 70988519df66f0b8edeb6ca95140f1d3e436fea8 #2856

Merged
merged 17 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d54ce67
Change hide media button to be in top right corner in web UI (#32048)
Gargron Sep 24, 2024
c808055
Update dependency webrick (#32054)
ClearlyClaire Sep 24, 2024
11ac5c8
New Crowdin Translations (automated) (#32052)
github-actions[bot] Sep 24, 2024
7c61533
Update dependency aws-sdk-s3 to v1.165.0 (#32050)
renovate[bot] Sep 24, 2024
780e2e9
Convert notification mailer spec shared examples to matchers (#32047)
mjankowski Sep 24, 2024
19dedd7
Set important mailer headers with `after_action` callback (#32057)
mjankowski Sep 24, 2024
cfb8fc6
Increase regexp timeout and allow override (#32056)
oneiros Sep 24, 2024
0a6b75b
Fix multiple bugs in notification requests and notification policies …
ClearlyClaire Sep 24, 2024
c36a76b
Fix error when accepting appeal for sensitive posts deleted in the me…
ClearlyClaire Sep 24, 2024
556837f
Fix the summary of converted object types to be treated as HTML (#28629)
Menrath Sep 24, 2024
f1b6a61
Fix wrapping in dashboard quick access buttons (#32043)
renchap Sep 24, 2024
7098851
Fix too many requests caused by relationship look-ups in web UI (#32042)
Gargron Sep 24, 2024
c6039f9
Merge commit '70988519df66f0b8edeb6ca95140f1d3e436fea8' into glitch-s…
ClearlyClaire Sep 24, 2024
aac6296
[Glitch] Change hide media button to be in top right corner in web UI
Gargron Sep 24, 2024
1316962
[Glitch] Fix multiple bugs in notification requests and notification …
ClearlyClaire Sep 24, 2024
6142adc
[Glitch] Fix wrapping in dashboard quick access buttons
renchap Sep 24, 2024
ba7b1f0
[Glitch] Fix too many requests caused by relationship look-ups in web UI
Gargron Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ GEM
awrence (1.2.1)
aws-eventstream (1.3.0)
aws-partitions (1.977.0)
aws-sdk-core (3.207.0)
aws-sdk-core (3.208.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.92.0)
aws-sdk-kms (1.93.0)
aws-sdk-core (~> 3, >= 3.207.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.164.0)
aws-sdk-s3 (1.165.0)
aws-sdk-core (~> 3, >= 3.207.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand Down Expand Up @@ -893,7 +893,7 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
webrick (1.8.1)
webrick (1.8.2)
websocket (1.2.11)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
Expand Down
23 changes: 16 additions & 7 deletions app/javascript/flavours/glitch/actions/accounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { browserHistory } from 'flavours/glitch/components/router';
import { debounceWithDispatchAndArguments } from 'flavours/glitch/utils/debounce';

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

Expand Down Expand Up @@ -462,6 +463,20 @@ export function expandFollowingFail(id, error) {
};
}

const debouncedFetchRelationships = debounceWithDispatchAndArguments((dispatch, ...newAccountIds) => {
if (newAccountIds.length === 0) {
return;
}

dispatch(fetchRelationshipsRequest(newAccountIds));

api().get(`/api/v1/accounts/relationships?with_suspended=true&${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
dispatch(fetchRelationshipsSuccess({ relationships: response.data }));
}).catch(error => {
dispatch(fetchRelationshipsFail(error));
});
}, { delay: 500 });

export function fetchRelationships(accountIds) {
return (dispatch, getState) => {
const state = getState();
Expand All @@ -473,13 +488,7 @@ export function fetchRelationships(accountIds) {
return;
}

dispatch(fetchRelationshipsRequest(newAccountIds));

api().get(`/api/v1/accounts/relationships?with_suspended=true&${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
dispatch(fetchRelationshipsSuccess({ relationships: response.data }));
}).catch(error => {
dispatch(fetchRelationshipsFail(error));
});
debouncedFetchRelationships(dispatch, ...newAccountIds);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export const updateNotificationsPolicy = createDataLoadingThunk(
(policy: Partial<NotificationPolicy>) => apiUpdateNotificationsPolicy(policy),
);

export const decreasePendingNotificationsCount = createAction<number>(
'notificationPolicy/decreasePendingNotificationCount',
export const decreasePendingRequestsCount = createAction<number>(
'notificationPolicy/decreasePendingRequestsCount',
);
40 changes: 10 additions & 30 deletions app/javascript/flavours/glitch/actions/notification_requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import type {
ApiNotificationJSON,
} from 'flavours/glitch/api_types/notifications';
import type { ApiStatusJSON } from 'flavours/glitch/api_types/statuses';
import type { AppDispatch, RootState } from 'flavours/glitch/store';
import type { AppDispatch } from 'flavours/glitch/store';
import { createDataLoadingThunk } from 'flavours/glitch/store/typed_functions';

import { importFetchedAccounts, importFetchedStatuses } from './importer';
import { decreasePendingNotificationsCount } from './notification_policies';
import { decreasePendingRequestsCount } from './notification_policies';

// TODO: refactor with notification_groups
function dispatchAssociatedRecords(
Expand Down Expand Up @@ -169,19 +169,11 @@ export const expandNotificationsForRequest = createDataLoadingThunk(
},
);

const selectNotificationCountForRequest = (state: RootState, id: string) => {
const requests = state.notificationRequests.items;
const thisRequest = requests.find((request) => request.id === id);
return thisRequest ? thisRequest.notifications_count : 0;
};

export const acceptNotificationRequest = createDataLoadingThunk(
'notificationRequest/accept',
({ id }: { id: string }) => apiAcceptNotificationRequest(id),
(_data, { dispatch, getState, discardLoadData, actionArg: { id } }) => {
const count = selectNotificationCountForRequest(getState(), id);

dispatch(decreasePendingNotificationsCount(count));
(_data, { dispatch, discardLoadData }) => {
dispatch(decreasePendingRequestsCount(1));

// The payload is not used in any functions
return discardLoadData;
Expand All @@ -191,10 +183,8 @@ export const acceptNotificationRequest = createDataLoadingThunk(
export const dismissNotificationRequest = createDataLoadingThunk(
'notificationRequest/dismiss',
({ id }: { id: string }) => apiDismissNotificationRequest(id),
(_data, { dispatch, getState, discardLoadData, actionArg: { id } }) => {
const count = selectNotificationCountForRequest(getState(), id);

dispatch(decreasePendingNotificationsCount(count));
(_data, { dispatch, discardLoadData }) => {
dispatch(decreasePendingRequestsCount(1));

// The payload is not used in any functions
return discardLoadData;
Expand All @@ -204,13 +194,8 @@ export const dismissNotificationRequest = createDataLoadingThunk(
export const acceptNotificationRequests = createDataLoadingThunk(
'notificationRequests/acceptBulk',
({ ids }: { ids: string[] }) => apiAcceptNotificationRequests(ids),
(_data, { dispatch, getState, discardLoadData, actionArg: { ids } }) => {
const count = ids.reduce(
(count, id) => count + selectNotificationCountForRequest(getState(), id),
0,
);

dispatch(decreasePendingNotificationsCount(count));
(_data, { dispatch, discardLoadData, actionArg: { ids } }) => {
dispatch(decreasePendingRequestsCount(ids.length));

// The payload is not used in any functions
return discardLoadData;
Expand All @@ -220,13 +205,8 @@ export const acceptNotificationRequests = createDataLoadingThunk(
export const dismissNotificationRequests = createDataLoadingThunk(
'notificationRequests/dismissBulk',
({ ids }: { ids: string[] }) => apiDismissNotificationRequests(ids),
(_data, { dispatch, getState, discardLoadData, actionArg: { ids } }) => {
const count = ids.reduce(
(count, id) => count + selectNotificationCountForRequest(getState(), id),
0,
);

dispatch(decreasePendingNotificationsCount(count));
(_data, { dispatch, discardLoadData, actionArg: { ids } }) => {
dispatch(decreasePendingRequestsCount(ids.length));

// The payload is not used in any functions
return discardLoadData;
Expand Down
13 changes: 1 addition & 12 deletions app/javascript/flavours/glitch/actions/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import api, { getLinks } from '../api';
import { unescapeHTML } from '../utils/html';
import { requestNotificationPermission } from '../utils/notifications';

import { fetchFollowRequests, fetchRelationships } from './accounts';
import { fetchFollowRequests } from './accounts';
import {
importFetchedAccount,
importFetchedAccounts,
Expand Down Expand Up @@ -68,14 +68,6 @@ defineMessages({
mention: { id: 'notification.mention', defaultMessage: '{name} mentioned you' },
});

const fetchRelatedRelationships = (dispatch, notifications) => {
const accountIds = notifications.filter(item => ['follow', 'follow_request', 'admin.sign_up'].indexOf(item.type) !== -1).map(item => item.account.id);

if (accountIds.length > 0) {
dispatch(fetchRelationships(accountIds));
}
};

export const loadPending = () => ({
type: NOTIFICATIONS_LOAD_PENDING,
});
Expand Down Expand Up @@ -118,8 +110,6 @@ export function updateNotifications(notification, intlMessages, intlLocale) {


dispatch(notificationsUpdate({ notification, preferPendingItems, playSound: playSound && !filtered}));

fetchRelatedRelationships(dispatch, [notification]);
} else if (playSound && !filtered) {
dispatch({
type: NOTIFICATIONS_UPDATE_NOOP,
Expand Down Expand Up @@ -211,7 +201,6 @@ export function expandNotifications({ maxId = undefined, forceLoad = false }) {
dispatch(importFetchedAccounts(response.data.filter(item => item.report).map(item => item.report.target_account)));

dispatch(expandNotificationsSuccess(response.data, next ? next.uri : null, isLoadingMore, isLoadingRecent, isLoadingRecent && preferPendingItems));
fetchRelatedRelationships(dispatch, response.data);
dispatch(submitMarkers());
} catch(error) {
dispatch(expandNotificationsFail(error, isLoadingMore));
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/flavours/glitch/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ export const apiAcceptNotificationRequests = async (id: string[]) => {
};

export const apiDismissNotificationRequests = async (id: string[]) => {
return apiRequestPost('v1/notifications/dismiss/dismiss', { id });
return apiRequestPost('v1/notifications/requests/dismiss', { id });
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const FilteredNotificationsIconButton: React.FC<{
history.push('/notifications/requests');
}, [history]);

if (policy === null || policy.summary.pending_notifications_count === 0) {
if (policy === null || policy.summary.pending_requests_count <= 0) {
return null;
}

Expand Down Expand Up @@ -70,7 +70,7 @@ export const FilteredNotificationsBanner: React.FC = () => {
};
}, [dispatch]);

if (policy === null || policy.summary.pending_notifications_count === 0) {
if (policy === null || policy.summary.pending_requests_count <= 0) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { createReducer, isAnyOf } from '@reduxjs/toolkit';

import {
fetchNotificationPolicy,
decreasePendingNotificationsCount,
decreasePendingRequestsCount,
updateNotificationsPolicy,
} from 'flavours/glitch/actions/notification_policies';
import type { NotificationPolicy } from 'flavours/glitch/models/notification_policy';

export const notificationPolicyReducer =
createReducer<NotificationPolicy | null>(null, (builder) => {
builder
.addCase(decreasePendingNotificationsCount, (state, action) => {
.addCase(decreasePendingRequestsCount, (state, action) => {
if (state) {
state.summary.pending_notifications_count -= action.payload;
state.summary.pending_requests_count -= 1;
state.summary.pending_requests_count -= action.payload;
}
})
.addMatcher(
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/flavours/glitch/styles/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7392,7 +7392,7 @@ img.modal-warning {

.media-gallery__actions {
position: absolute;
bottom: 6px;
top: 6px;
inset-inline-end: 6px;
display: flex;
gap: 2px;
Expand All @@ -7415,7 +7415,7 @@ img.modal-warning {
.media-gallery__item__badges {
position: absolute;
bottom: 8px;
inset-inline-start: 8px;
inset-inline-end: 8px;
display: flex;
gap: 2px;

Expand Down
4 changes: 1 addition & 3 deletions app/javascript/flavours/glitch/styles/dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@
color: $primary-text-color;
transition: all 100ms ease-in;
font-size: 14px;
padding: 0 16px;
line-height: 36px;
height: 36px;
padding: 8px 16px;
text-decoration: none;
margin-bottom: 4px;

Expand Down
23 changes: 23 additions & 0 deletions app/javascript/flavours/glitch/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { debounce } from 'lodash';

import type { AppDispatch } from 'flavours/glitch/store';

export const debounceWithDispatchAndArguments = <T>(
fn: (dispatch: AppDispatch, ...args: T[]) => void,
{ delay = 100 },
) => {
let argumentBuffer: T[] = [];
let dispatchBuffer: AppDispatch;

const wrapped = debounce(() => {
const tmpBuffer = argumentBuffer;
argumentBuffer = [];
fn(dispatchBuffer, ...tmpBuffer);
}, delay);

return (dispatch: AppDispatch, ...args: T[]) => {
dispatchBuffer = dispatch;
argumentBuffer.push(...args);
wrapped();
};
};
23 changes: 16 additions & 7 deletions app/javascript/mastodon/actions/accounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { browserHistory } from 'mastodon/components/router';
import { debounceWithDispatchAndArguments } from 'mastodon/utils/debounce';

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

Expand Down Expand Up @@ -449,6 +450,20 @@ export function expandFollowingFail(id, error) {
};
}

const debouncedFetchRelationships = debounceWithDispatchAndArguments((dispatch, ...newAccountIds) => {
if (newAccountIds.length === 0) {
return;
}

dispatch(fetchRelationshipsRequest(newAccountIds));

api().get(`/api/v1/accounts/relationships?with_suspended=true&${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
dispatch(fetchRelationshipsSuccess({ relationships: response.data }));
}).catch(error => {
dispatch(fetchRelationshipsFail(error));
});
}, { delay: 500 });

export function fetchRelationships(accountIds) {
return (dispatch, getState) => {
const state = getState();
Expand All @@ -460,13 +475,7 @@ export function fetchRelationships(accountIds) {
return;
}

dispatch(fetchRelationshipsRequest(newAccountIds));

api().get(`/api/v1/accounts/relationships?with_suspended=true&${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then(response => {
dispatch(fetchRelationshipsSuccess({ relationships: response.data }));
}).catch(error => {
dispatch(fetchRelationshipsFail(error));
});
debouncedFetchRelationships(dispatch, ...newAccountIds);
};
}

Expand Down
4 changes: 2 additions & 2 deletions app/javascript/mastodon/actions/notification_policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export const updateNotificationsPolicy = createDataLoadingThunk(
(policy: Partial<NotificationPolicy>) => apiUpdateNotificationsPolicy(policy),
);

export const decreasePendingNotificationsCount = createAction<number>(
'notificationPolicy/decreasePendingNotificationCount',
export const decreasePendingRequestsCount = createAction<number>(
'notificationPolicy/decreasePendingRequestsCount',
);
Loading
Loading