diff --git a/src-tauri/prisma/migrations/20230405082721_rename_follow_to_pleb/migration.sql b/src-tauri/prisma/migrations/20230405082721_rename_follow_to_pleb/migration.sql new file mode 100644 index 00000000..84fee655 --- /dev/null +++ b/src-tauri/prisma/migrations/20230405082721_rename_follow_to_pleb/migration.sql @@ -0,0 +1,30 @@ +/* + Warnings: + + - You are about to drop the `Follow` table. If the table is not empty, all the data it contains will be lost. + - A unique constraint covering the columns `[pubkey]` on the table `Account` will be added. If there are existing duplicate values, this will fail. + +*/ +-- DropTable +PRAGMA foreign_keys=off; +DROP TABLE "Follow"; +PRAGMA foreign_keys=on; + +-- CreateTable +CREATE TABLE "Pleb" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "pubkey" TEXT NOT NULL, + "kind" INTEGER NOT NULL, + "metadata" TEXT NOT NULL, + "accountId" INTEGER NOT NULL, + CONSTRAINT "Pleb_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "Pleb_pubkey_key" ON "Pleb"("pubkey"); + +-- CreateIndex +CREATE INDEX "Pleb_pubkey_idx" ON "Pleb"("pubkey"); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_pubkey_key" ON "Account"("pubkey"); diff --git a/src-tauri/prisma/schema.prisma b/src-tauri/prisma/schema.prisma index 7cc44f70..234522da 100644 --- a/src-tauri/prisma/schema.prisma +++ b/src-tauri/prisma/schema.prisma @@ -12,27 +12,29 @@ generator client { model Account { id Int @id @default(autoincrement()) - pubkey String + pubkey String @unique privkey String @unique active Boolean @default(false) metadata String // related - follows Follow[] + plebs Pleb[] messages Message[] notes Note[] @@index([pubkey]) } -model Follow { +model Pleb { id Int @id @default(autoincrement()) - pubkey String + pubkey String @unique kind Int metadata String Account Account @relation(fields: [accountId], references: [id]) accountId Int + + @@index([pubkey]) } model Note { diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index cd9fdb11..84332605 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -33,17 +33,17 @@ struct CreateAccountData { } #[derive(Deserialize, Type)] -struct GetFollowData { +struct GetPlebData { account_id: i32, } #[derive(Deserialize, Type)] -struct GetFollowPubkeyData { +struct GetPlebPubkeyData { pubkey: String, } #[derive(Deserialize, Type)] -struct CreateFollowData { +struct CreatePlebData { pubkey: String, kind: i32, metadata: String, @@ -102,9 +102,9 @@ async fn create_account(db: DbState<'_>, data: CreateAccountData) -> Result, data: GetFollowData) -> Result, ()> { - db.follow() - .find_many(vec![follow::account_id::equals(data.account_id)]) +async fn get_plebs(db: DbState<'_>, data: GetPlebData) -> Result, ()> { + db.pleb() + .find_many(vec![pleb::account_id::equals(data.account_id)]) .exec() .await .map_err(|_| ()) @@ -112,12 +112,12 @@ async fn get_follows(db: DbState<'_>, data: GetFollowData) -> Result, - data: GetFollowPubkeyData, -) -> Result, ()> { - db.follow() - .find_first(vec![follow::pubkey::equals(data.pubkey)]) + data: GetPlebPubkeyData, +) -> Result, ()> { + db.pleb() + .find_first(vec![pleb::pubkey::equals(data.pubkey)]) .exec() .await .map_err(|_| ()) @@ -125,8 +125,8 @@ async fn get_follow_by_pubkey( #[tauri::command] #[specta::specta] -async fn create_follow(db: DbState<'_>, data: CreateFollowData) -> Result { - db.follow() +async fn create_pleb(db: DbState<'_>, data: CreatePlebData) -> Result { + db.pleb() .create( data.pubkey, data.kind, @@ -215,9 +215,9 @@ async fn main() { collect_types![ get_accounts, create_account, - get_follows, - get_follow_by_pubkey, - create_follow, + get_plebs, + get_pleb_by_pubkey, + create_pleb, create_note, get_notes, get_latest_notes, @@ -256,9 +256,9 @@ async fn main() { .invoke_handler(tauri::generate_handler![ get_accounts, create_account, - get_follows, - get_follow_by_pubkey, - create_follow, + get_plebs, + get_pleb_by_pubkey, + create_pleb, create_note, get_notes, get_latest_notes, diff --git a/src/components/multiAccounts/activeAccount.tsx b/src/components/multiAccounts/activeAccount.tsx index effd9c2b..fa843fcc 100644 --- a/src/components/multiAccounts/activeAccount.tsx +++ b/src/components/multiAccounts/activeAccount.tsx @@ -28,12 +28,12 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any } const insertFollowsToStorage = useCallback( async (tags) => { - const { createFollow } = await import('@utils/bindings'); + const { createPleb } = await import('@utils/bindings'); const activeAccount = JSON.parse(localStorage.getItem('activeAccount')); for (const tag of tags) { const metadata: any = await fetchMetadata(tag[1], pool, relays); - createFollow({ pubkey: tag[1], kind: 0, metadata: metadata.content, account_id: activeAccount.id }).catch( + createPleb({ pubkey: tag[1], kind: 0, metadata: metadata.content, account_id: activeAccount.id }).catch( console.error ); } diff --git a/src/components/user/extend.tsx b/src/components/user/extend.tsx index b04934b5..64a37557 100644 --- a/src/components/user/extend.tsx +++ b/src/components/user/extend.tsx @@ -31,8 +31,8 @@ export const UserExtend = ({ pubkey, time }: { pubkey: string; time: number }) = }, []); const getCachedMetadata = useCallback(async () => { - const { getFollowByPubkey } = await import('@utils/bindings'); - getFollowByPubkey({ pubkey: pubkey }) + const { getPlebByPubkey } = await import('@utils/bindings'); + getPlebByPubkey({ pubkey: pubkey }) .then((res) => { if (res) { const metadata = JSON.parse(res.metadata); diff --git a/src/components/user/follow.tsx b/src/components/user/follow.tsx index 8548f1b5..41f8db9b 100644 --- a/src/components/user/follow.tsx +++ b/src/components/user/follow.tsx @@ -10,8 +10,8 @@ export const UserFollow = ({ pubkey }: { pubkey: string }) => { const [profile, setProfile] = useState(null); const getCachedMetadata = useCallback(async () => { - const { getFollowByPubkey } = await import('@utils/bindings'); - getFollowByPubkey({ pubkey: pubkey }) + const { getPlebByPubkey } = await import('@utils/bindings'); + getPlebByPubkey({ pubkey: pubkey }) .then((res) => { if (res) { const metadata = JSON.parse(res.metadata); diff --git a/src/components/user/large.tsx b/src/components/user/large.tsx index 11474890..58d579c4 100644 --- a/src/components/user/large.tsx +++ b/src/components/user/large.tsx @@ -15,8 +15,8 @@ export const UserLarge = ({ pubkey, time }: { pubkey: string; time: number }) => const [profile, setProfile] = useState(null); const getCachedMetadata = useCallback(async () => { - const { getFollowByPubkey } = await import('@utils/bindings'); - getFollowByPubkey({ pubkey: pubkey }) + const { getPlebByPubkey } = await import('@utils/bindings'); + getPlebByPubkey({ pubkey: pubkey }) .then((res) => { if (res) { const metadata = JSON.parse(res.metadata); diff --git a/src/components/user/mention.tsx b/src/components/user/mention.tsx index 34fbb60b..72d1d8c5 100644 --- a/src/components/user/mention.tsx +++ b/src/components/user/mention.tsx @@ -15,8 +15,8 @@ export const UserMention = memo(function UserMention({ pubkey }: { pubkey: strin }, []); const getCachedMetadata = useCallback(async () => { - const { getFollowByPubkey } = await import('@utils/bindings'); - getFollowByPubkey({ pubkey: pubkey }) + const { getPlebByPubkey } = await import('@utils/bindings'); + getPlebByPubkey({ pubkey: pubkey }) .then((res) => { if (res) { const metadata = JSON.parse(res.metadata); diff --git a/src/components/user/mini.tsx b/src/components/user/mini.tsx index a8ee798a..0869d483 100644 --- a/src/components/user/mini.tsx +++ b/src/components/user/mini.tsx @@ -10,8 +10,8 @@ export const UserMini = ({ pubkey }: { pubkey: string }) => { const [profile, setProfile] = useState(null); const getCachedMetadata = useCallback(async () => { - const { getFollowByPubkey } = await import('@utils/bindings'); - getFollowByPubkey({ pubkey: pubkey }) + const { getPlebByPubkey } = await import('@utils/bindings'); + getPlebByPubkey({ pubkey: pubkey }) .then((res) => { if (res) { const metadata = JSON.parse(res.metadata); diff --git a/src/pages/index.tsx b/src/pages/index.tsx index cb67651c..47985259 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -19,8 +19,8 @@ export default function Page() { }, []); const fetchFollowsByAccount = useCallback(async (id) => { - const { getFollows } = await import('@utils/bindings'); - return await getFollows({ account_id: id }); + const { getPlebs } = await import('@utils/bindings'); + return await getPlebs({ account_id: id }); }, []); useEffect(() => { diff --git a/src/pages/onboarding/create/step-2.tsx b/src/pages/onboarding/create/step-2.tsx index 63b5e7c8..6ccb249c 100644 --- a/src/pages/onboarding/create/step-2.tsx +++ b/src/pages/onboarding/create/step-2.tsx @@ -80,12 +80,12 @@ export default function Page() { // save follows to database then broadcast const submit = useCallback(async () => { - const { createFollow } = await import('@utils/bindings'); + const { createPleb } = await import('@utils/bindings'); setLoading(true); for (const follow of follows) { const metadata: any = await fetchMetadata(follow, pool, relays); - createFollow({ pubkey: follow, kind: 0, metadata: metadata.content, account_id: parseInt(id) }).catch( + createPleb({ pubkey: follow, kind: 0, metadata: metadata.content, account_id: parseInt(id) }).catch( console.error ); } diff --git a/src/pages/onboarding/login/step-2.tsx b/src/pages/onboarding/login/step-2.tsx index c9d16c7b..a6467de0 100644 --- a/src/pages/onboarding/login/step-2.tsx +++ b/src/pages/onboarding/login/step-2.tsx @@ -46,11 +46,11 @@ export default function Page() { const insertFollowsToStorage = useCallback( async (tags) => { - const { createFollow } = await import('@utils/bindings'); + const { createPleb } = await import('@utils/bindings'); if (profile?.id !== null) { for (const tag of tags) { const metadata: any = await fetchMetadata(tag[1], pool, relays); - createFollow({ pubkey: tag[1], kind: 0, metadata: metadata.content, account_id: profile.id }).catch( + createPleb({ pubkey: tag[1], kind: 0, metadata: metadata.content, account_id: profile.id }).catch( console.error ); } diff --git a/src/utils/bindings.ts b/src/utils/bindings.ts index 708147a7..6c2b38d3 100644 --- a/src/utils/bindings.ts +++ b/src/utils/bindings.ts @@ -16,16 +16,16 @@ export function createAccount(data: CreateAccountData) { return invoke('create_account', { data }); } -export function getFollows(data: GetFollowData) { - return invoke('get_follows', { data }); +export function getPlebs(data: GetPlebData) { + return invoke('get_plebs', { data }); } -export function getFollowByPubkey(data: GetFollowPubkeyData) { - return invoke('get_follow_by_pubkey', { data }); +export function getPlebByPubkey(data: GetPlebPubkeyData) { + return invoke('get_pleb_by_pubkey', { data }); } -export function createFollow(data: CreateFollowData) { - return invoke('create_follow', { data }); +export function createPleb(data: CreatePlebData) { + return invoke('create_pleb', { data }); } export function createNote(data: CreateNoteData) { @@ -44,7 +44,11 @@ export function getNoteById(data: GetNoteByIdData) { return invoke('get_note_by_id', { data }); } -export type GetFollowData = { account_id: number }; +export type CreatePlebData = { pubkey: string; kind: number; metadata: string; account_id: number }; +export type Account = { id: number; pubkey: string; privkey: string; active: boolean; metadata: string }; +export type GetLatestNoteData = { date: number }; +export type Pleb = { id: number; pubkey: string; kind: number; metadata: string; accountId: number }; +export type GetPlebPubkeyData = { pubkey: string }; export type Note = { id: number; eventId: string; @@ -57,12 +61,8 @@ export type Note = { createdAt: number; accountId: number; }; -export type Account = { id: number; pubkey: string; privkey: string; active: boolean; metadata: string }; -export type GetLatestNoteData = { date: number }; -export type CreateFollowData = { pubkey: string; kind: number; metadata: string; account_id: number }; -export type GetFollowPubkeyData = { pubkey: string }; +export type GetPlebData = { account_id: number }; export type CreateAccountData = { pubkey: string; privkey: string; metadata: string }; -export type Follow = { id: number; pubkey: string; kind: number; metadata: string; accountId: number }; export type CreateNoteData = { event_id: string; pubkey: string;