Skip to content

Commit f4442d5

Browse files
authored
feat: post tags (Lemmy v1 + PieFed) (#40)
Surface per-post tags on `PostView.tags` as a portable `PostTag[]` shape (`{ name, display_name?, color? }`) so consumers can render them uniformly across backends. - Lemmy v1: maps each `CommunityTag` on `PostView.tags`. `color` is the palette slot (e.g. `"color03"`). - PieFed: maps `PostView.flair_list[]` (CommunityFlair). `color` is the hex `background_color` (e.g. `"#a91b9c"`). - Lemmy v0: `tags: []`. `color` is opaque to threadiverse — consumers either render it directly (hex) or resolve it from a palette (Lemmy v1). The minimal shape skips v1-specific housekeeping (`id`, `ap_id`, `published_at`, `deleted`, `community_id`) since they don't have PieFed analogs and aren't useful for view-only rendering; mutation APIs can grow their own richer types later.
1 parent 04ccc56 commit f4442d5

6 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/providers/lemmyv0/compat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ export function toPostView(v: LemmyV0.PostView): types.PostView {
636636
read: v.read,
637637
saved: v.saved,
638638
subscribed: v.subscribed,
639+
tags: [],
639640
unread_comments: v.unread_comments,
640641
};
641642
}

src/providers/piefed/compat.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ export function toPostView(
255255
read: v.read,
256256
saved: v.saved,
257257
subscribed: toSubscribedType(v.subscribed),
258+
tags: (v.flair_list ?? []).map((f) => ({
259+
color: f.background_color,
260+
name: f.flair_title,
261+
})),
258262
unread_comments: v.counts.comments,
259263
};
260264
}

src/schemas/PostTag.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { z } from "zod/v4-mini";
2+
3+
/**
4+
* A tag attached to a post.
5+
*
6+
* - Lemmy v1: maps from `CommunityTag` (mod-curated, palette color slot like
7+
* `"color03"`).
8+
* - PieFed: maps from `CommunityFlair` applied to the post (hex `color`
9+
* like `"#a91b9c"`).
10+
* - Lemmy v0: not supported (empty array).
11+
*
12+
* `color` is opaque to threadiverse — consumers either render it directly
13+
* (hex) or look it up in a palette (Lemmy v1 slot keys).
14+
*/
15+
export const PostTag = z.object({
16+
color: z.optional(z.string()),
17+
display_name: z.optional(z.string()),
18+
name: z.string(),
19+
});

src/schemas/PostView.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Community } from "./Community";
44
import { Person } from "./Person";
55
import { Post } from "./Post";
66
import { PostNotificationsMode } from "./PostNotificationsMode";
7+
import { PostTag } from "./PostTag";
78
import { SubscribedType } from "./SubscribedType";
89
import { Vote } from "./Vote";
910

@@ -22,5 +23,6 @@ export const PostView = z.object({
2223
read: z.boolean(),
2324
saved: z.boolean(),
2425
subscribed: SubscribedType,
26+
tags: z.array(PostTag),
2527
unread_comments: z.number(),
2628
});

src/schemas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export * from "./Post";
3636
export * from "./PostNotificationsMode";
3737
export * from "./PostReport";
3838
export * from "./PostReportView";
39+
export * from "./PostTag";
3940
export * from "./PostView";
4041
export * from "./PrivateMessage";
4142
export * from "./PrivateMessageView";

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export type PostNotificationsMode = z.infer<
8383
>;
8484
export type PostReport = z.infer<typeof schemas.PostReport>;
8585
export type PostReportView = z.infer<typeof schemas.PostReportView>;
86+
export type PostTag = z.infer<typeof schemas.PostTag>;
8687
export type PostView = z.infer<typeof schemas.PostView>;
8788
export type PrivateMessage = z.infer<typeof schemas.PrivateMessage>;
8889
export type PrivateMessageView = z.infer<typeof schemas.PrivateMessageView>;

0 commit comments

Comments
 (0)