fix: Set default channel name to "general"

This commit is contained in:
April Hall 2025-02-06 10:35:32 -05:00
parent 7a0aa70e0e
commit 2600f590d5
No known key found for this signature in database
GPG Key ID: A49AC35CB186266C
3 changed files with 5 additions and 5 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -11,7 +11,7 @@ class Db {
async createChannel(channelName: string) { async createChannel(channelName: string) {
try { try {
await this.client.execute(` await this.client.execute(`
CREATE TABLE IF NOT EXISTS channels.channel_${channelName} ( CREATE TABLE IF NOT EXISTS channels.${channelName} (
id UUID, id UUID,
message_content TEXT, message_content TEXT,
channel_name TEXT, channel_name TEXT,
@ -28,7 +28,7 @@ class Db {
async sendMessage(channelName: string, content: string, sender: string, id: string) { async sendMessage(channelName: string, content: string, sender: string, id: string) {
try { try {
const now = new Date(); const now = new Date();
await this.client.execute(`INSERT INTO channels.channel_${channelName} (id, message_content, channel_name, timestamp, sender) await this.client.execute(`INSERT INTO channels.${channelName} (id, message_content, channel_name, timestamp, sender)
VALUES (${id}, '${content}', '${channelName}', ${now.getTime()}, ${sender})`); VALUES (${id}, '${content}', '${channelName}', ${now.getTime()}, ${sender})`);
} catch (e) { } catch (e) {
console.log(`Error storing messages: ${e as Error}`); console.log(`Error storing messages: ${e as Error}`);
@ -50,7 +50,7 @@ class Db {
async getMessages(channelName: string, limit: number): Promise<cassandra.types.Row[] | undefined> { async getMessages(channelName: string, limit: number): Promise<cassandra.types.Row[] | undefined> {
try { try {
const res = await this.client.execute( const res = await this.client.execute(
`SELECT * FROM channels.channel_${channelName} WHERE channel_name = '${channelName}' ORDER BY timestamp DESC LIMIT ${limit}`, `SELECT * FROM channels.${channelName} WHERE channel_name = '${channelName}' ORDER BY timestamp DESC LIMIT ${limit}`,
); );
return res.rows; return res.rows;
} catch (e) { } catch (e) {
@ -83,5 +83,6 @@ try {
} }
const db = new Db(client); const db = new Db(client);
await db.createChannel('general');
export { db }; export { db };

View File

@ -21,8 +21,7 @@ export function startupSocketIOServer(httpServer: HttpServer | null) {
if (msg.content !== '') { if (msg.content !== '') {
console.log(`[ws:kit] message from ${socket.id}: ${msg.content}`); console.log(`[ws:kit] message from ${socket.id}: ${msg.content}`);
// Store the message in the database // Store the message in the database
await db.createChannel('000'); await db.sendMessage('general', msg.content, msg.id, uuidv4());
await db.sendMessage('000', msg.content, msg.id, uuidv4());
io!.emit('message', { io!.emit('message', {
user: msg.id, user: msg.id,
message: msg.content, message: msg.content,