refactor: use bskyClient

This commit is contained in:
kawamataryo 2024-11-28 12:54:58 +09:00
parent f637e48f3a
commit 93b4d2f8ae
2 changed files with 4 additions and 42 deletions

View File

@ -1,35 +0,0 @@
import type { PlasmoMessaging } from "@plasmohq/messaging";
import { BskyClient } from "~lib/bskyClient";
import { STORAGE_KEYS } from "~lib/constants";
const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
const { name, description, userDids } = req.body;
const storage = await chrome.storage.local.get(
STORAGE_KEYS.BSKY_CLIENT_SESSION,
);
const session = storage[STORAGE_KEYS.BSKY_CLIENT_SESSION];
if (!session || !session.did) {
res.send({
error: {
message: "Invalid session data",
},
});
return;
}
try {
const client = await BskyClient.createAgentFromSession(session);
await client.createListAndAddUsers({ name, description, userDids });
res.send({ success: true });
} catch (e) {
res.send({
error: {
message: e.message,
},
});
}
};
export default handler;

View File

@ -131,13 +131,10 @@ export const useBskyUserManager = () => {
if (actionMode === ACTION_MODE.IMPORT_LIST) {
const userDids = filteredUsers.map((user) => user.did);
await chrome.runtime.sendMessage({
name: "createListAndAddUsers",
body: {
name: listName,
description: "List imported via Sky Follower Bridge",
userDids,
},
await bskyClient.current.createListAndAddUsers({
name: listName,
description: "List imported via Sky Follower Bridge",
userDids,
});
return;
}