From 960abac7d9be611fccf0e0de1540528418019656 Mon Sep 17 00:00:00 2001 From: shockrah Date: Wed, 4 Nov 2020 00:19:35 -0800 Subject: [PATCH] DbInvites .filter method ! untested --- server-api/db/src/messages.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/server-api/db/src/messages.rs b/server-api/db/src/messages.rs index de0e3f0..e11ed9b 100644 --- a/server-api/db/src/messages.rs +++ b/server-api/db/src/messages.rs @@ -19,7 +19,7 @@ pub struct Message { } #[async_trait] -impl FromDB for Message { +impl FromDB for Message { type Row = Option<(UBigInt, BigInt, VarChar, UBigInt, VarChar)>; async fn get(p: &Pool, id: UBigInt) -> Response { @@ -78,4 +78,37 @@ impl FromDB for Message { } return Response::Other(no_conn!("Message::FromDB::update")) } + + async fn filter(p: &Pool, (time, channel_id): (BigInt, UBigInt)) -> Response { + //! FIlter happens via unix_timestamp and channel_id respectively + if let Ok(conn) = p.get_conn().await { + let q = "SELECT id, time, content, author_id"; + if let Ok(query)= conn.prep_exec(q, params!{"time" => time, "cid" => channel_id}).await { + let mapping_r = query.map_and_drop(|row| { + let (id, time, content, uid): (UBigInt, BigInt, VarChar, UBigInt) = + mysql_async::from_row(row); + + Message { + id: id, + time: time, + content: content, + author_id: uid, + channel_name: "".into() // no point at this point tbh + } + }).await; + + match mapping_r { + Ok((_, messages)) => Response::Set(messages), + Err(_) => Response::Other(sql_err!("db::Message::filter")) + } + } + else { + return Response::Empty; + } + + } + else { + return Response::Other(no_conn!("db::Message::filter")); + } + } }