Skip to content

Commit

Permalink
Merge pull request #2856 from ClearlyClaire/glitch-soc/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream changes up to 7098851
  • Loading branch information
ClearlyClaire authored Sep 24, 2024
2 parents 6551129 + ba7b1f0 commit 5df7e36
Show file tree
Hide file tree
Showing 109 changed files with 458 additions and 273 deletions.
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

0 comments on commit 5df7e36

Please sign in to comment.