Working auth and fixed a lot of bugs

This commit is contained in:
2025-09-22 23:29:26 +02:00
parent 68e6e538bd
commit cac654cd22
8 changed files with 401 additions and 46 deletions
+28 -1
View File
@@ -12,7 +12,7 @@ impl Database {
"CREATE TABLE IF NOT EXISTS chat (
id INTEGER PRIMARY KEY AUTOINCREMENT,
channel_id TEXT NOT NULL,
user_id TEXT NOT NULL,
user_id INTEGER NOT NULL,
contents TEXT NOT NULL,
timestamp INTEGER NOT NULL
)",
@@ -102,6 +102,33 @@ impl Database {
}
Ok(None)
}
/// Get all messages with an ID greater than the given one
pub fn get_messages_after_id(&self, message_id: usize) -> Result<Vec<Message>> {
let mut stmt = self.0.prepare(
"SELECT id, channel_id, user_id, contents, timestamp
FROM chat
WHERE id > ?1
ORDER BY id ASC",
)?;
let rows = stmt.query_map(params![message_id], |row| {
Ok(Message {
id: row.get::<_, i64>(0)?,
channel_id: row.get::<_, String>(1)?,
from: row.get::<_, u32>(2)?,
contents: row.get::<_, String>(3)?,
timestamp: row.get::<_, i64>(4)?,
})
})?;
let mut messages = Vec::new();
for row in rows {
messages.push(row?);
}
Ok(messages)
}
}
unsafe impl Send for Database {}