mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 11:43:30 +00:00
added get channels
This commit is contained in:
parent
fabc0e6cc2
commit
0bfcb10253
@ -0,0 +1,17 @@
|
|||||||
|
-- RedefineTables
|
||||||
|
PRAGMA foreign_keys=OFF;
|
||||||
|
CREATE TABLE "new_Channel" (
|
||||||
|
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"eventId" TEXT NOT NULL,
|
||||||
|
"content" TEXT NOT NULL,
|
||||||
|
"active" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"accountId" INTEGER NOT NULL,
|
||||||
|
CONSTRAINT "Channel_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||||
|
);
|
||||||
|
INSERT INTO "new_Channel" ("accountId", "content", "eventId", "id") SELECT "accountId", "content", "eventId", "id" FROM "Channel";
|
||||||
|
DROP TABLE "Channel";
|
||||||
|
ALTER TABLE "new_Channel" RENAME TO "Channel";
|
||||||
|
CREATE UNIQUE INDEX "Channel_eventId_key" ON "Channel"("eventId");
|
||||||
|
CREATE INDEX "Channel_eventId_idx" ON "Channel"("eventId");
|
||||||
|
PRAGMA foreign_key_check;
|
||||||
|
PRAGMA foreign_keys=ON;
|
@ -80,9 +80,10 @@ model Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Channel {
|
model Channel {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
eventId String @unique
|
eventId String @unique
|
||||||
content String
|
content String
|
||||||
|
active Boolean @default(false)
|
||||||
|
|
||||||
Account Account @relation(fields: [accountId], references: [id])
|
Account Account @relation(fields: [accountId], references: [id])
|
||||||
accountId Int
|
accountId Int
|
||||||
|
@ -100,6 +100,17 @@ struct CreateChannelData {
|
|||||||
account_id: i32,
|
account_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Type)]
|
||||||
|
struct GetChannelData {
|
||||||
|
limit: i32,
|
||||||
|
offset: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Type)]
|
||||||
|
struct GetActiveChannelData {
|
||||||
|
active: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
async fn get_accounts(db: DbState<'_>) -> Result<Vec<account::Data>, ()> {
|
async fn get_accounts(db: DbState<'_>) -> Result<Vec<account::Data>, ()> {
|
||||||
@ -253,6 +264,31 @@ async fn create_channel(db: DbState<'_>, data: CreateChannelData) -> Result<chan
|
|||||||
.map_err(|_| ())
|
.map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
#[specta::specta]
|
||||||
|
async fn get_channels(db: DbState<'_>, data: GetChannelData) -> Result<Vec<channel::Data>, ()> {
|
||||||
|
db.channel()
|
||||||
|
.find_many(vec![])
|
||||||
|
.take(data.limit.into())
|
||||||
|
.skip(data.offset.into())
|
||||||
|
.exec()
|
||||||
|
.await
|
||||||
|
.map_err(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
#[specta::specta]
|
||||||
|
async fn get_active_channels(
|
||||||
|
db: DbState<'_>,
|
||||||
|
data: GetActiveChannelData,
|
||||||
|
) -> Result<Vec<channel::Data>, ()> {
|
||||||
|
db.channel()
|
||||||
|
.find_many(vec![channel::active::equals(data.active)])
|
||||||
|
.exec()
|
||||||
|
.await
|
||||||
|
.map_err(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
async fn create_chat(db: DbState<'_>, data: CreateChatData) -> Result<chat::Data, ()> {
|
async fn create_chat(db: DbState<'_>, data: CreateChatData) -> Result<chat::Data, ()> {
|
||||||
@ -299,6 +335,8 @@ async fn main() {
|
|||||||
get_latest_notes,
|
get_latest_notes,
|
||||||
get_note_by_id,
|
get_note_by_id,
|
||||||
create_channel,
|
create_channel,
|
||||||
|
get_channels,
|
||||||
|
get_active_channels,
|
||||||
create_chat,
|
create_chat,
|
||||||
get_chats
|
get_chats
|
||||||
],
|
],
|
||||||
@ -344,6 +382,8 @@ async fn main() {
|
|||||||
get_note_by_id,
|
get_note_by_id,
|
||||||
count_total_notes,
|
count_total_notes,
|
||||||
create_channel,
|
create_channel,
|
||||||
|
get_channels,
|
||||||
|
get_active_channels,
|
||||||
create_chat,
|
create_chat,
|
||||||
get_chats
|
get_chats
|
||||||
])
|
])
|
||||||
|
55
src/pages/channels/[id].tsx
Normal file
55
src/pages/channels/[id].tsx
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import BaseLayout from '@layouts/base';
|
||||||
|
import WithSidebarLayout from '@layouts/withSidebar';
|
||||||
|
|
||||||
|
import { RelayContext } from '@components/relaysProvider';
|
||||||
|
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal, useContext, useEffect } from 'react';
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
const [pool, relays]: any = useContext(RelayContext);
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const id: string | string[] = router.query.id || null;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const unsubscribe = pool.subscribe(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
kinds: [42],
|
||||||
|
since: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
relays,
|
||||||
|
(event: any) => {
|
||||||
|
console.log(event);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unsubscribe;
|
||||||
|
};
|
||||||
|
}, [pool, relays]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-full w-full flex-col justify-between">
|
||||||
|
<p>{id}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Page.getLayout = function getLayout(
|
||||||
|
page:
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| boolean
|
||||||
|
| ReactElement<unknown, string | JSXElementConstructor<unknown>>
|
||||||
|
| ReactFragment
|
||||||
|
| ReactPortal
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<BaseLayout>
|
||||||
|
<WithSidebarLayout>{page}</WithSidebarLayout>
|
||||||
|
</BaseLayout>
|
||||||
|
);
|
||||||
|
};
|
@ -48,6 +48,14 @@ export function createChannel(data: CreateChannelData) {
|
|||||||
return invoke<Channel>('create_channel', { data });
|
return invoke<Channel>('create_channel', { data });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getChannels(data: GetChannelData) {
|
||||||
|
return invoke<Channel[]>('get_channels', { data });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getActiveChannels(data: GetActiveChannelData) {
|
||||||
|
return invoke<Channel[]>('get_active_channels', { data });
|
||||||
|
}
|
||||||
|
|
||||||
export function createChat(data: CreateChatData) {
|
export function createChat(data: CreateChatData) {
|
||||||
return invoke<Chat>('create_chat', { data });
|
return invoke<Chat>('create_chat', { data });
|
||||||
}
|
}
|
||||||
@ -85,11 +93,13 @@ export type GetNoteByIdData = { event_id: string };
|
|||||||
export type Chat = { id: number; pubkey: string; createdAt: number; accountId: number };
|
export type Chat = { id: number; pubkey: string; createdAt: number; accountId: number };
|
||||||
export type Account = { id: number; pubkey: string; privkey: string; active: boolean; metadata: string };
|
export type Account = { id: number; pubkey: string; privkey: string; active: boolean; metadata: string };
|
||||||
export type GetChatData = { account_id: number };
|
export type GetChatData = { account_id: number };
|
||||||
|
export type GetChannelData = { limit: number; offset: number };
|
||||||
export type CreateChannelData = { event_id: string; content: string; account_id: number };
|
export type CreateChannelData = { event_id: string; content: string; account_id: number };
|
||||||
export type GetPlebPubkeyData = { pubkey: string };
|
export type GetPlebPubkeyData = { pubkey: string };
|
||||||
export type Channel = { id: number; eventId: string; content: string; accountId: number };
|
export type GetActiveChannelData = { active: boolean };
|
||||||
export type GetPlebData = { account_id: number };
|
export type GetPlebData = { account_id: number };
|
||||||
export type CreateAccountData = { pubkey: string; privkey: string; metadata: string };
|
export type CreateAccountData = { pubkey: string; privkey: string; metadata: string };
|
||||||
|
export type Channel = { id: number; eventId: string; content: string; active: boolean; accountId: number };
|
||||||
export type GetLatestNoteData = { date: number };
|
export type GetLatestNoteData = { date: number };
|
||||||
export type Pleb = { id: number; plebId: string; pubkey: string; kind: number; metadata: string; accountId: number };
|
export type Pleb = { id: number; plebId: string; pubkey: string; kind: number; metadata: string; accountId: number };
|
||||||
export type GetNoteData = { date: number; limit: number; offset: number };
|
export type GetNoteData = { date: number; limit: number; offset: number };
|
||||||
|
Loading…
Reference in New Issue
Block a user