Various AT Protocol integrations with obsidian
20
fork

Configure Feed

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

cleanup

+13 -31
+12 -29
src/lib/client.ts
··· 3 3 import { isActorIdentifier } from "@atcute/lexicons/syntax"; 4 4 import { ResolvedActor } from "@atcute/identity-resolver"; 5 5 import { OAuthHandler, } from "./oauth/oauth"; 6 - import { OAuthUserAgent, Session } from "@atcute/oauth-browser-client"; 6 + import { OAuthUserAgent } from "@atcute/oauth-browser-client"; 7 7 8 8 export class ATClient extends Client { 9 9 private hh: Handler; 10 + private oauth: OAuthHandler; 10 11 actor?: ResolvedActor; 11 12 12 13 constructor() { 13 - const oauth = new OAuthHandler(); 14 - const hh = new Handler(oauth); 14 + const hh = new Handler(); 15 15 super({ handler: hh }); 16 + this.oauth = new OAuthHandler(); 16 17 this.hh = hh; 17 18 } 18 19 ··· 21 22 } 22 23 23 24 async login(identifier: string): Promise<void> { 24 - await this.hh.login(identifier); 25 + const session = await this.oauth.authorize(identifier); 26 + this.hh.agent = new OAuthUserAgent(session); 25 27 const did = this.hh.agent?.session.info.sub; 26 28 if (did) { 27 29 this.actor = await this.hh.getActor(did); ··· 29 31 } 30 32 31 33 async restoreSession(did: string): Promise<void> { 32 - await this.hh.restoreSession(did); 34 + const session = await this.oauth.restore(did); 35 + this.hh.agent = new OAuthUserAgent(session); 33 36 this.actor = await this.hh.getActor(did); 34 37 } 35 38 36 39 async logout(identifier: string): Promise<void> { 37 - await this.hh.logout(identifier); 40 + await this.oauth.revoke(identifier); 41 + this.hh.agent = undefined; 38 42 this.actor = undefined; 39 43 } 40 44 ··· 43 47 } 44 48 45 49 handleOAuthCallback(params: URLSearchParams): void { 46 - this.hh.handleOAuthCallback(params); 50 + this.oauth.handleCallback(params); 47 51 } 48 52 } 49 53 ··· 52 56 */ 53 57 export class Handler implements FetchHandlerObject { 54 58 cache: Cache; 55 - oauth: OAuthHandler; 56 59 agent?: OAuthUserAgent; 57 60 58 - constructor(oauth: OAuthHandler) { 59 - this.oauth = oauth; 61 + constructor() { 60 62 this.cache = new Cache(5 * 60 * 1000); // 5 minutes TTL 61 - } 62 - 63 - async login(identifier: string): Promise<void> { 64 - const session = await this.oauth.authorize(identifier); 65 - this.agent = new OAuthUserAgent(session); 66 - } 67 - 68 - async restoreSession(did: string): Promise<void> { 69 - const session = await this.oauth.restore(did); 70 - this.agent = new OAuthUserAgent(session); 71 - } 72 - 73 - async logout(identifier: string): Promise<void> { 74 - await this.oauth.revoke(identifier); 75 - this.agent = undefined; 76 - } 77 - 78 - handleOAuthCallback(params: URLSearchParams): void { 79 - this.oauth.handleCallback(params); 80 63 } 81 64 82 65 async getActor(identifier: string): Promise<ResolvedActor> {
+1 -1
src/lib/oauth/oauth.ts
··· 45 45 target: { type: 'account', identifier: identifier as ActorIdentifier }, 46 46 scope: metadata.scope, 47 47 }); 48 - await sleep(200); 48 + await new Promise((resolve) => setTimeout(resolve, 200)); 49 49 50 50 // Create promise for callback 51 51 const waitForCallback = new Promise<URLSearchParams>((resolve, reject) => {
-1
src/main.ts
··· 81 81 this.addSettingTab(new SettingTab(this.app, this)); 82 82 } 83 83 84 - 85 84 async checkAuth() { 86 85 if (this.client.loggedIn) { 87 86 return true;