diff --git a/src/providers/twitter/conversation.ts b/src/providers/twitter/conversation.ts index 45f2087..bda9474 100644 --- a/src/providers/twitter/conversation.ts +++ b/src/providers/twitter/conversation.ts @@ -237,12 +237,16 @@ const findNextStatus = (id: string, bucket: GraphQLProcessBucket): number => { }; const findPreviousStatus = (id: string, bucket: GraphQLProcessBucket): number => { - const status = bucket.statuses.find(status => (status.rest_id ?? status.legacy?.id_str) === id); + const status = bucket.allStatuses.find(status => (status.rest_id ?? status.legacy?.id_str) === id); if (!status) { console.log('uhhh, we could not even find that tweet, dunno how that happened'); return -1; } - return bucket.statuses.findIndex( + if ((status.rest_id ?? status.legacy?.id_str) === status.legacy?.in_reply_to_status_id_str) { + console.log('Tweet does not have a parent') + return 0; + } + return bucket.allStatuses.findIndex( _status => (_status.rest_id ?? _status.legacy?.id_str) === status.legacy?.in_reply_to_status_id_str ); @@ -357,6 +361,7 @@ export const constructTwitterThread = async ( } const threadStatuses = [originalStatus]; + bucket.allStatuses = bucket.statuses; bucket.statuses = filterBucketStatuses(bucket.statuses, originalStatus); let currentId = id; @@ -432,7 +437,7 @@ export const constructTwitterThread = async ( while (findPreviousStatus(currentId, bucket) !== -1) { const index = findPreviousStatus(currentId, bucket); - const status = bucket.statuses[index]; + const status = bucket.allStatuses[index]; const newCurrentId = status.rest_id ?? status.legacy?.id_str; console.log( diff --git a/src/types/vendor/twitter.d.ts b/src/types/vendor/twitter.d.ts index b2bcd97..16b35b0 100644 --- a/src/types/vendor/twitter.d.ts +++ b/src/types/vendor/twitter.d.ts @@ -572,5 +572,6 @@ type TweetStub = { interface GraphQLProcessBucket { statuses: GraphQLTwitterStatus[]; + allStatuses: GraphQLTwitterStatus[]; cursors: GraphQLTimelineCursor[]; }