fix: force fresh sweetistics thread fetch
This commit is contained in:
@@ -380,10 +380,15 @@ export class SweetisticsClient {
|
|||||||
|
|
||||||
private async fetchConversation(
|
private async fetchConversation(
|
||||||
tweetId: string,
|
tweetId: string,
|
||||||
options: { excludeRoot: boolean },
|
options: { excludeRoot: boolean; force?: boolean } = { excludeRoot: false, force: true },
|
||||||
): Promise<SweetisticsTimelineResult> {
|
): Promise<SweetisticsTimelineResult> {
|
||||||
const url = new URL(`${this.baseUrl}/api/trpc/tweets.getConversation`);
|
const url = new URL(`${this.baseUrl}/api/trpc/tweets.getConversation`);
|
||||||
url.searchParams.set('input', JSON.stringify({ tweetId }));
|
const input: Record<string, unknown> = { 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;
|
let response: Response;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ describe('SweetisticsClient', () => {
|
|||||||
expect(result.tweets?.[0].id).toBe('2');
|
expect(result.tweets?.[0].id).toBe('2');
|
||||||
const [url, init] = fetchMock.mock.calls[0];
|
const [url, init] = fetchMock.mock.calls[0];
|
||||||
expect(url).toContain('/api/trpc/tweets.getConversation');
|
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' });
|
expect((init as RequestInit).headers).toMatchObject({ authorization: 'Bearer sweet-test' });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -165,6 +167,8 @@ describe('SweetisticsClient', () => {
|
|||||||
expect(result.tweets?.length).toBe(2);
|
expect(result.tweets?.length).toBe(2);
|
||||||
const [url, init] = fetchMock.mock.calls[0];
|
const [url, init] = fetchMock.mock.calls[0];
|
||||||
expect(url).toContain('/api/trpc/tweets.getConversation');
|
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' });
|
expect((init as RequestInit).headers).toMatchObject({ authorization: 'Bearer sweet-test' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user