mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 11:43:30 +00:00
renamed model follow to pleb
This commit is contained in:
parent
5da94e091f
commit
3c63dece46
@ -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");
|
@ -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 {
|
||||
|
@ -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<acco
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_follows(db: DbState<'_>, data: GetFollowData) -> Result<Vec<follow::Data>, ()> {
|
||||
db.follow()
|
||||
.find_many(vec![follow::account_id::equals(data.account_id)])
|
||||
async fn get_plebs(db: DbState<'_>, data: GetPlebData) -> Result<Vec<pleb::Data>, ()> {
|
||||
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<Vec<follow:
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_follow_by_pubkey(
|
||||
async fn get_pleb_by_pubkey(
|
||||
db: DbState<'_>,
|
||||
data: GetFollowPubkeyData,
|
||||
) -> Result<Option<follow::Data>, ()> {
|
||||
db.follow()
|
||||
.find_first(vec![follow::pubkey::equals(data.pubkey)])
|
||||
data: GetPlebPubkeyData,
|
||||
) -> Result<Option<pleb::Data>, ()> {
|
||||
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<follow::Data, ()> {
|
||||
db.follow()
|
||||
async fn create_pleb(db: DbState<'_>, data: CreatePlebData) -> Result<pleb::Data, ()> {
|
||||
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,
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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(() => {
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -16,16 +16,16 @@ export function createAccount(data: CreateAccountData) {
|
||||
return invoke<Account>('create_account', { data });
|
||||
}
|
||||
|
||||
export function getFollows(data: GetFollowData) {
|
||||
return invoke<Follow[]>('get_follows', { data });
|
||||
export function getPlebs(data: GetPlebData) {
|
||||
return invoke<Pleb[]>('get_plebs', { data });
|
||||
}
|
||||
|
||||
export function getFollowByPubkey(data: GetFollowPubkeyData) {
|
||||
return invoke<Follow | null>('get_follow_by_pubkey', { data });
|
||||
export function getPlebByPubkey(data: GetPlebPubkeyData) {
|
||||
return invoke<Pleb | null>('get_pleb_by_pubkey', { data });
|
||||
}
|
||||
|
||||
export function createFollow(data: CreateFollowData) {
|
||||
return invoke<Follow>('create_follow', { data });
|
||||
export function createPleb(data: CreatePlebData) {
|
||||
return invoke<Pleb>('create_pleb', { data });
|
||||
}
|
||||
|
||||
export function createNote(data: CreateNoteData) {
|
||||
@ -44,7 +44,11 @@ export function getNoteById(data: GetNoteByIdData) {
|
||||
return invoke<Note | null>('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;
|
||||
|
Loading…
Reference in New Issue
Block a user