refactor post model

This commit is contained in:
john 2025-08-10 18:08:17 +02:00
parent 62f9de9546
commit 30025b4044
8 changed files with 373 additions and 151 deletions

View file

@ -2,10 +2,10 @@ import { Temporal } from '@js-temporal/polyfill'
import { components } from '../../api/schema.ts'
import { immerable } from 'immer'
export interface EmojiReaction {
export interface PostReaction {
emoji: string
count: number
didReact: boolean
authorName: string
reactedOn: Temporal.Instant
}
export class Post {
@ -16,7 +16,7 @@ export class Post {
public readonly media: PostMedia[]
public readonly createdAt: Temporal.Instant
public readonly authorName: string
public readonly reactions: EmojiReaction[]
public readonly reactions: PostReaction[]
public readonly possibleReactions: string[]
constructor(
@ -25,7 +25,7 @@ export class Post {
media: PostMedia[],
createdAt: string | Temporal.Instant,
authorName: string,
reactions: EmojiReaction[] = [],
reactions: PostReaction[] = [],
possibleReactions: string[] = [],
) {
this.postId = postId
@ -44,11 +44,7 @@ export class Post {
dto.media.map((m) => new PostMediaImpl(new URL(m.url), m.width, m.height)),
Temporal.Instant.from(dto.createdAt),
dto.author.username,
dto.reactions.map((r) => ({
emoji: r.emoji,
count: r.count,
didReact: r.didReact,
})),
dto.reactions.map((r) => ({ ...r, reactedOn: Temporal.Instant.from(r.reactedOn) })),
dto.possibleReactions,
)
}