Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Session] Convert account to session data explicitly (#4446)

* Extract a variable

* Extract sessionAccountToSession

* Convert account to session data on assignment

authored by

dan and committed by
GitHub
7ddbc392 51594952

+24 -17
+21 -15
src/state/session/agent.ts
··· 38 38 } 39 39 const gates = tryFetchGates(storedAccount.did, 'prefer-low-latency') 40 40 const moderation = configureModerationForAccount(agent, storedAccount) 41 - const prevSession: AtpSessionData = { 42 - // Sorted in the same property order as when returned by BskyAgent (alphabetical). 43 - accessJwt: storedAccount.accessJwt ?? '', 44 - did: storedAccount.did, 45 - email: storedAccount.email, 46 - emailAuthFactor: storedAccount.emailAuthFactor, 47 - emailConfirmed: storedAccount.emailConfirmed, 48 - handle: storedAccount.handle, 49 - refreshJwt: storedAccount.refreshJwt ?? '', 50 - /** 51 - * @see https://github.com/bluesky-social/atproto/blob/c5d36d5ba2a2c2a5c4f366a5621c06a5608e361e/packages/api/src/agent.ts#L188 52 - */ 53 - active: storedAccount.active ?? true, 54 - status: storedAccount.status, 55 - } 41 + const prevSession: AtpSessionData = sessionAccountToSession(storedAccount) 56 42 if (isSessionExpired(storedAccount)) { 57 43 await networkRetry(1, () => agent.resumeSession(prevSession)) 58 44 } else { ··· 253 239 pdsUrl: agent.pdsUrl?.toString(), 254 240 } 255 241 } 242 + 243 + export function sessionAccountToSession( 244 + account: SessionAccount, 245 + ): AtpSessionData { 246 + return { 247 + // Sorted in the same property order as when returned by BskyAgent (alphabetical). 248 + accessJwt: account.accessJwt ?? '', 249 + did: account.did, 250 + email: account.email, 251 + emailAuthFactor: account.emailAuthFactor, 252 + emailConfirmed: account.emailConfirmed, 253 + handle: account.handle, 254 + refreshJwt: account.refreshJwt ?? '', 255 + /** 256 + * @see https://github.com/bluesky-social/atproto/blob/c5d36d5ba2a2c2a5c4f366a5621c06a5608e361e/packages/api/src/agent.ts#L188 257 + */ 258 + active: account.active ?? true, 259 + status: account.status, 260 + } 261 + }
+3 -2
src/state/session/index.tsx
··· 14 14 createAgentAndCreateAccount, 15 15 createAgentAndLogin, 16 16 createAgentAndResume, 17 + sessionAccountToSession, 17 18 } from './agent' 18 19 import {getInitialState, reducer} from './reducer' 19 20 ··· 175 176 if (syncedAccount.did !== state.currentAgentState.did) { 176 177 resumeSession(syncedAccount) 177 178 } else { 178 - // @ts-ignore we checked for `refreshJwt` above 179 - state.currentAgentState.agent.session = syncedAccount 179 + const agent = state.currentAgentState.agent as BskyAgent 180 + agent.session = sessionAccountToSession(syncedAccount) 180 181 } 181 182 } 182 183 })