Reformat
This commit is contained in:
parent
3d99ba221a
commit
dd02092519
|
@ -361,8 +361,7 @@ pub fn get_auth_token_challenge(
|
|||
// Note that a given public key can have multiple pending tokens
|
||||
let conn = pool.get().map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
let stmt =
|
||||
"INSERT INTO pending_tokens (public_key, timestamp, token) VALUES (?1, ?2, ?3)";
|
||||
let stmt = "INSERT INTO pending_tokens (public_key, timestamp, token) VALUES (?1, ?2, ?3)";
|
||||
let _ = match conn.execute(&stmt, params![hex_public_key, now, token]) {
|
||||
Ok(rows) => rows,
|
||||
Err(e) => {
|
||||
|
@ -404,8 +403,7 @@ pub fn claim_auth_token(
|
|||
.ok_or(Error::Unauthorized)?;
|
||||
let token = &pending_tokens[index].1;
|
||||
// Store the claimed token
|
||||
let stmt =
|
||||
"INSERT INTO tokens (public_key, timestamp, token) VALUES (?1, ?2, ?3)";
|
||||
let stmt = "INSERT INTO tokens (public_key, timestamp, token) VALUES (?1, ?2, ?3)";
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
match conn.execute(&stmt, params![public_key, now, hex::encode(token)]) {
|
||||
Ok(_) => (),
|
||||
|
@ -606,8 +604,7 @@ fn update_usage_statistics(
|
|||
let public_key = get_public_key_for_auth_token(auth_token, pool)?;
|
||||
let conn = pool.get().map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
let stmt =
|
||||
"INSERT OR REPLACE INTO user_activity (public_key, last_active) VALUES(?1, ?2)";
|
||||
let stmt = "INSERT OR REPLACE INTO user_activity (public_key, last_active) VALUES(?1, ?2)";
|
||||
conn.execute(&stmt, params![public_key, now]).map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -676,8 +673,7 @@ pub fn delete_message(
|
|||
};
|
||||
// Update the deletions table if needed
|
||||
if count > 0 {
|
||||
let stmt =
|
||||
"INSERT INTO deleted_messages (deleted_message_id) VALUES (?1)";
|
||||
let stmt = "INSERT INTO deleted_messages (deleted_message_id) VALUES (?1)";
|
||||
match tx.execute(&stmt, params![id]) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
|
@ -723,7 +719,8 @@ pub fn get_deleted_messages(
|
|||
if query_params.get("from_server_id").is_some() {
|
||||
raw_query = "SELECT id, deleted_message_id FROM deleted_messages WHERE id > (?1) ORDER BY id ASC LIMIT (?2)";
|
||||
} else {
|
||||
raw_query = "SELECT id, deleted_message_id FROM deleted_messages ORDER BY id DESC LIMIT (?2)";
|
||||
raw_query =
|
||||
"SELECT id, deleted_message_id FROM deleted_messages ORDER BY id DESC LIMIT (?2)";
|
||||
}
|
||||
let mut query = conn.prepare(raw_query).map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
let rows = match query.query_map(params![from_server_id, limit], |row| {
|
||||
|
@ -846,8 +843,7 @@ pub fn ban_and_delete_all_messages(
|
|||
ban(public_key, auth_token, pool)?;
|
||||
// Get the IDs of the messages to delete
|
||||
let conn = pool.get().map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
let raw_query =
|
||||
"SELECT id FROM messages WHERE public_key = (?1) AND is_deleted = 0";
|
||||
let raw_query = "SELECT id FROM messages WHERE public_key = (?1) AND is_deleted = 0";
|
||||
let mut query = conn.prepare(&raw_query).map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
let rows = match query.query_map(params![public_key], |row| Ok(row.get(0)?)) {
|
||||
Ok(rows) => rows,
|
||||
|
@ -1259,8 +1255,7 @@ fn is_banned(public_key: &str, pool: &storage::DatabaseConnectionPool) -> Result
|
|||
// Get a database connection
|
||||
let conn = pool.get().map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
// Query the database
|
||||
let raw_query =
|
||||
"SELECT COUNT(public_key) FROM block_list WHERE public_key = (?1)";
|
||||
let raw_query = "SELECT COUNT(public_key) FROM block_list WHERE public_key = (?1)";
|
||||
let mut query = conn.prepare(&raw_query).map_err(|_| Error::DatabaseFailedInternally)?;
|
||||
let rows = match query.query_map(params![public_key], |row| row.get(0)) {
|
||||
Ok(rows) => rows,
|
||||
|
|
|
@ -30,8 +30,7 @@ pub fn create_main_database_if_needed() {
|
|||
}
|
||||
|
||||
fn create_main_tables_if_needed(conn: &DatabaseConnection) {
|
||||
let main_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS main (
|
||||
let main_table_cmd = "CREATE TABLE IF NOT EXISTS main (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT,
|
||||
image_id TEXT
|
||||
|
@ -74,8 +73,7 @@ pub fn create_room_tables_if_needed(conn: &DatabaseConnection) {
|
|||
// Messages
|
||||
// The `id` field is needed to make `rowid` stable, which is important because otherwise
|
||||
// the `id`s in this table won't correspond to those in the deleted messages table
|
||||
let messages_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS messages (
|
||||
let messages_table_cmd = "CREATE TABLE IF NOT EXISTS messages (
|
||||
id INTEGER PRIMARY KEY,
|
||||
public_key TEXT,
|
||||
timestamp INTEGER,
|
||||
|
@ -85,29 +83,25 @@ pub fn create_room_tables_if_needed(conn: &DatabaseConnection) {
|
|||
)";
|
||||
conn.execute(&messages_table_cmd, params![]).expect("Couldn't create messages table.");
|
||||
// Deleted messages
|
||||
let deleted_messages_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS deleted_messages (
|
||||
let deleted_messages_table_cmd = "CREATE TABLE IF NOT EXISTS deleted_messages (
|
||||
id INTEGER PRIMARY KEY,
|
||||
deleted_message_id INTEGER
|
||||
)";
|
||||
conn.execute(&deleted_messages_table_cmd, params![])
|
||||
.expect("Couldn't create deleted messages table.");
|
||||
// Moderators
|
||||
let moderators_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS moderators (
|
||||
let moderators_table_cmd = "CREATE TABLE IF NOT EXISTS moderators (
|
||||
public_key TEXT
|
||||
)";
|
||||
conn.execute(&moderators_table_cmd, params![]).expect("Couldn't create moderators table.");
|
||||
// Block list
|
||||
let block_list_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS block_list (
|
||||
let block_list_table_cmd = "CREATE TABLE IF NOT EXISTS block_list (
|
||||
public_key TEXT
|
||||
)";
|
||||
conn.execute(&block_list_table_cmd, params![]).expect("Couldn't create block list table.");
|
||||
// Pending tokens
|
||||
// Note that a given public key can have multiple pending tokens
|
||||
let pending_tokens_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS pending_tokens (
|
||||
let pending_tokens_table_cmd = "CREATE TABLE IF NOT EXISTS pending_tokens (
|
||||
public_key TEXT,
|
||||
timestamp INTEGER,
|
||||
token BLOB
|
||||
|
@ -116,23 +110,20 @@ pub fn create_room_tables_if_needed(conn: &DatabaseConnection) {
|
|||
.expect("Couldn't create pending tokens table.");
|
||||
// Tokens
|
||||
// The token is stored as hex here (rather than as bytes) because it's more convenient for lookup
|
||||
let tokens_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS tokens (
|
||||
let tokens_table_cmd = "CREATE TABLE IF NOT EXISTS tokens (
|
||||
public_key TEXT,
|
||||
timestamp INTEGER,
|
||||
token TEXT PRIMARY KEY
|
||||
)";
|
||||
conn.execute(&tokens_table_cmd, params![]).expect("Couldn't create tokens table.");
|
||||
// Files
|
||||
let files_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS files (
|
||||
let files_table_cmd = "CREATE TABLE IF NOT EXISTS files (
|
||||
id TEXT PRIMARY KEY,
|
||||
timestamp INTEGER
|
||||
)";
|
||||
conn.execute(&files_table_cmd, params![]).expect("Couldn't create files table.");
|
||||
// User activity table
|
||||
let user_activity_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS user_activity (
|
||||
let user_activity_table_cmd = "CREATE TABLE IF NOT EXISTS user_activity (
|
||||
public_key TEXT PRIMARY KEY,
|
||||
last_active INTEGER NOT NULL
|
||||
)";
|
||||
|
@ -326,8 +317,7 @@ pub fn perform_migration() {
|
|||
return error!("Couldn't get all room IDs.");
|
||||
}
|
||||
};
|
||||
let create_tokens_table_cmd =
|
||||
"CREATE TABLE IF NOT EXISTS tokens (
|
||||
let create_tokens_table_cmd = "CREATE TABLE IF NOT EXISTS tokens (
|
||||
public_key TEXT,
|
||||
timestamp INTEGER,
|
||||
token TEXT PRIMARY KEY
|
||||
|
|
Loading…
Reference in New Issue