diff options
Diffstat (limited to 'src/state/models/session.ts')
-rw-r--r-- | src/state/models/session.ts | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/state/models/session.ts b/src/state/models/session.ts index e131b2b2c..c2e10880d 100644 --- a/src/state/models/session.ts +++ b/src/state/models/session.ts @@ -1,9 +1,9 @@ import {makeAutoObservable, runInAction} from 'mobx' import { - AtpAgent, + BskyAgent, AtpSessionEvent, AtpSessionData, - ComAtprotoServerGetAccountsConfig as GetAccountsConfig, + ComAtprotoServerDescribeServer as DescribeServer, } from '@atproto/api' import normalizeUrl from 'normalize-url' import {isObj, hasProp} from 'lib/type-guards' @@ -11,7 +11,7 @@ import {networkRetry} from 'lib/async/retry' import {z} from 'zod' import {RootStoreModel} from './root-store' -export type ServiceDescription = GetAccountsConfig.OutputSchema +export type ServiceDescription = DescribeServer.OutputSchema export const activeSession = z.object({ service: z.string(), @@ -40,7 +40,7 @@ export class SessionModel { // emergency log facility to help us track down this logout issue // remove when resolved // -prf - private _log(message: string, details?: Record<string, any>) { + _log(message: string, details?: Record<string, any>) { details = details || {} details.state = { data: this.data, @@ -73,6 +73,7 @@ export class SessionModel { rootStore: false, serialize: false, hydrate: false, + hasSession: false, }) } @@ -154,7 +155,7 @@ export class SessionModel { /** * Sets the active session */ - async setActiveSession(agent: AtpAgent, did: string) { + async setActiveSession(agent: BskyAgent, did: string) { this._log('SessionModel:setActiveSession') this.data = { service: agent.service.toString(), @@ -166,7 +167,7 @@ export class SessionModel { /** * Upserts a session into the accounts */ - private persistSession( + persistSession( service: string, did: string, event: AtpSessionEvent, @@ -225,7 +226,7 @@ export class SessionModel { /** * Clears any session tokens from the accounts; used on logout. */ - private clearSessionTokens() { + clearSessionTokens() { this._log('SessionModel:clearSessionTokens') this.accounts = this.accounts.map(acct => ({ service: acct.service, @@ -239,10 +240,8 @@ export class SessionModel { /** * Fetches additional information about an account on load. */ - private async loadAccountInfo(agent: AtpAgent, did: string) { - const res = await agent.api.app.bsky.actor - .getProfile({actor: did}) - .catch(_e => undefined) + async loadAccountInfo(agent: BskyAgent, did: string) { + const res = await agent.getProfile({actor: did}).catch(_e => undefined) if (res) { return { dispayName: res.data.displayName, @@ -255,8 +254,8 @@ export class SessionModel { * Helper to fetch the accounts config settings from an account. */ async describeService(service: string): Promise<ServiceDescription> { - const agent = new AtpAgent({service}) - const res = await agent.api.com.atproto.server.getAccountsConfig({}) + const agent = new BskyAgent({service}) + const res = await agent.com.atproto.server.describeServer({}) return res.data } @@ -272,7 +271,7 @@ export class SessionModel { return false } - const agent = new AtpAgent({ + const agent = new BskyAgent({ service: account.service, persistSession: (evt: AtpSessionEvent, sess?: AtpSessionData) => { this.persistSession(account.service, account.did, evt, sess) @@ -321,7 +320,7 @@ export class SessionModel { password: string }) { this._log('SessionModel:login') - const agent = new AtpAgent({service}) + const agent = new BskyAgent({service}) await agent.login({identifier, password}) if (!agent.session) { throw new Error('Failed to establish session') @@ -355,7 +354,7 @@ export class SessionModel { inviteCode?: string }) { this._log('SessionModel:createAccount') - const agent = new AtpAgent({service}) + const agent = new BskyAgent({service}) await agent.createAccount({ handle, password, @@ -389,7 +388,7 @@ export class SessionModel { // need to evaluate why deleting the session has caused errors at times // -prf /*if (this.hasSession) { - this.rootStore.api.com.atproto.session.delete().catch((e: any) => { + this.rootStore.agent.com.atproto.session.delete().catch((e: any) => { this.rootStore.log.warn( '(Minor issue) Failed to delete session on the server', e, @@ -415,7 +414,7 @@ export class SessionModel { if (!sess) { return } - const res = await this.rootStore.api.app.bsky.actor + const res = await this.rootStore.agent .getProfile({actor: sess.did}) .catch(_e => undefined) if (res?.success) { |