diff --git a/src/routes/replies.ts b/src/routes/replies.ts index 5d474e6..57e5629 100644 --- a/src/routes/replies.ts +++ b/src/routes/replies.ts @@ -108,7 +108,7 @@ function serializeReply(row: typeof replies.$inferSelect) { const placeholderContent = row.isModDeleted ? '[Removed by moderator]' : row.isAuthorDeleted - ? '' + ? '[Deleted by author]' : row.content return { diff --git a/src/routes/topics.ts b/src/routes/topics.ts index 98faa13..aa031ba 100644 --- a/src/routes/topics.ts +++ b/src/routes/topics.ts @@ -100,13 +100,19 @@ const topicJsonSchema = { * @param categoryMaturityRating - The maturity rating inherited from the topic's category. */ function serializeTopic(row: typeof topics.$inferSelect, categoryMaturityRating: string = 'safe') { + const isDeleted = row.isAuthorDeleted || row.isModDeleted + const placeholderTitle = row.isModDeleted + ? '[Removed by moderator]' + : row.isAuthorDeleted + ? '[Deleted by author]' + : row.title return { uri: row.uri, rkey: row.rkey, authorDid: row.authorDid, - title: row.isAuthorDeleted ? '[Deleted by author]' : row.title, - content: row.isAuthorDeleted ? '' : row.content, - contentFormat: row.isAuthorDeleted ? null : (row.contentFormat ?? null), + title: placeholderTitle, + content: isDeleted ? '' : row.content, + contentFormat: isDeleted ? null : (row.contentFormat ?? null), category: row.category, tags: row.tags ?? null, labels: row.labels ?? null, @@ -115,6 +121,7 @@ function serializeTopic(row: typeof topics.$inferSelect, categoryMaturityRating: replyCount: row.replyCount, reactionCount: row.reactionCount, isAuthorDeleted: row.isAuthorDeleted, + isModDeleted: row.isModDeleted, categoryMaturityRating, lastActivityAt: row.lastActivityAt.toISOString(), createdAt: row.createdAt.toISOString(), diff --git a/tests/unit/routes/replies.test.ts b/tests/unit/routes/replies.test.ts index 2f17709..9770f28 100644 --- a/tests/unit/routes/replies.test.ts +++ b/tests/unit/routes/replies.test.ts @@ -2090,7 +2090,7 @@ describe('reply routes', () => { resetAllDbMocks() }) - it('returns empty content for author-deleted replies', async () => { + it('returns placeholder content for author-deleted replies', async () => { selectChain.where.mockResolvedValueOnce([sampleTopicRow()]) const authorDeletedReply = sampleReplyRow({ @@ -2111,8 +2111,8 @@ describe('reply routes', () => { replies: Array<{ content: string; contentFormat: string | null }> }>() expect(body.replies).toHaveLength(1) - // Author-deleted replies return empty content - expect(body.replies[0]?.content).toBe('') + // Author-deleted replies return placeholder content + expect(body.replies[0]?.content).toBe('[Deleted by author]') expect(body.replies[0]?.contentFormat).toBeNull() })