mirror of
https://github.com/lumehq/lume.git
synced 2025-09-26 09:27:34 +02:00
renamed model follow to pleb
This commit is contained in:
@@ -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 {
|
model Account {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
pubkey String
|
pubkey String @unique
|
||||||
privkey String @unique
|
privkey String @unique
|
||||||
active Boolean @default(false)
|
active Boolean @default(false)
|
||||||
metadata String
|
metadata String
|
||||||
|
|
||||||
// related
|
// related
|
||||||
follows Follow[]
|
plebs Pleb[]
|
||||||
messages Message[]
|
messages Message[]
|
||||||
notes Note[]
|
notes Note[]
|
||||||
|
|
||||||
@@index([pubkey])
|
@@index([pubkey])
|
||||||
}
|
}
|
||||||
|
|
||||||
model Follow {
|
model Pleb {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
pubkey String
|
pubkey String @unique
|
||||||
kind Int
|
kind Int
|
||||||
metadata String
|
metadata String
|
||||||
|
|
||||||
Account Account @relation(fields: [accountId], references: [id])
|
Account Account @relation(fields: [accountId], references: [id])
|
||||||
accountId Int
|
accountId Int
|
||||||
|
|
||||||
|
@@index([pubkey])
|
||||||
}
|
}
|
||||||
|
|
||||||
model Note {
|
model Note {
|
||||||
|
@@ -33,17 +33,17 @@ struct CreateAccountData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Type)]
|
#[derive(Deserialize, Type)]
|
||||||
struct GetFollowData {
|
struct GetPlebData {
|
||||||
account_id: i32,
|
account_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Type)]
|
#[derive(Deserialize, Type)]
|
||||||
struct GetFollowPubkeyData {
|
struct GetPlebPubkeyData {
|
||||||
pubkey: String,
|
pubkey: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Type)]
|
#[derive(Deserialize, Type)]
|
||||||
struct CreateFollowData {
|
struct CreatePlebData {
|
||||||
pubkey: String,
|
pubkey: String,
|
||||||
kind: i32,
|
kind: i32,
|
||||||
metadata: String,
|
metadata: String,
|
||||||
@@ -102,9 +102,9 @@ async fn create_account(db: DbState<'_>, data: CreateAccountData) -> Result<acco
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
async fn get_follows(db: DbState<'_>, data: GetFollowData) -> Result<Vec<follow::Data>, ()> {
|
async fn get_plebs(db: DbState<'_>, data: GetPlebData) -> Result<Vec<pleb::Data>, ()> {
|
||||||
db.follow()
|
db.pleb()
|
||||||
.find_many(vec![follow::account_id::equals(data.account_id)])
|
.find_many(vec![pleb::account_id::equals(data.account_id)])
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ())
|
.map_err(|_| ())
|
||||||
@@ -112,12 +112,12 @@ async fn get_follows(db: DbState<'_>, data: GetFollowData) -> Result<Vec<follow:
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
async fn get_follow_by_pubkey(
|
async fn get_pleb_by_pubkey(
|
||||||
db: DbState<'_>,
|
db: DbState<'_>,
|
||||||
data: GetFollowPubkeyData,
|
data: GetPlebPubkeyData,
|
||||||
) -> Result<Option<follow::Data>, ()> {
|
) -> Result<Option<pleb::Data>, ()> {
|
||||||
db.follow()
|
db.pleb()
|
||||||
.find_first(vec![follow::pubkey::equals(data.pubkey)])
|
.find_first(vec![pleb::pubkey::equals(data.pubkey)])
|
||||||
.exec()
|
.exec()
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ())
|
.map_err(|_| ())
|
||||||
@@ -125,8 +125,8 @@ async fn get_follow_by_pubkey(
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
async fn create_follow(db: DbState<'_>, data: CreateFollowData) -> Result<follow::Data, ()> {
|
async fn create_pleb(db: DbState<'_>, data: CreatePlebData) -> Result<pleb::Data, ()> {
|
||||||
db.follow()
|
db.pleb()
|
||||||
.create(
|
.create(
|
||||||
data.pubkey,
|
data.pubkey,
|
||||||
data.kind,
|
data.kind,
|
||||||
@@ -215,9 +215,9 @@ async fn main() {
|
|||||||
collect_types![
|
collect_types![
|
||||||
get_accounts,
|
get_accounts,
|
||||||
create_account,
|
create_account,
|
||||||
get_follows,
|
get_plebs,
|
||||||
get_follow_by_pubkey,
|
get_pleb_by_pubkey,
|
||||||
create_follow,
|
create_pleb,
|
||||||
create_note,
|
create_note,
|
||||||
get_notes,
|
get_notes,
|
||||||
get_latest_notes,
|
get_latest_notes,
|
||||||
@@ -256,9 +256,9 @@ async fn main() {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
get_accounts,
|
get_accounts,
|
||||||
create_account,
|
create_account,
|
||||||
get_follows,
|
get_plebs,
|
||||||
get_follow_by_pubkey,
|
get_pleb_by_pubkey,
|
||||||
create_follow,
|
create_pleb,
|
||||||
create_note,
|
create_note,
|
||||||
get_notes,
|
get_notes,
|
||||||
get_latest_notes,
|
get_latest_notes,
|
||||||
|
@@ -28,12 +28,12 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
|
|||||||
|
|
||||||
const insertFollowsToStorage = useCallback(
|
const insertFollowsToStorage = useCallback(
|
||||||
async (tags) => {
|
async (tags) => {
|
||||||
const { createFollow } = await import('@utils/bindings');
|
const { createPleb } = await import('@utils/bindings');
|
||||||
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
|
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
|
||||||
|
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
const metadata: any = await fetchMetadata(tag[1], pool, relays);
|
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
|
console.error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -31,8 +31,8 @@ export const UserExtend = ({ pubkey, time }: { pubkey: string; time: number }) =
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const getCachedMetadata = useCallback(async () => {
|
const getCachedMetadata = useCallback(async () => {
|
||||||
const { getFollowByPubkey } = await import('@utils/bindings');
|
const { getPlebByPubkey } = await import('@utils/bindings');
|
||||||
getFollowByPubkey({ pubkey: pubkey })
|
getPlebByPubkey({ pubkey: pubkey })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
const metadata = JSON.parse(res.metadata);
|
const metadata = JSON.parse(res.metadata);
|
||||||
|
@@ -10,8 +10,8 @@ export const UserFollow = ({ pubkey }: { pubkey: string }) => {
|
|||||||
const [profile, setProfile] = useState(null);
|
const [profile, setProfile] = useState(null);
|
||||||
|
|
||||||
const getCachedMetadata = useCallback(async () => {
|
const getCachedMetadata = useCallback(async () => {
|
||||||
const { getFollowByPubkey } = await import('@utils/bindings');
|
const { getPlebByPubkey } = await import('@utils/bindings');
|
||||||
getFollowByPubkey({ pubkey: pubkey })
|
getPlebByPubkey({ pubkey: pubkey })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
const metadata = JSON.parse(res.metadata);
|
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 [profile, setProfile] = useState(null);
|
||||||
|
|
||||||
const getCachedMetadata = useCallback(async () => {
|
const getCachedMetadata = useCallback(async () => {
|
||||||
const { getFollowByPubkey } = await import('@utils/bindings');
|
const { getPlebByPubkey } = await import('@utils/bindings');
|
||||||
getFollowByPubkey({ pubkey: pubkey })
|
getPlebByPubkey({ pubkey: pubkey })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
const metadata = JSON.parse(res.metadata);
|
const metadata = JSON.parse(res.metadata);
|
||||||
|
@@ -15,8 +15,8 @@ export const UserMention = memo(function UserMention({ pubkey }: { pubkey: strin
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const getCachedMetadata = useCallback(async () => {
|
const getCachedMetadata = useCallback(async () => {
|
||||||
const { getFollowByPubkey } = await import('@utils/bindings');
|
const { getPlebByPubkey } = await import('@utils/bindings');
|
||||||
getFollowByPubkey({ pubkey: pubkey })
|
getPlebByPubkey({ pubkey: pubkey })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
const metadata = JSON.parse(res.metadata);
|
const metadata = JSON.parse(res.metadata);
|
||||||
|
@@ -10,8 +10,8 @@ export const UserMini = ({ pubkey }: { pubkey: string }) => {
|
|||||||
const [profile, setProfile] = useState(null);
|
const [profile, setProfile] = useState(null);
|
||||||
|
|
||||||
const getCachedMetadata = useCallback(async () => {
|
const getCachedMetadata = useCallback(async () => {
|
||||||
const { getFollowByPubkey } = await import('@utils/bindings');
|
const { getPlebByPubkey } = await import('@utils/bindings');
|
||||||
getFollowByPubkey({ pubkey: pubkey })
|
getPlebByPubkey({ pubkey: pubkey })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
const metadata = JSON.parse(res.metadata);
|
const metadata = JSON.parse(res.metadata);
|
||||||
|
@@ -19,8 +19,8 @@ export default function Page() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchFollowsByAccount = useCallback(async (id) => {
|
const fetchFollowsByAccount = useCallback(async (id) => {
|
||||||
const { getFollows } = await import('@utils/bindings');
|
const { getPlebs } = await import('@utils/bindings');
|
||||||
return await getFollows({ account_id: id });
|
return await getPlebs({ account_id: id });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@@ -80,12 +80,12 @@ export default function Page() {
|
|||||||
|
|
||||||
// save follows to database then broadcast
|
// save follows to database then broadcast
|
||||||
const submit = useCallback(async () => {
|
const submit = useCallback(async () => {
|
||||||
const { createFollow } = await import('@utils/bindings');
|
const { createPleb } = await import('@utils/bindings');
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
for (const follow of follows) {
|
for (const follow of follows) {
|
||||||
const metadata: any = await fetchMetadata(follow, pool, relays);
|
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
|
console.error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -46,11 +46,11 @@ export default function Page() {
|
|||||||
|
|
||||||
const insertFollowsToStorage = useCallback(
|
const insertFollowsToStorage = useCallback(
|
||||||
async (tags) => {
|
async (tags) => {
|
||||||
const { createFollow } = await import('@utils/bindings');
|
const { createPleb } = await import('@utils/bindings');
|
||||||
if (profile?.id !== null) {
|
if (profile?.id !== null) {
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
const metadata: any = await fetchMetadata(tag[1], pool, relays);
|
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
|
console.error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -16,16 +16,16 @@ export function createAccount(data: CreateAccountData) {
|
|||||||
return invoke<Account>('create_account', { data });
|
return invoke<Account>('create_account', { data });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFollows(data: GetFollowData) {
|
export function getPlebs(data: GetPlebData) {
|
||||||
return invoke<Follow[]>('get_follows', { data });
|
return invoke<Pleb[]>('get_plebs', { data });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFollowByPubkey(data: GetFollowPubkeyData) {
|
export function getPlebByPubkey(data: GetPlebPubkeyData) {
|
||||||
return invoke<Follow | null>('get_follow_by_pubkey', { data });
|
return invoke<Pleb | null>('get_pleb_by_pubkey', { data });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createFollow(data: CreateFollowData) {
|
export function createPleb(data: CreatePlebData) {
|
||||||
return invoke<Follow>('create_follow', { data });
|
return invoke<Pleb>('create_pleb', { data });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createNote(data: CreateNoteData) {
|
export function createNote(data: CreateNoteData) {
|
||||||
@@ -44,7 +44,11 @@ export function getNoteById(data: GetNoteByIdData) {
|
|||||||
return invoke<Note | null>('get_note_by_id', { data });
|
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 = {
|
export type Note = {
|
||||||
id: number;
|
id: number;
|
||||||
eventId: string;
|
eventId: string;
|
||||||
@@ -57,12 +61,8 @@ export type Note = {
|
|||||||
createdAt: number;
|
createdAt: number;
|
||||||
accountId: number;
|
accountId: number;
|
||||||
};
|
};
|
||||||
export type Account = { id: number; pubkey: string; privkey: string; active: boolean; metadata: string };
|
export type GetPlebData = { account_id: number };
|
||||||
export type GetLatestNoteData = { date: number };
|
|
||||||
export type CreateFollowData = { pubkey: string; kind: number; metadata: string; account_id: number };
|
|
||||||
export type GetFollowPubkeyData = { pubkey: string };
|
|
||||||
export type CreateAccountData = { pubkey: string; privkey: string; metadata: string };
|
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 = {
|
export type CreateNoteData = {
|
||||||
event_id: string;
|
event_id: string;
|
||||||
pubkey: string;
|
pubkey: string;
|
||||||
|
Reference in New Issue
Block a user