2024-09-16 19:54:03 +10:00
|
|
|
import api, {
|
|
|
|
apiRequest,
|
|
|
|
getLinks,
|
|
|
|
apiRequestGet,
|
|
|
|
apiRequestPost,
|
|
|
|
} from 'mastodon/api';
|
|
|
|
import type {
|
|
|
|
ApiNotificationGroupsResultJSON,
|
|
|
|
ApiNotificationRequestJSON,
|
|
|
|
ApiNotificationJSON,
|
|
|
|
} from 'mastodon/api_types/notifications';
|
2024-07-19 00:36:09 +10:00
|
|
|
|
2024-09-16 19:54:03 +10:00
|
|
|
export const apiFetchNotifications = async (
|
|
|
|
params?: {
|
|
|
|
account_id?: string;
|
|
|
|
since_id?: string;
|
|
|
|
},
|
|
|
|
url?: string,
|
|
|
|
) => {
|
|
|
|
const response = await api().request<ApiNotificationJSON[]>({
|
|
|
|
method: 'GET',
|
|
|
|
url: url ?? '/api/v1/notifications',
|
|
|
|
params,
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
notifications: response.data,
|
|
|
|
links: getLinks(response),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const apiFetchNotificationGroups = async (params?: {
|
|
|
|
url?: string;
|
2024-07-19 00:36:09 +10:00
|
|
|
exclude_types?: string[];
|
|
|
|
max_id?: string;
|
2024-08-22 00:41:31 +10:00
|
|
|
since_id?: string;
|
2024-07-19 00:36:09 +10:00
|
|
|
}) => {
|
2024-07-31 20:50:13 +10:00
|
|
|
const response = await api().request<ApiNotificationGroupsResultJSON>({
|
2024-07-19 00:36:09 +10:00
|
|
|
method: 'GET',
|
2024-09-16 22:10:02 +10:00
|
|
|
url: '/api/v2/notifications',
|
2024-07-19 00:36:09 +10:00
|
|
|
params,
|
|
|
|
});
|
|
|
|
|
2024-07-31 20:50:13 +10:00
|
|
|
const { statuses, accounts, notification_groups } = response.data;
|
|
|
|
|
|
|
|
return {
|
|
|
|
statuses,
|
|
|
|
accounts,
|
|
|
|
notifications: notification_groups,
|
|
|
|
links: getLinks(response),
|
|
|
|
};
|
2024-07-19 00:36:09 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
export const apiClearNotifications = () =>
|
|
|
|
apiRequest<undefined>('POST', 'v1/notifications/clear');
|
2024-09-16 19:54:03 +10:00
|
|
|
|
|
|
|
export const apiFetchNotificationRequests = async (
|
|
|
|
params?: {
|
|
|
|
since_id?: string;
|
|
|
|
},
|
|
|
|
url?: string,
|
|
|
|
) => {
|
|
|
|
const response = await api().request<ApiNotificationRequestJSON[]>({
|
|
|
|
method: 'GET',
|
|
|
|
url: url ?? '/api/v1/notifications/requests',
|
|
|
|
params,
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
requests: response.data,
|
|
|
|
links: getLinks(response),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const apiFetchNotificationRequest = async (id: string) => {
|
|
|
|
return apiRequestGet<ApiNotificationRequestJSON>(
|
|
|
|
`v1/notifications/requests/${id}`,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const apiAcceptNotificationRequest = async (id: string) => {
|
|
|
|
return apiRequestPost(`v1/notifications/requests/${id}/accept`);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const apiDismissNotificationRequest = async (id: string) => {
|
|
|
|
return apiRequestPost(`v1/notifications/requests/${id}/dismiss`);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const apiAcceptNotificationRequests = async (id: string[]) => {
|
|
|
|
return apiRequestPost('v1/notifications/requests/accept', { id });
|
|
|
|
};
|
|
|
|
|
|
|
|
export const apiDismissNotificationRequests = async (id: string[]) => {
|
|
|
|
return apiRequestPost('v1/notifications/dismiss/dismiss', { id });
|
|
|
|
};
|