Unfollow tool for Bluesky

cleanup oauth code

Changed files
+12 -18
src
+12 -18
src/App.tsx
···
// TODO:
// - dark mode
// - display loading notice when fetching existing session
-
// - rework oauth as implementation fleshes out
-
// - split in multiple files?
import {
createSignal,
···
import { createStore } from "solid-js/store";
import { Agent } from "@atproto/api";
-
import {
-
BrowserOAuthClient,
-
OAuthSession,
-
} from "@atproto/oauth-client-browser";
+
import { BrowserOAuthClient } from "@atproto/oauth-client-browser";
enum RepoStatus {
BLOCKEDBY = 1 << 0,
···
setLoginState(false);
});
-
let appAgent: Agent;
+
let agent: Agent;
let userHandle: string;
-
const result: undefined | OAuthSession = await client.init().catch(() => {});
+
const result = await client.init().catch(() => {});
if (result) {
-
const init = await client.init();
-
appAgent = new Agent(init!.session);
+
agent = new Agent(result.session);
setLoginState(true);
-
const res = await appAgent.getProfile({ actor: appAgent.did! });
+
const res = await agent.getProfile({ actor: agent.did! });
userHandle = res.data.handle;
}
···
};
const logoutBsky = async () => {
-
if (result) await client.revoke(result.sub);
+
if (result) await client.revoke(result.session.sub);
};
const Follows: Component = () => {
···
const fetchFollows = async () => {
const PAGE_LIMIT = 100;
const fetchPage = async (cursor?: any) => {
-
return await appAgent.com.atproto.repo.listRecords({
-
repo: appAgent.did!,
+
return await agent.com.atproto.repo.listRecords({
+
repo: agent.did!,
collection: "app.bsky.graph.follow",
limit: PAGE_LIMIT,
cursor: cursor,
···
setFollowCount(follows.length);
try {
-
const res = await appAgent.getProfile({
+
const res = await agent.getProfile({
actor: record.value.subject,
});
···
viewer.blocking || viewer.blockingByList
? RepoStatus.BLOCKEDBY | RepoStatus.BLOCKING
: RepoStatus.BLOCKEDBY;
-
} else if (res.data.did.includes(appAgent.did!)) {
+
} else if (res.data.did.includes(agent.did!)) {
status = RepoStatus.YOURSELF;
} else if (viewer.blocking || viewer.blockingByList) {
status = RepoStatus.BLOCKING;
···
const BATCHSIZE = 200;
for (let i = 0; i < writes.length; i += BATCHSIZE) {
-
await appAgent.com.atproto.repo.applyWrites({
-
repo: appAgent.did!,
+
await agent.com.atproto.repo.applyWrites({
+
repo: agent.did!,
writes: writes.slice(i, i + BATCHSIZE),
});
}