Various AT Protocol integrations with obsidian
20
fork

Configure Feed

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

cleanup storing session/agent

+10 -9
+10 -9
src/lib/client.ts
··· 7 7 8 8 export class ATClient extends Client { 9 9 private hh: Handler; 10 - actor?: ResolvedActor 10 + actor?: ResolvedActor; 11 11 12 12 constructor() { 13 13 const oauth = new OAuthHandler(); ··· 17 17 } 18 18 19 19 get loggedIn(): boolean { 20 - return (!!this.actor?.did && !!this.hh.session?.info.sub) 20 + return !!this.hh.agent && !!this.actor; 21 21 } 22 22 23 23 async login(identifier: string): Promise<void> { 24 24 await this.hh.login(identifier); 25 - this.actor = await this.hh.getActor(this.hh.session!.info.sub); 25 + const did = this.hh.agent?.session.info.sub; 26 + if (did) { 27 + this.actor = await this.hh.getActor(did); 28 + } 26 29 } 27 30 28 31 async restoreSession(did: string): Promise<void> { ··· 32 35 33 36 async logout(identifier: string): Promise<void> { 34 37 await this.hh.logout(identifier); 38 + this.actor = undefined; 35 39 } 36 40 37 41 async getActor(identifier: string): Promise<ResolvedActor> { ··· 49 53 export class Handler implements FetchHandlerObject { 50 54 cache: Cache; 51 55 oauth: OAuthHandler; 52 - session?: Session; 53 56 agent?: OAuthUserAgent; 54 - actor?: ResolvedActor; 55 57 56 58 constructor(oauth: OAuthHandler) { 57 59 this.oauth = oauth; ··· 60 62 61 63 async login(identifier: string): Promise<void> { 62 64 const session = await this.oauth.authorize(identifier); 63 - this.session = session; 64 65 this.agent = new OAuthUserAgent(session); 65 66 } 67 + 66 68 async restoreSession(did: string): Promise<void> { 67 69 const session = await this.oauth.restore(did); 68 - this.session = session; 69 70 this.agent = new OAuthUserAgent(session); 70 71 } 72 + 71 73 async logout(identifier: string): Promise<void> { 72 74 await this.oauth.revoke(identifier); 73 - this.session = undefined; 74 75 this.agent = undefined; 75 76 } 76 77 ··· 104 105 return null; 105 106 } 106 107 107 - const own = (repo === this.session?.info.sub) 108 + const own = (repo === this.agent?.session.info.sub); 108 109 if (!own) { 109 110 // resolve to get user's PDS 110 111 const actor = await this.getActor(repo);