Skip to content

Commit 9ee78c5

Browse files
Added reply parent context on profile post DTOs.
Internal outbox rows join the parent author so the admin UI can label replies; remote replies stay id-only with a null author. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f8ca257 commit 9ee78c5

12 files changed

Lines changed: 503 additions & 13 deletions

‎src/http/api/__snapshots__/feed.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"excerpt": "Excerpt 789",
3131
"featureImageUrl": "https://example.com/images/post-789.png",
3232
"id": "https://example.com/.activitypub/post/post-789",
33+
"inReplyTo": null,
3334
"likeCount": 1,
3435
"likedByMe": false,
3536
"publishedAt": "2025-02-24T16:40:00.000Z",
@@ -60,6 +61,7 @@
6061
"excerpt": "Excerpt 790",
6162
"featureImageUrl": "https://example.com/images/post-790.png",
6263
"id": "https://example.com/.activitypub/post/post-790",
64+
"inReplyTo": null,
6365
"likeCount": 0,
6466
"likedByMe": false,
6567
"publishedAt": "2025-02-24T16:40:00.000Z",

‎src/http/api/__snapshots__/post-authored-by-me.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"excerpt": "Test Post 789 Excerpt",
1515
"featureImageUrl": "https://example.com/images/post-789.jpg",
1616
"id": "http://example.com/.ghost/activitypub/article/259e92cb-5ac2-4d62-910f-ddea29b2cf55",
17+
"inReplyTo": null,
1718
"likeCount": 0,
1819
"likedByMe": false,
1920
"metadata": {

‎src/http/api/__snapshots__/post-liked-by-me.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"excerpt": "Test Post 789 Excerpt",
1515
"featureImageUrl": "https://example.com/images/post-789.jpg",
1616
"id": "http://example.com/.ghost/activitypub/article/259e92cb-5ac2-4d62-910f-ddea29b2cf55",
17+
"inReplyTo": null,
1718
"likeCount": 0,
1819
"likedByMe": true,
1920
"metadata": {

‎src/http/api/__snapshots__/post-reposted-by-me.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"excerpt": "Test Post 789 Excerpt",
1515
"featureImageUrl": "https://example.com/images/post-789.jpg",
1616
"id": "http://example.com/.ghost/activitypub/article/259e92cb-5ac2-4d62-910f-ddea29b2cf55",
17+
"inReplyTo": null,
1718
"likeCount": 0,
1819
"likedByMe": false,
1920
"metadata": {

‎src/http/api/__snapshots__/post.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"excerpt": "Test Post 789 Excerpt",
1515
"featureImageUrl": "https://example.com/images/post-789.jpg",
1616
"id": "http://example.com/.ghost/activitypub/article/259e92cb-5ac2-4d62-910f-ddea29b2cf55",
17+
"inReplyTo": null,
1718
"likeCount": 0,
1819
"likedByMe": false,
1920
"metadata": {

‎src/http/api/feed.controller.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
} from '@/feed/feed.service';
1212
import { normalizePlainText } from '@/helpers/html';
1313
import { requireParam } from '@/http/api/helpers/request';
14+
import type { PostDTO } from '@/http/api/types';
1415
import { APIRoute, RequireRoles } from '@/http/decorators/route.decorator';
1516
import { GhostRole } from '@/http/middleware/role-guard';
1617
import type { PostInteractionCountsService } from '@/post/post-interaction-counts.service';
@@ -154,8 +155,8 @@ export class FeedController {
154155
private mapFeedResultsToPostDTO(
155156
results: GetFeedDataResultRow[],
156157
myAccount: Account,
157-
) {
158-
return results.map((result) => {
158+
): PostDTO[] {
159+
return results.map((result): PostDTO => {
159160
return {
160161
id: result.post_ap_id,
161162
type: result.post_type,
@@ -211,6 +212,7 @@ export class FeedController {
211212
followedByMe: result.reposter_followed_by_user === 1,
212213
}
213214
: null,
215+
inReplyTo: null,
214216
};
215217
});
216218
}

‎src/http/api/helpers/post.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function postToDTO(
7070
repostedBy: meta.repostedBy
7171
? accountToAuthorDTO(meta.repostedBy, meta.followingReposter)
7272
: null,
73+
inReplyTo: null,
7374
metadata: post.metadata ?? {
7475
ghostAuthors: [],
7576
},

‎src/http/api/types.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ export interface PostDTO {
219219
* Account that reposted the post
220220
*/
221221
repostedBy: AuthorDTO | null;
222+
/** Parent reply context; `{ id, author: null }` when the parent author is unknown. */
223+
inReplyTo: {
224+
id: string;
225+
author: Pick<AuthorDTO, 'name' | 'handle' | 'url'> | null;
226+
} | null;
222227
/**
223228
* Metadata of the post, containing e.g. information about ghost authors
224229
*/

‎src/http/api/views/account.posts.view.integration.test.ts‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,92 @@ describe('AccountPostsView', () => {
304304
}
305305
});
306306

307+
describe('inReplyTo', () => {
308+
async function getOutbox(subject: Account) {
309+
const result = await viewer.getPostsFromOutbox(
310+
subject,
311+
contextAccount.id,
312+
10,
313+
null,
314+
true,
315+
);
316+
expect(isError(result)).toBe(false);
317+
return getValue(result as [null, AccountPosts]).results;
318+
}
319+
320+
it('names the parent author when replying to another account', async () => {
321+
const [parentAuthor] =
322+
await fixtureManager.createInternalAccount();
323+
const parent = await fixtureManager.createPost(parentAuthor);
324+
const reply = await fixtureManager.createReply(account, parent);
325+
326+
const [parentAsListed] = await getOutbox(parentAuthor);
327+
const results = await getOutbox(account);
328+
329+
expect(results).toHaveLength(1);
330+
expect(results[0].id).toBe(reply.apId.href);
331+
expect(results[0].inReplyTo).toEqual({
332+
id: parent.apId.href,
333+
author: {
334+
name: parentAuthor.name,
335+
handle: parentAsListed.author.handle,
336+
url: parentAuthor.url.href,
337+
},
338+
});
339+
expect(results[0].inReplyTo?.author?.handle).not.toBe(
340+
results[0].author.handle,
341+
);
342+
});
343+
344+
it('gives the same handle for author and parent when replying to self', async () => {
345+
const parent = await fixtureManager.createPost(account);
346+
await fixtureManager.createReply(account, parent);
347+
348+
const results = await getOutbox(account);
349+
350+
expect(results).toHaveLength(2);
351+
const [reply, original] = results;
352+
expect(reply.inReplyTo).toMatchObject({
353+
id: parent.apId.href,
354+
author: { handle: reply.author.handle },
355+
});
356+
expect(reply.inReplyTo?.author?.handle).toBe(
357+
original.author.handle,
358+
);
359+
});
360+
361+
it('returns null for posts that are not replies', async () => {
362+
await fixtureManager.createPost(account);
363+
364+
const results = await getOutbox(account);
365+
366+
expect(results).toHaveLength(1);
367+
expect(results[0].inReplyTo).toBeNull();
368+
});
369+
370+
it('still names the parent author when the parent is soft-deleted', async () => {
371+
const [parentAuthor] =
372+
await fixtureManager.createInternalAccount();
373+
const parent = await fixtureManager.createPost(parentAuthor);
374+
await fixtureManager.createReply(account, parent);
375+
376+
await db('posts')
377+
.where({ id: parent.id })
378+
.update({ deleted_at: db.fn.now() });
379+
380+
const results = await getOutbox(account);
381+
382+
expect(results).toHaveLength(1);
383+
expect(results[0].inReplyTo).toMatchObject({
384+
id: parent.apId.href,
385+
author: {
386+
name: parentAuthor.name,
387+
url: parentAuthor.url.href,
388+
},
389+
});
390+
});
391+
});
392+
307393
it('sets likedByMe and repostedByMe correctly', async () => {
308394
const post = await fixtureManager.createPost(account);
309395
await postRepository.save(post);

0 commit comments

Comments
 (0)