-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated thread implementation to work with posts instead of activities
refs [AP-721](https://linear.app/ghost/issue/AP-721/update-getactivitythread-to-work-with-posts-instead-of-activities) Updated thread implementation to work with posts instead of activities as part of the posts migration
- Loading branch information
Showing
6 changed files
with
283 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { AccountService } from 'account/account.service'; | ||
import type { AppContext } from '../../app'; | ||
import type { KnexPostRepository } from '../../post/post.repository.knex'; | ||
import { postToDTO } from './helpers/post'; | ||
|
||
/** | ||
* Create a handler for a request for a thread | ||
* | ||
* @param postRepository Post repository instance | ||
*/ | ||
export function createGetThreadHandler( | ||
postRepository: KnexPostRepository, | ||
accountService: AccountService, | ||
) { | ||
/** | ||
* Handle a request for a thread | ||
* | ||
* @param ctx App context instance | ||
*/ | ||
return async function handleGetThread(ctx: AppContext) { | ||
const paramPostApId = ctx.req.param('post_ap_id'); | ||
const postApId = paramPostApId ? decodeURIComponent(paramPostApId) : ''; | ||
|
||
if (!postApId) { | ||
return new Response(null, { status: 400 }); | ||
} | ||
|
||
const account = await accountService.getDefaultAccountForSite( | ||
ctx.get('site'), | ||
); | ||
|
||
const posts = ( | ||
await postRepository.getThreadByApId(postApId, account.id) | ||
).map(({ post, likedByAccount, repostedByAccount }) => { | ||
return postToDTO(post, { | ||
likedByMe: likedByAccount, | ||
repostedByMe: repostedByAccount, | ||
repostedBy: null, | ||
}); | ||
}); | ||
|
||
return new Response( | ||
JSON.stringify({ | ||
posts, | ||
}), | ||
{ | ||
status: 200, | ||
}, | ||
); | ||
}; | ||
} |
Oops, something went wrong.