pl-api: Add some newer Mastodon methods
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
72aa5c69d0
commit
822e7e2287
4 changed files with 65 additions and 17 deletions
|
@ -169,6 +169,7 @@ import type {
|
|||
GetTrendingLinks,
|
||||
GetTrendingStatuses,
|
||||
GetTrendingTags,
|
||||
GetUnreadNotificationCountParams,
|
||||
GroupTimelineParams,
|
||||
HashtagTimelineParams,
|
||||
HomeTimelineParams,
|
||||
|
@ -2524,13 +2525,30 @@ class PlApiClient {
|
|||
return response.json as {};
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the number of unread notification
|
||||
* Get the (capped) number of unread notifications for the current user.
|
||||
*
|
||||
* Requires features{@link Features['notificationsGetUnreadCount']}.
|
||||
* @see {@link https://docs.joinmastodon.org/methods/notifications/#unread-count}
|
||||
*/
|
||||
getUnreadNotificationCount: async (params?: GetUnreadNotificationCountParams) => {
|
||||
const response = await this.request('/api/v1/notifications/unread_count', { params });
|
||||
|
||||
return v.parse(v.object({
|
||||
count: v.number(),
|
||||
}), response.json);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the filtering policy for notifications
|
||||
* Notifications filtering policy for the user.
|
||||
*
|
||||
* Requires features{@link Features['notificationsPolicy']}.
|
||||
* @see {@link https://docs.joinmastodon.org/methods/notifications/#get-policy}
|
||||
*/
|
||||
getNotificationPolicy: async () => {
|
||||
const response = await this.request('/api/v1/notifications/policy');
|
||||
const response = await this.request('/api/v2/notifications/policy');
|
||||
|
||||
return v.parse(notificationPolicySchema, response.json);
|
||||
},
|
||||
|
@ -2538,10 +2556,12 @@ class PlApiClient {
|
|||
/**
|
||||
* Update the filtering policy for notifications
|
||||
* Update the user’s notifications filtering policy.
|
||||
*
|
||||
* Requires features{@link Features['notificationsPolicy']}.
|
||||
* @see {@link https://docs.joinmastodon.org/methods/notifications/#update-the-filtering-policy-for-notifications}
|
||||
*/
|
||||
updateNotificationPolicy: async (params: UpdateNotificationPolicyRequest) => {
|
||||
const response = await this.request('/api/v1/notifications/policy', { method: 'POST', body: params });
|
||||
const response = await this.request('/api/v2/notifications/policy', { method: 'PATCH', body: params });
|
||||
|
||||
return v.parse(notificationPolicySchema, response.json);
|
||||
},
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import * as v from 'valibot';
|
||||
|
||||
const notificationPolicyRuleSchema = v.picklist(['accept', 'filter', 'drop']);
|
||||
|
||||
/** @see {@link https://docs.joinmastodon.org/entities/NotificationPolicy} */
|
||||
const notificationPolicySchema = v.object({
|
||||
filter_not_following: v.boolean(),
|
||||
filter_not_followers: v.boolean(),
|
||||
filter_new_accounts: v.boolean(),
|
||||
filter_private_mentions: v.boolean(),
|
||||
for_not_following: notificationPolicyRuleSchema,
|
||||
for_not_followers: notificationPolicyRuleSchema,
|
||||
for_new_accounts: notificationPolicyRuleSchema,
|
||||
for_private_mentions: notificationPolicyRuleSchema,
|
||||
for_limited_accounts: notificationPolicyRuleSchema,
|
||||
summary: v.object({
|
||||
pending_requests_count: v.pipe(v.number(), v.integer()),
|
||||
pending_notifications_count: v.pipe(v.number(), v.integer()),
|
||||
|
|
|
@ -833,6 +833,11 @@ const getFeatures = (instance: Instance) => {
|
|||
*/
|
||||
notificationsExcludeVisibilities: v.software === PLEROMA,
|
||||
|
||||
/**
|
||||
* @see GET /api/v1/notifications/unread_count
|
||||
*/
|
||||
notificationsGetUnreadCount: instance.api_versions.mastodon >= 1,
|
||||
|
||||
/**
|
||||
* Allows specifying notification types to include, rather than to exclude.
|
||||
* @see GET /api/v1/notifications
|
||||
|
@ -846,6 +851,12 @@ const getFeatures = (instance: Instance) => {
|
|||
v.software === GOTOSOCIAL,
|
||||
]),
|
||||
|
||||
/**
|
||||
* @see GET /api/v2/notifications/policy
|
||||
* @see PATCH /api/v2/notifications/policy
|
||||
*/
|
||||
notificationsPolicy: instance.api_versions.mastodon >= 1,
|
||||
|
||||
pleromaAdminAccounts: v.software === PLEROMA,
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import type { PaginationParams } from './common';
|
||||
|
||||
interface GetNotificationParams extends PaginationParams {
|
||||
/** Array of String. Types to include in the result. */
|
||||
/** Types to include in the result. */
|
||||
types?: string[];
|
||||
/** Array of String. Types to exclude from the results. */
|
||||
/** Types to exclude from the results. */
|
||||
exclude_types?: string[];
|
||||
/** String. Return only notifications received from the specified account. */
|
||||
/** Return only notifications received from the specified account. */
|
||||
account_id?: string;
|
||||
/**
|
||||
* will exclude the notifications for activities with the given visibilities. The parameter accepts an array of visibility types (`public`, `unlisted`, `private`, `direct`).
|
||||
|
@ -14,21 +14,35 @@ interface GetNotificationParams extends PaginationParams {
|
|||
exclude_visibilities?: string[];
|
||||
}
|
||||
|
||||
interface GetUnreadNotificationCountParams {
|
||||
/** Maximum number of results to return. Defaults to 100 notifications. Max 1000 notifications. */
|
||||
limit?: number;
|
||||
/** Types of notifications that should count towards unread notifications. */
|
||||
types?: string[];
|
||||
/** Types of notifications that should not count towards unread notifications */
|
||||
exclude_types?: string[];
|
||||
/** Only count unread notifications received from the specified account. */
|
||||
account_id?: string;
|
||||
}
|
||||
|
||||
interface UpdateNotificationPolicyRequest {
|
||||
/** Boolean. Whether to filter notifications from accounts the user is not following. */
|
||||
filter_not_following?: boolean;
|
||||
/** Boolean. Whether to filter notifications from accounts that are not following the user. */
|
||||
filter_not_followers?: boolean;
|
||||
/** Boolean. Whether to filter notifications from accounts created in the past 30 days. */
|
||||
filter_new_accounts?: boolean;
|
||||
/** Boolean. Whether to filter notifications from private mentions. Replies to private mentions initiated by the user, as well as accounts the user follows, are never filtered. */
|
||||
filter_private_mentions?: boolean;
|
||||
/** Whether to `accept`, `filter` or `drop` notifications from accounts the user is not following. */
|
||||
for_not_following?: boolean;
|
||||
/** Whether to `accept`, `filter` or `drop` notifications from accounts that are not following the user. */
|
||||
for_not_followers?: boolean;
|
||||
/** Whether to `accept`, `filter` or `drop` notifications from accounts created in the past 30 days. */
|
||||
for_new_accounts?: boolean;
|
||||
/** Whether to `accept`, `filter` or `drop` notifications from private mentions. drop will prevent creation of the notification object altogether (without preventing the underlying activity), */
|
||||
for_private_mentions?: boolean;
|
||||
/** Whether to `accept`, `filter` or `drop` notifications from accounts that were limited by a moderator. */
|
||||
for_limited_accounts?: boolean;
|
||||
}
|
||||
|
||||
type GetNotificationRequestsParams = PaginationParams;
|
||||
|
||||
export type {
|
||||
GetNotificationParams,
|
||||
GetUnreadNotificationCountParams,
|
||||
UpdateNotificationPolicyRequest,
|
||||
GetNotificationRequestsParams,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue