🚀 support for firefox

This commit is contained in:
kawamataryo
2023-08-25 23:26:36 +09:00
parent 0e4c201394
commit 36f590f1a6
12 changed files with 206 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
import { AtUri, BskyAgent } from "@atproto/api";
import { AtUri, BskyAgent, type AtpSessionData } from "@atproto/api";
export type BskyLoginParams = {
identifier: string;
@@ -13,9 +13,24 @@ export class BskyClient {
email: string;
};
agent: BskyAgent;
session = {}
private constructor() {
this.agent = new BskyAgent({ service: this.service });
this.agent = new BskyAgent({ service: this.service, persistSession: (evt, session) => {
this.session = session
} });
}
public static createAgentFromSession(session: AtpSessionData): BskyClient {
const client = new BskyClient();
client.agent.resumeSession(session);
client.me = {
did: session.did,
handle: session.handle,
email: session.email,
}
return client;
}
public static async createAgent({

View File

@@ -0,0 +1,92 @@
import { sendToBackground } from "@plasmohq/messaging";
export type BskyLoginParams = {
identifier: string;
password: string;
}
export class BskyServiceWorkerClient {
private session = {}
private constructor() {
}
public static async createAgent({
identifier,
password,
}: BskyLoginParams): Promise<BskyServiceWorkerClient> {
const client = new BskyServiceWorkerClient();
const { session } = await sendToBackground({
name: "login",
body: {
identifier,
password,
}
})
client.session = session
return client;
}
public searchUser = async ({
term,
limit,
}: {
term: string;
limit: number;
}) => {
const { actors } = await sendToBackground({
name: "searchUser",
body: {
session: this.session,
term,
limit,
}
})
return actors;
};
public follow = async (subjectDid: string) => {
const { result } = await sendToBackground({
name: "follow",
body: {
session: this.session,
subjectDid
}
})
return result;
}
public unfollow = async (followUri: string) => {
const { result } = await sendToBackground({
name: "unfollow",
body: {
session: this.session,
followUri
}
})
return result;
}
public block = async (subjectDid: string) => {
const { result } = await sendToBackground({
name: "block",
body: {
session: this.session,
subjectDid
}
})
return result;
}
public unblock = async (blockUri: string) => {
// TODO: unblock is not working. Need to fix it.
const { result } = await sendToBackground({
name: "unblock",
body: {
session: this.session,
blockUri
}
})
return result;
}
}

View File

@@ -5,6 +5,7 @@ import { debugLog } from "~lib/utils";
import type { BskyClient } from './bskyClient';
import type { ViewerState } from '@atproto/api/dist/client/types/app/bsky/actor/defs';
import type { UserCellBtnLabel } from './components/BskyUserCell';
import type { BskyServiceWorkerClient } from './bskyServiceWorkerClient';
const notFoundUserCache = new Set<string>()
@@ -20,7 +21,7 @@ export const searchAndInsertBskyUsers = async (
addQuery,
removeQuery,
}: {
agent: BskyClient,
agent: BskyServiceWorkerClient | BskyClient,
userCellQueryParam: string,
btnLabel: UserCellBtnLabel,
statusKey: keyof ViewerState,