Repository navigation
feat: media timelines - #1885
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded new profile/media GraphQL queries and validators, extended profile timeline types, implemented a profile media API + route (/2/profile/{handle}/media), added optional with_replies handling to profile statuses, updated tests/mocks, and re-enabled a runtime GraphQL response log. (50 words) Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client/API Request
participant Router as API Router
participant Provider as profileMediaAPI
participant GraphQL as GraphQL Orchestrator
participant Validator as Response Validator
participant Processor as Timeline Processor
participant Builder as Status Builder
Client->>Router: GET /2/profile/{handle}/media
Router->>Provider: profileMediaAPI(handle, count, cursor)
Provider->>Provider: resolve userId from handle
Provider->>GraphQL: execute UserMediaQuery
GraphQL-->>Provider: timeline response
Provider->>Validator: validateUserMediaTimelineResponse(response)
Validator-->>Provider: validation result
Provider->>Processor: getProfileStatusesTimelineInstructions(response)
Processor-->>Provider: TimelineInstruction[]
Provider->>Processor: processTimelineInstructions(instructions)
Processor-->>Provider: statuses + cursors
Provider->>Builder: buildAPITwitterStatus per status
Builder-->>Provider: built status objects
Provider-->>Router: { code, results[], cursor }
Router-->>Client: HTTP response (status = code) + JSON
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/providers/twitter/graphql/queries.ts (1)
610-663: Consider reusinguserTweetsFeaturesto reduce duplication.The
userMediaFeaturesobject is nearly identical touserTweetsFeatures(lines 554-592), differing only in the omission oftweet_awards_web_tipping_enabled. If this difference is intentional (captured from Twitter's actual Media tab requests), this is fine. Otherwise, consider reusing the existing feature set.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/providers/twitter/graphql/queries.ts` around lines 610 - 663, Duplicate feature flags exist between userMediaFeatures and userTweetsFeatures; either reuse the existing userTweetsFeatures or make the one intentional omission explicit. Update the UserMediaQuery construction to reference userTweetsFeatures (or a shared const like baseUserFeatures) and then override or delete the tweet_awards_web_tipping_enabled flag if needed; locate and modify the userMediaFeatures constant and the UserMediaQuery.features assignment so it reuses userTweetsFeatures (or a merged object) rather than duplicating nearly identical flags.src/providers/twitter/userStatuses.ts (1)
120-311: Consider extracting shared timeline API logic.The three new functions (
profileMediaAPI,profilePhotosAPI,profileUserVideosAPI) share significant structural similarity:
- Resolve userId from handle
- Execute GraphQL orchestrator
- Extract instructions
- Process timeline instructions
- Build statuses with error handling
- Return results with cursors
A shared helper could reduce duplication:
♻️ Example refactor sketch
const executeTimelineAPI = async ( handleOrId: ProfileHandleOrId, c: Context, config: { key: string; query: GraphQLQuery; validator: (r: unknown) => boolean; extractInstructions: (r: unknown) => TimelineInstruction[] | undefined; variables: Record<string, unknown>; } ): Promise<APISearchResults> => { const userId = handleOrId.type === 'userId' ? handleOrId.value : await getTwitterUserRestIdByScreenName(c, handleOrId.value); if (!userId) { return { code: 404, results: [], cursor: { top: null, bottom: null } }; } const results = await graphQLOrchestrator(c, [{ key: config.key, required: true, query: config.query, validator: config.validator, variables: { ...config.variables, userId, rest_id: userId } }]); // ... shared processing logic };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/providers/twitter/userStatuses.ts` around lines 120 - 311, Extract the duplicated timeline flow into a helper (e.g. executeTimelineAPI) that takes (handleOrId: ProfileHandleOrId, c: Context, config: { key, query, validator, extractInstructions, variables? }) and implements: resolving userId (reuse getTwitterUserRestIdByScreenName), calling graphQLOrchestrator with provided key/query/validator/variables, checking success and logging errors, calling the provided extractInstructions (or default getProfileStatusesTimelineInstructions / getProfilePhotoTimelineInstructions), processing the instructions with processTimelineInstructions, building statuses via buildAPITwitterStatus with the same try/catch pattern, filtering out null/FetchResults, and returning the APISearchResults with top/bottom cursors; then replace profileMediaAPI, profilePhotosAPI and profileUserVideosAPI to call executeTimelineAPI with the appropriate config (key: 'media'|'photos'|'videos', queries UserMediaQuery|ProfileUserPhotoTimelineQuery|ProfileUserVideoTimelineQuery, validators validateUserTweetsTimeline|validateProfileUserPhotoTimelineResponse|validateProfileUserVideoTimelineResponse, and extractInstructions mapping to getProfileStatusesTimelineInstructions or getProfilePhotoTimelineInstructions) so their bodies only prepare config and forward the call.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/providers/twitter/userStatuses.ts`:
- Around line 134-156: getProfileStatusesTimelineInstructions currently lacks
handling for the profile_user_media_timeline shape returned by UserMediaQuery,
which causes it to return undefined and the caller to send a 404; update
getProfileStatusesTimelineInstructions to detect and return instructions when
asProfile.data.user_result_by_rest_id.result.profile_user_media_timeline.timeline.instructions
is an array (insert this check after the existing video-path handler and before
the final return undefined) so the profile media timeline path is handled the
same way as the other timeline shapes.
In `@src/realms/api/routes/twitter.ts`:
- Line 114: The code falls back to an undocumented camelCase query param by
calling c.req.query('withReplies') when computing const withReplies =
isParamTruthy(...), so either explicitly document the alias or remove the
fallback; fix by (A) adding a documented query parameter named "withReplies" to
the route's OpenAPI/schema alongside "with_replies" (so the alias is supported)
or (B) remove the c.req.query('withReplies') fallback and only read the
documented "with_replies" param; update any validation/handlers that rely on
isParamTruthy and the withReplies constant accordingly.
---
Nitpick comments:
In `@src/providers/twitter/graphql/queries.ts`:
- Around line 610-663: Duplicate feature flags exist between userMediaFeatures
and userTweetsFeatures; either reuse the existing userTweetsFeatures or make the
one intentional omission explicit. Update the UserMediaQuery construction to
reference userTweetsFeatures (or a shared const like baseUserFeatures) and then
override or delete the tweet_awards_web_tipping_enabled flag if needed; locate
and modify the userMediaFeatures constant and the UserMediaQuery.features
assignment so it reuses userTweetsFeatures (or a merged object) rather than
duplicating nearly identical flags.
In `@src/providers/twitter/userStatuses.ts`:
- Around line 120-311: Extract the duplicated timeline flow into a helper (e.g.
executeTimelineAPI) that takes (handleOrId: ProfileHandleOrId, c: Context,
config: { key, query, validator, extractInstructions, variables? }) and
implements: resolving userId (reuse getTwitterUserRestIdByScreenName), calling
graphQLOrchestrator with provided key/query/validator/variables, checking
success and logging errors, calling the provided extractInstructions (or default
getProfileStatusesTimelineInstructions / getProfilePhotoTimelineInstructions),
processing the instructions with processTimelineInstructions, building statuses
via buildAPITwitterStatus with the same try/catch pattern, filtering out
null/FetchResults, and returning the APISearchResults with top/bottom cursors;
then replace profileMediaAPI, profilePhotosAPI and profileUserVideosAPI to call
executeTimelineAPI with the appropriate config (key: 'media'|'photos'|'videos',
queries
UserMediaQuery|ProfileUserPhotoTimelineQuery|ProfileUserVideoTimelineQuery,
validators
validateUserTweetsTimeline|validateProfileUserPhotoTimelineResponse|validateProfileUserVideoTimelineResponse,
and extractInstructions mapping to getProfileStatusesTimelineInstructions or
getProfilePhotoTimelineInstructions) so their bodies only prepare config and
forward the call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b138c1d5-58a4-478e-afbf-a0b13d8a428a
📒 Files selected for processing (12)
src/providers/twitter/graphql/queries.tssrc/providers/twitter/graphql/validators.tssrc/providers/twitter/userStatuses.tssrc/realms/api/router.tssrc/realms/api/routes.tssrc/realms/api/routes/twitter.tssrc/types/vendor/twitter.d.tstest/api.profileMedia.test.tstest/api.profilePhotos.test.tstest/api.profileVideos.test.tstest/helpers/harness.tstest/profileStatusesInstructions.test.ts
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/realms/api/routes/twitter.ts (1)
107-107:⚠️ Potential issue | 🟡 MinorUndocumented camelCase parameter fallback should be addressed.
The fallback to
c.req.query('withReplies')provides a camelCase alias that isn't documented in the OpenAPI schema. Looking atsrc/realms/api/routes.ts:28-36, theaboutAccountQuerypattern explicitly documents both snake_case and camelCase variants. Either:
- Document
withRepliesas an alias in the route schema (likeaboutAccount)- Remove the fallback if it's not intentionally supported
Option 1: Document the alias in routes.ts
cursor: z .string() .optional() .openapi({ description: 'Pagination cursor from prior response' }), with_replies: z.string().optional().openapi({ description: 'If truthy (`1`, `true`, `yes`, `on`, or empty), include replies using alternate upstream timelines' - }) + }), + withReplies: z.string().optional().openapi({ + description: 'Alias for with_replies' + })Option 2: Remove undocumented fallback
- const withReplies = isParamTruthy(query.with_replies ?? c.req.query('withReplies')); + const withReplies = isParamTruthy(query.with_replies);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/realms/api/routes/twitter.ts` at line 107, The code uses a camelCase fallback when building withReplies: "const withReplies = isParamTruthy(query.with_replies ?? c.req.query('withReplies'))" which isn't documented; either add the camelCase alias to the route schema (update the aboutAccountQuery schema to include "withReplies" alongside "with_replies") so the OpenAPI/docs match the runtime, or remove the undocumented fallback and read only query.with_replies (i.e., replace the nullish-coalescing fallback so withReplies = isParamTruthy(query.with_replies)); update references to isParamTruthy, withReplies, and aboutAccountQuery accordingly.
🧹 Nitpick comments (1)
src/providers/twitter/userStatuses.ts (1)
116-179: Consider extracting shared logic to reduce duplication.
profileMediaAPIandprofileStatusesAPIshare nearly identical patterns for:
- User ID resolution (lines 122-128 vs 29-35)
- Error handling in
buildAPITwitterStatusmapping (lines 158-169 vs 93-104)- Response construction (lines 171-178 vs 106-113)
This could be refactored into a shared helper, but given the minor differences in orchestrator configuration, deferring is acceptable.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/providers/twitter/userStatuses.ts` around lines 116 - 179, profileMediaAPI and profileStatusesAPI duplicate user ID resolution, status-building error handling, and response construction; extract three helpers: 1) a userId resolver that wraps getTwitterUserRestIdByScreenName (used by profileMediaAPI/profileStatusesAPI) to return the 404 result shape when missing, 2) a safeBuildStatuses utility that maps statuses -> buildAPITwitterStatus with try/catch and returns typed APITwitterStatus[] (filtering out nulls/FetchResults), and 3) a small response-builder that assembles { code, results, cursor } given builtStatuses and cursors from processTimelineInstructions/getProfileStatusesTimelineInstructions; replace the duplicated blocks in profileMediaAPI and profileStatusesAPI to call these helpers to keep orchestrator-specific logic intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/realms/api/routes/twitter.ts`:
- Line 107: The code uses a camelCase fallback when building withReplies: "const
withReplies = isParamTruthy(query.with_replies ?? c.req.query('withReplies'))"
which isn't documented; either add the camelCase alias to the route schema
(update the aboutAccountQuery schema to include "withReplies" alongside
"with_replies") so the OpenAPI/docs match the runtime, or remove the
undocumented fallback and read only query.with_replies (i.e., replace the
nullish-coalescing fallback so withReplies = isParamTruthy(query.with_replies));
update references to isParamTruthy, withReplies, and aboutAccountQuery
accordingly.
---
Nitpick comments:
In `@src/providers/twitter/userStatuses.ts`:
- Around line 116-179: profileMediaAPI and profileStatusesAPI duplicate user ID
resolution, status-building error handling, and response construction; extract
three helpers: 1) a userId resolver that wraps getTwitterUserRestIdByScreenName
(used by profileMediaAPI/profileStatusesAPI) to return the 404 result shape when
missing, 2) a safeBuildStatuses utility that maps statuses ->
buildAPITwitterStatus with try/catch and returns typed APITwitterStatus[]
(filtering out nulls/FetchResults), and 3) a small response-builder that
assembles { code, results, cursor } given builtStatuses and cursors from
processTimelineInstructions/getProfileStatusesTimelineInstructions; replace the
duplicated blocks in profileMediaAPI and profileStatusesAPI to call these
helpers to keep orchestrator-specific logic intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 7a81c0fa-dd1e-49ca-ba7f-073038969b51
📒 Files selected for processing (10)
src/providers/twitter/fetch.tssrc/providers/twitter/graphql/queries.tssrc/providers/twitter/graphql/validators.tssrc/providers/twitter/userStatuses.tssrc/realms/api/router.tssrc/realms/api/routes.tssrc/realms/api/routes/twitter.tssrc/types/vendor/twitter.d.tstest/helpers/harness.tstest/profileStatusesInstructions.test.ts
✅ Files skipped from review due to trivial changes (4)
- src/providers/twitter/fetch.ts
- src/realms/api/router.ts
- test/helpers/harness.ts
- test/profileStatusesInstructions.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/types/vendor/twitter.d.ts
- src/providers/twitter/graphql/validators.ts
- src/providers/twitter/graphql/queries.ts
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/realms/api/routes/twitter.ts (1)
124-124:⚠️ Potential issue | 🟡 MinorUndocumented camelCase query alias is still accepted.
c.req.query('withReplies')is still used as a fallback, but onlywith_repliesis documented in the query schema. Either documentwithRepliesexplicitly or remove the fallback to avoid silent API surface drift.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/realms/api/routes/twitter.ts` at line 124, The code silently accepts an undocumented camelCase query alias; update the handling for the with_replies query parameter by removing the fallback to the camelCase form to avoid API surface drift: change the initialization of withReplies (the const withReplies = isParamTruthy(...)) to only read the documented query key (with_replies) via c.req.query('with_replies') (or the existing query object), and remove the c.req.query('withReplies') fallback, or alternatively add explicit documentation/validation for the camelCase alias in your query schema if you intend to support it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/realms/api/routes/twitter.ts`:
- Line 124: The code silently accepts an undocumented camelCase query alias;
update the handling for the with_replies query parameter by removing the
fallback to the camelCase form to avoid API surface drift: change the
initialization of withReplies (the const withReplies = isParamTruthy(...)) to
only read the documented query key (with_replies) via
c.req.query('with_replies') (or the existing query object), and remove the
c.req.query('withReplies') fallback, or alternatively add explicit
documentation/validation for the camelCase alias in your query schema if you
intend to support it.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8bbaec78-47e3-4efe-acfc-61040d092080
📒 Files selected for processing (3)
src/realms/api/router.tssrc/realms/api/routes.tssrc/realms/api/routes/twitter.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/realms/api/router.ts
- src/realms/api/routes.ts
Summary by CodeRabbit
New Features
Improvements
Tests