diff --git a/src/lib/sweetistics-client.ts b/src/lib/sweetistics-client.ts index 3096aea..8170c8b 100644 --- a/src/lib/sweetistics-client.ts +++ b/src/lib/sweetistics-client.ts @@ -380,10 +380,15 @@ export class SweetisticsClient { private async fetchConversation( tweetId: string, - options: { excludeRoot: boolean }, + options: { excludeRoot: boolean; force?: boolean } = { excludeRoot: false, force: true }, ): Promise { const url = new URL(`${this.baseUrl}/api/trpc/tweets.getConversation`); - url.searchParams.set('input', JSON.stringify({ tweetId })); + const input: Record = { tweetId }; + // Always request a fresh conversation to avoid cached Sweetistics data unless explicitly disabled + if (options.force ?? true) { + input.force = 'true'; + } + url.searchParams.set('input', JSON.stringify(input)); let response: Response; try { diff --git a/tests/sweetistics-client.test.ts b/tests/sweetistics-client.test.ts index 539d5e4..ef9eb91 100644 --- a/tests/sweetistics-client.test.ts +++ b/tests/sweetistics-client.test.ts @@ -137,6 +137,8 @@ describe('SweetisticsClient', () => { expect(result.tweets?.[0].id).toBe('2'); const [url, init] = fetchMock.mock.calls[0]; expect(url).toContain('/api/trpc/tweets.getConversation'); + const params = new URL(url as string).searchParams.get('input'); + expect(params).toBe(JSON.stringify({ tweetId: '1', force: 'true' })); expect((init as RequestInit).headers).toMatchObject({ authorization: 'Bearer sweet-test' }); }); @@ -165,6 +167,8 @@ describe('SweetisticsClient', () => { expect(result.tweets?.length).toBe(2); const [url, init] = fetchMock.mock.calls[0]; expect(url).toContain('/api/trpc/tweets.getConversation'); + const params = new URL(url as string).searchParams.get('input'); + expect(params).toBe(JSON.stringify({ tweetId: '1', force: 'true' })); expect((init as RequestInit).headers).toMatchObject({ authorization: 'Bearer sweet-test' }); });