Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,21 @@ export abstract class BaseClient {
options?: RequestOptions,
): Promise<{ comment_view: types.CommentView }>;

abstract editCommunityNotifications(
payload: types.EditCommunityNotifications,
options?: RequestOptions,
): Promise<void>;

abstract editPost(
payload: types.EditPost,
options?: RequestOptions,
): Promise<{ post_view: types.PostView }>;

abstract editPostNotifications(
payload: types.EditPostNotifications,
options?: RequestOptions,
): Promise<void>;

abstract featurePost(
payload: {
feature_type: "community" | "local";
Expand Down
12 changes: 12 additions & 0 deletions src/SafeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,23 @@ export default function buildSafeClient(_Client: AnyClient): AnyClient {
return { comment_view: schemas.CommentView.parse(comment_view) };
}

async editCommunityNotifications(
...params: Parameters<BaseClient["editCommunityNotifications"]>
) {
await super.editCommunityNotifications(...params);
}

async editPost(...params: Parameters<BaseClient["editPost"]>) {
const { post_view } = await super.editPost(...params);
return { post_view: schemas.PostView.parse(post_view) };
}

async editPostNotifications(
...params: Parameters<BaseClient["editPostNotifications"]>
) {
await super.editPostNotifications(...params);
}

async featurePost(...params: Parameters<BaseClient["featurePost"]>) {
const { post_view } = await super.featurePost(...params);
return { post_view: schemas.PostView.parse(post_view) };
Expand Down
14 changes: 14 additions & 0 deletions src/ThreadiverseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,25 @@ export default class ThreadiverseClient implements BaseClient {
return client.editComment(...params);
}

async editCommunityNotifications(
...params: Parameters<BaseClient["editCommunityNotifications"]>
) {
const client = await this.ensureClient();
return client.editCommunityNotifications(...params);
}

async editPost(...params: Parameters<BaseClient["editPost"]>) {
const client = await this.ensureClient();
return client.editPost(...params);
}

async editPostNotifications(
...params: Parameters<BaseClient["editPostNotifications"]>
) {
const client = await this.ensureClient();
return client.editPostNotifications(...params);
}

async featurePost(...params: Parameters<BaseClient["featurePost"]>) {
const client = await this.ensureClient();
return client.featurePost(...params);
Expand Down
2 changes: 2 additions & 0 deletions src/providers/lemmyv0/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export function toCommunityView(v: LemmyV0.CommunityView): types.CommunityView {
return {
blocked: false,
community: toCommunityWithCounts(v.community, v.counts),
notifications: "replies_and_mentions",
subscribed: v.subscribed,
};
}
Expand Down Expand Up @@ -630,6 +631,7 @@ export function toPostView(v: LemmyV0.PostView): types.PostView {
creator_is_moderator: v.creator_is_moderator,
hidden: v.hidden ?? false, // v0.13.3
my_vote: toVote(v.my_vote),
notifications: "replies_and_mentions",
post: toPost(v.post, v.counts),
read: v.read,
saved: v.saved,
Expand Down
16 changes: 16 additions & 0 deletions src/providers/lemmyv0/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ export class UnsafeLemmyV0Client implements BaseClient {
};
}

async editCommunityNotifications(
..._params: Parameters<BaseClient["editCommunityNotifications"]>
): ReturnType<BaseClient["editCommunityNotifications"]> {
throw new UnsupportedError(
"Edit community notifications is not supported by Lemmy v0",
);
}

async editPost(
...params: Parameters<BaseClient["editPost"]>
): ReturnType<BaseClient["editPost"]> {
Expand All @@ -186,6 +194,14 @@ export class UnsafeLemmyV0Client implements BaseClient {
};
}

async editPostNotifications(
..._params: Parameters<BaseClient["editPostNotifications"]>
): ReturnType<BaseClient["editPostNotifications"]> {
throw new UnsupportedError(
"Edit post notifications is not supported by Lemmy v0",
);
}

async featurePost(
payload: Parameters<BaseClient["featurePost"]>[0],
options?: RequestOptions,
Expand Down
21 changes: 18 additions & 3 deletions src/providers/lemmyv1/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function toCommunityView(v: LemmyV1.CommunityView): types.CommunityView {
return {
...v,
blocked: !!v.community_actions?.blocked_at,
notifications: v.community_actions?.notifications ?? "replies_and_mentions",
subscribed: toFollowState(v.community_actions?.follow_state),
};
}
Expand Down Expand Up @@ -149,6 +150,7 @@ export function toPostView(v: LemmyV1.PostView): types.PostView {
creator_blocked: !!v.person_actions?.blocked_at,
hidden: !!v.post_actions?.hidden_at,
my_vote: toVote(v.post_actions),
notifications: v.post_actions?.notifications ?? "replies_and_mentions",
read: !!v.post_actions?.read_at,
saved: !!v.post_actions?.saved_at,
subscribed: toFollowState(v.community_actions?.follow_state),
Expand Down Expand Up @@ -233,9 +235,22 @@ export function toSupportedNotificationView(
};
}
case "subscribed":
// "Someone posted/commented in a community you subscribe to." Voyager
// already surfaces these via the home feed; not shown in inbox.
return;
switch (item.data.type_) {
case "comment":
return {
...item,
data: { type_: "comment", ...toCommentView(item.data) },
notification,
};
case "post":
return {
...item,
data: { type_: "post", ...toPostView(item.data) },
notification,
};
default:
return undefined;
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/providers/lemmyv1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ export class UnsafeLemmyV1Client implements BaseClient {
};
}

async editCommunityNotifications(
...params: Parameters<BaseClient["editCommunityNotifications"]>
): ReturnType<BaseClient["editCommunityNotifications"]> {
unwrap(await this.#client.editCommunityNotifications(...params));
}

async editPost(
...params: Parameters<BaseClient["editPost"]>
): ReturnType<BaseClient["editPost"]> {
Expand All @@ -194,6 +200,12 @@ export class UnsafeLemmyV1Client implements BaseClient {
};
}

async editPostNotifications(
...params: Parameters<BaseClient["editPostNotifications"]>
): ReturnType<BaseClient["editPostNotifications"]> {
unwrap(await this.#client.editPostNotifications(...params));
}

async featurePost(
...params: Parameters<BaseClient["featurePost"]>
): ReturnType<BaseClient["featurePost"]> {
Expand Down
2 changes: 2 additions & 0 deletions src/providers/piefed/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function toCommunityView(
return {
blocked: v.blocked,
community: toCommunity(v.community, v.counts),
notifications: "replies_and_mentions",
subscribed: toSubscribedType(v.subscribed),
};
}
Expand Down Expand Up @@ -249,6 +250,7 @@ export function toPostView(
creator_is_moderator: v.creator_is_moderator,
hidden: v.hidden,
my_vote: v.my_vote,
notifications: "replies_and_mentions",
post: toPost(v.post, v.counts),
read: v.read,
saved: v.saved,
Expand Down
16 changes: 16 additions & 0 deletions src/providers/piefed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ export class UnsafePiefedClient implements BaseClient {
};
}

async editCommunityNotifications(
..._params: Parameters<BaseClient["editCommunityNotifications"]>
): ReturnType<BaseClient["editCommunityNotifications"]> {
throw new UnsupportedError(
"Edit community notifications is not supported by piefed",
);
}

async editPost(
payload: Parameters<BaseClient["editPost"]>[0],
options?: RequestOptions,
Expand All @@ -300,6 +308,14 @@ export class UnsafePiefedClient implements BaseClient {
};
}

async editPostNotifications(
..._params: Parameters<BaseClient["editPostNotifications"]>
): ReturnType<BaseClient["editPostNotifications"]> {
throw new UnsupportedError(
"Edit post notifications is not supported by piefed",
);
}

async featurePost(
payload: Parameters<BaseClient["featurePost"]>[0],
options?: RequestOptions,
Expand Down
18 changes: 18 additions & 0 deletions src/schemas/CommunityNotificationsMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { z } from "zod/v4-mini";

/**
* Notification setting for a community.
*
* - `all_posts_and_comments`: notify on every new post and comment in the
* community.
* - `all_posts`: notify on every new post (not comments).
* - `replies_and_mentions`: only notify when the user is replied to or
* mentioned (this is the default for users who haven't customized).
* - `mute`: never notify, even for direct replies/mentions in this community.
*/
export const CommunityNotificationsMode = z.enum([
"all_posts_and_comments",
"all_posts",
"replies_and_mentions",
"mute",
]);
2 changes: 2 additions & 0 deletions src/schemas/CommunityView.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { z } from "zod/v4-mini";

import { Community } from "./Community";
import { CommunityNotificationsMode } from "./CommunityNotificationsMode";
import { SubscribedType } from "./SubscribedType";

export const CommunityView = z.object({
blocked: z.boolean(),
community: Community,
notifications: CommunityNotificationsMode,
subscribed: SubscribedType,
});
15 changes: 15 additions & 0 deletions src/schemas/PostNotificationsMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { z } from "zod/v4-mini";

/**
* Notification setting for a post.
*
* - `all_comments`: notify on every new comment on the post.
* - `replies_and_mentions`: only notify when the user is replied to or
* mentioned (this is the default for users who haven't customized).
* - `mute`: never notify, even for direct replies/mentions on this post.
*/
export const PostNotificationsMode = z.enum([
"all_comments",
"replies_and_mentions",
"mute",
]);
2 changes: 2 additions & 0 deletions src/schemas/PostView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from "zod/v4-mini";
import { Community } from "./Community";
import { Person } from "./Person";
import { Post } from "./Post";
import { PostNotificationsMode } from "./PostNotificationsMode";
import { SubscribedType } from "./SubscribedType";
import { Vote } from "./Vote";

Expand All @@ -16,6 +17,7 @@ export const PostView = z.object({
creator_is_moderator: z.boolean(),
hidden: z.boolean(),
my_vote: z.optional(Vote),
notifications: PostNotificationsMode,
post: Post,
read: z.boolean(),
saved: z.boolean(),
Expand Down
2 changes: 2 additions & 0 deletions src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./CommentView";
export * from "./Community";
export * from "./CommunityFollowerView";
export * from "./CommunityModeratorView";
export * from "./CommunityNotificationsMode";
export * from "./CommunityView";
export * from "./CommunityVisibility";
export * from "./FederatedInstances";
Expand All @@ -32,6 +33,7 @@ export * from "./PersonContentItem";
export * from "./PersonContentItem";
export * from "./PersonMention";
export * from "./Post";
export * from "./PostNotificationsMode";
export * from "./PostReport";
export * from "./PostReportView";
export * from "./PostView";
Expand Down
8 changes: 8 additions & 0 deletions src/types/EditCommunityNotifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { z } from "zod/v4-mini";

import type { CommunityNotificationsMode } from "../schemas/CommunityNotificationsMode";

export interface EditCommunityNotifications {
community_id: number;
mode: z.infer<typeof CommunityNotificationsMode>;
}
8 changes: 8 additions & 0 deletions src/types/EditPostNotifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { z } from "zod/v4-mini";

import type { PostNotificationsMode } from "../schemas/PostNotificationsMode";

export interface EditPostNotifications {
mode: z.infer<typeof PostNotificationsMode>;
post_id: number;
}
8 changes: 8 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export type CommunityFollowerView = z.infer<
export type CommunityModeratorView = z.infer<
typeof schemas.CommunityModeratorView
>;
export type CommunityNotificationsMode = z.infer<
typeof schemas.CommunityNotificationsMode
>;
export type CommunityView = z.infer<typeof schemas.CommunityView>;
export type CommunityVisibility = z.infer<typeof schemas.CommunityVisibility>;
export type FederatedInstances = z.infer<typeof schemas.FederatedInstances>;
Expand Down Expand Up @@ -75,6 +78,9 @@ export type PersonMention = z.infer<typeof schemas.PersonMention>;
export type PersonView = z.infer<typeof schemas.PersonView>;
export type PiefedErrorResponse = z.infer<typeof schemas.PiefedErrorResponse>;
export type Post = z.infer<typeof schemas.Post>;
export type PostNotificationsMode = z.infer<
typeof schemas.PostNotificationsMode
>;
export type PostReport = z.infer<typeof schemas.PostReport>;
export type PostReportView = z.infer<typeof schemas.PostReportView>;
export type PostView = z.infer<typeof schemas.PostView>;
Expand All @@ -100,7 +106,9 @@ export type * from "./CommunitySortType";
export type * from "./CreateComment";
export type * from "./CreatePost";
export type * from "./EditComment";
export type * from "./EditCommunityNotifications";
export type * from "./EditPost";
export type * from "./EditPostNotifications";
export type * from "./GetComments";
export type * from "./GetCommunity";
export type * from "./GetModlog";
Expand Down
Loading