Actual DM structure

This commit is contained in:
2025-10-04 16:49:29 +02:00
parent 5fa7fd224f
commit f5162cceeb
2 changed files with 12 additions and 7 deletions
+2 -2
View File
@@ -119,9 +119,9 @@ impl Server {
client.send(types::ServerMessage::Authenticated {
uuid,
messages: if let Some(i) = last_message {
self.wrap_err(&client, self.db.get_messages_after_id(i))?
self.wrap_err(&client, self.db.get_messages_after_id(uuid, i))?
} else {
self.wrap_err(&client, self.db.get_messages_after_id(0))?
self.wrap_err(&client, self.db.get_messages_after_id(uuid, 0))?
},
}),
)?;
+9 -4
View File
@@ -104,15 +104,20 @@ impl Database {
}
/// Get all messages with an ID greater than the given one
pub fn get_messages_after_id(&self, message_id: usize) -> Result<Vec<Message>> {
pub fn get_messages_after_id(
&self,
channel_id: u32,
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",
WHERE (channel_id = ?2 OR user_id = ?2)
AND id > ?1
ORDER BY id ASC;",
)?;
let rows = stmt.query_map(params![message_id], |row| {
let rows = stmt.query_map(params![message_id, channel_id], |row| {
Ok(Message {
id: row.get::<_, i64>(0)?,
channel_id: row.get::<_, u32>(1)?,