Match client changes
This commit is contained in:
parent
9e1bfa7320
commit
4c4a23f8b5
|
@ -219,8 +219,8 @@ pub async fn insert_message(mut message: models::Message, auth_token: Option<Str
|
|||
let mut conn = pool.get().map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
let tx = conn.transaction().map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
// Insert the message
|
||||
let stmt = format!("INSERT INTO {} (public_key, text) VALUES (?1, ?2)", storage::MESSAGES_TABLE);
|
||||
match tx.execute(&stmt, params![ &requesting_public_key, message.text ]) {
|
||||
let stmt = format!("INSERT INTO {} (public_key, data, signature) VALUES (?1, ?2)", storage::MESSAGES_TABLE);
|
||||
match tx.execute(&stmt, params![ &requesting_public_key, message.data, message.signature ]) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
println!("Couldn't insert message due to error: {}.", e);
|
||||
|
@ -245,13 +245,13 @@ pub async fn get_messages(options: rpc::QueryOptions, pool: &storage::DatabaseCo
|
|||
// Query the database
|
||||
let raw_query: String;
|
||||
if options.from_server_id.is_some() {
|
||||
raw_query = format!("SELECT id, text FROM {} WHERE rowid > (?1) LIMIT (?2)", storage::MESSAGES_TABLE);
|
||||
raw_query = format!("SELECT id, data, signature FROM {} WHERE rowid > (?1) LIMIT (?2)", storage::MESSAGES_TABLE);
|
||||
} else {
|
||||
raw_query = format!("SELECT id, text FROM {} ORDER BY rowid DESC LIMIT (?2)", storage::MESSAGES_TABLE);
|
||||
raw_query = format!("SELECT id, data, signature FROM {} ORDER BY rowid DESC LIMIT (?2)", storage::MESSAGES_TABLE);
|
||||
}
|
||||
let mut query = conn.prepare(&raw_query).map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
let rows = match query.query_map(params![ from_server_id, limit ], |row| {
|
||||
Ok(models::Message { server_id : row.get(0)?, text : row.get(1)? })
|
||||
Ok(models::Message { server_id : row.get(0)?, data : row.get(1)?, signature : row.get(2)? })
|
||||
}) {
|
||||
Ok(rows) => rows,
|
||||
Err(e) => {
|
||||
|
|
|
@ -3,13 +3,14 @@ use serde::{Deserialize, Serialize};
|
|||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Message {
|
||||
pub server_id: Option<i64>,
|
||||
pub text: String
|
||||
pub data: String,
|
||||
pub signature: String
|
||||
}
|
||||
|
||||
impl Message {
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
return !self.text.is_empty();
|
||||
return !self.data.is_empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,8 @@ fn create_room_tables_if_needed(conn: &DatabaseConnection) {
|
|||
"CREATE TABLE IF NOT EXISTS {} (
|
||||
id INTEGER PRIMARY KEY,
|
||||
public_key TEXT,
|
||||
text TEXT
|
||||
data TEXT,
|
||||
signature TEXT
|
||||
)", MESSAGES_TABLE);
|
||||
conn.execute(&messages_table_cmd, params![]).expect("Couldn't create messages table.");
|
||||
// Deleted messages
|
||||
|
|
Loading…
Reference in New Issue