refactor channel

This commit is contained in:
Ren Amamiya
2023-06-17 12:28:46 +07:00
parent 0a6865431d
commit c9f7d942a0
21 changed files with 275 additions and 291 deletions

View File

@@ -303,6 +303,31 @@ export async function updateChannelMetadata(event_id: string, value: string) {
);
}
// create channel messages
export async function createChannelMessage(
channel_id: string,
event_id: string,
pubkey: string,
kind: number,
content: string,
tags: string[][],
created_at: number,
) {
const db = await connect();
return await db.execute(
"INSERT OR IGNORE INTO channel_messages (channel_id, event_id, pubkey, kind, content, tags, created_at) VALUES (?, ?, ?, ?, ?, ?, ?);",
[channel_id, event_id, pubkey, kind, content, tags, created_at],
);
}
// get channel messages by channel id
export async function getChannelMessages(channel_id: string) {
const db = await connect();
return await db.select(
`SELECT * FROM channel_messages WHERE channel_id = "${channel_id}" ORDER BY created_at ASC;`,
);
}
// get all chats by pubkey
export async function getChatsByPubkey(pubkey: string) {
const db = await connect();