diff --git a/package.json b/package.json index 05ecfbde4..e7ec5b3e2 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,7 @@ "@bsky.app/tapper": "^0.6.1", "@bsky.app/video": "0.3.6", "@bsky.app/video-compressor": "0.2.0", - "@bsky/sdk": "1.1.0", + "@bsky/sdk": "1.1.2", "@emoji-mart/data": "^1.2.1", "@emoji-mart/react": "^1.1.1", "@expo/html-elements": "^0.12.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b93d18816..1800d4e69 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -294,8 +294,8 @@ importers: specifier: 0.2.0 version: 0.2.0(expo@57.0.24)(react-native@0.86.3(patch_hash=b98fd903a666d35370a478712d555fc967023b6b40a07efe51e90adc04da15d9)(@babel/core@7.29.0(supports-color@8.1.1))(@react-native/jest-preset@0.86.3(@babel/core@7.29.0(supports-color@8.1.1))(react@19.2.3)(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.0(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1))(react@19.2.3) '@bsky/sdk': - specifier: 1.1.0 - version: 1.1.0(@atproto/lex@0.3.8) + specifier: 1.1.2 + version: 1.1.2(@atproto/lex@0.3.8) '@emoji-mart/data': specifier: ^1.2.1 version: 1.2.1 @@ -1750,8 +1750,8 @@ packages: react: '*' react-native: '*' - '@bsky/sdk@1.1.0': - resolution: {integrity: sha512-6ZSrhNa6KC0arcimBG79Otk+FGZ15Br1YaEeatncbJYfWXGsw9l9nPjZ38IVpSW7UqQ/uhZ+WSQGnVUAdekzaw==} + '@bsky/sdk@1.1.2': + resolution: {integrity: sha512-wMZXVdxnSHViyVrqm+eOpJLZAwfuWLX8gvuCEyV++4k/E/gp9inxQevzuNyCFZv/XJAZ4xRh1WXN7kymF4UMXA==} engines: {node: '>=22.12.0'} peerDependencies: '@atproto/lex': ^0.3.0 @@ -10914,7 +10914,7 @@ snapshots: react: 19.2.3 react-native: 0.86.3(patch_hash=b98fd903a666d35370a478712d555fc967023b6b40a07efe51e90adc04da15d9)(@babel/core@7.29.0(supports-color@8.1.1))(@react-native/jest-preset@0.86.3(@babel/core@7.29.0(supports-color@8.1.1))(react@19.2.3)(supports-color@8.1.1))(@react-native/metro-config@0.86.3(@babel/core@7.29.0(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.3)(supports-color@8.1.1) - '@bsky/sdk@1.1.0(@atproto/lex@0.3.8)': + '@bsky/sdk@1.1.2(@atproto/lex@0.3.8)': dependencies: '@atproto-labs/handle-resolver': 0.4.8 '@atproto/lex': 0.3.8 diff --git a/src/lib/api/feed/__tests__/utils.test.ts b/src/lib/api/feed/__tests__/utils.test.ts new file mode 100644 index 000000000..7863104ea --- /dev/null +++ b/src/lib/api/feed/__tests__/utils.test.ts @@ -0,0 +1,50 @@ +import {describe, expect, it, jest} from '@jest/globals' + +import {type UsePreferencesQueryResponse} from '#/state/queries/preferences' + +jest.mock('#/env', () => ({IS_WEB: false})) + +import {aggregateUserInterests, createBskyTopicsHeader} from '../utils' + +function preferences( + interests: Pick< + UsePreferencesQueryResponse['interests'], + 'tags' | 'updatedAt' + >, +) { + return {interests} as UsePreferencesQueryResponse +} + +describe('aggregateUserInterests', () => { + it('appends the update timestamp after a semicolon', () => { + expect( + createBskyTopicsHeader( + aggregateUserInterests( + preferences({ + tags: ['animals', 'music'], + updatedAt: '2026-09-03T17:00:00.000Z', + }), + ), + ), + ).toEqual({ + 'x-atproto-bsky-topics': 'animals,music;2026-09-03T17:00:00.000Z', + }) + }) + + it('supports interests created before update timestamps were recorded', () => { + expect(aggregateUserInterests(preferences({tags: ['animals']}))).toBe( + 'animals', + ) + }) + + it('passes the timestamp when the user has no selected interests', () => { + expect( + aggregateUserInterests( + preferences({ + tags: [], + updatedAt: '2026-09-03T17:00:00.000Z', + }), + ), + ).toBe(';2026-09-03T17:00:00.000Z') + }) +}) diff --git a/src/lib/api/feed/utils.ts b/src/lib/api/feed/utils.ts index b6ef738fc..8cca3d571 100644 --- a/src/lib/api/feed/utils.ts +++ b/src/lib/api/feed/utils.ts @@ -12,14 +12,18 @@ if (IS_WEB && typeof window !== 'undefined') { export function createBskyTopicsHeader(userInterests?: string) { return { - 'X-Bsky-Topics': debugTopics || userInterests || '', + 'x-atproto-bsky-topics': debugTopics || userInterests || '', } } export function aggregateUserInterests( preferences?: UsePreferencesQueryResponse, ) { - return preferences?.interests?.tags?.join(',') || '' + const tags = preferences?.interests.tags ?? [] + const updatedAt = preferences?.interests.updatedAt + + const interests = tags.join(',') + return updatedAt ? `${interests};${updatedAt}` : interests } export function isBlueskyOwnedFeed(feedUri: string) { diff --git a/src/screens/Settings/InterestsSettings.tsx b/src/screens/Settings/InterestsSettings.tsx index 84589d748..be964e791 100644 --- a/src/screens/Settings/InterestsSettings.tsx +++ b/src/screens/Settings/InterestsSettings.tsx @@ -1,5 +1,6 @@ import {useMemo, useState} from 'react' import {type TextStyle, View, type ViewStyle} from 'react-native' +import {currentDatetimeString} from '@atproto/syntax' import {setInterestsPref} from '@bsky/sdk' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' @@ -112,12 +113,23 @@ function Inner({ try { await pdsClient.call(setInterestsPref, {tags: interests}) + /* + * The SDK timestamps the preference during the request, so this local + * timestamp may differ slightly from the persisted value. + */ + const updatedAt = currentDatetimeString() qc.setQueriesData( {queryKey: preferencesQueryKey}, (old?: UsePreferencesQueryResponse) => { if (!old) return old - old.interests.tags = interests - return old + return { + ...old, + interests: { + ...old.interests, + tags: interests, + updatedAt, + }, + } }, ) await Promise.all([