cargo fmt

This commit is contained in:
Alexander Krotov
2019-12-01 11:40:18 +01:00
committed by Floris Bruynooghe
parent 612600278a
commit ee18d60644
3 changed files with 132 additions and 119 deletions

View File

@@ -1690,10 +1690,13 @@ fn set_group_explicitly_left(context: &Context, grpid: impl AsRef<str>) -> Resul
} }
pub fn is_group_explicitly_left(context: &Context, grpid: impl AsRef<str>) -> Result<bool, Error> { pub fn is_group_explicitly_left(context: &Context, grpid: impl AsRef<str>) -> Result<bool, Error> {
context.sql.exists( context
"SELECT id FROM leftgrps WHERE grpid=?;", .sql
params![grpid.as_ref()], .exists(
).map_err(Into::into) "SELECT id FROM leftgrps WHERE grpid=?;",
params![grpid.as_ref()],
)
.map_err(Into::into)
} }
pub fn set_chat_name( pub fn set_chat_name(

View File

@@ -495,46 +495,50 @@ pub fn save(
independent: bool, independent: bool,
) -> Result<u32, Error> { ) -> Result<u32, Error> {
ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat id"); ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat id");
context.sql.prepare2( context
"SELECT id FROM locations WHERE timestamp=? AND from_id=?", .sql
"INSERT INTO locations\ .prepare2(
(timestamp, from_id, chat_id, latitude, longitude, accuracy, independent) \ "SELECT id FROM locations WHERE timestamp=? AND from_id=?",
VALUES (?,?,?,?,?,?,?);", "INSERT INTO locations\
|mut stmt_test, mut stmt_insert, conn| { (timestamp, from_id, chat_id, latitude, longitude, accuracy, independent) \
let mut newest_timestamp = 0; VALUES (?,?,?,?,?,?,?);",
let mut newest_location_id = 0; |mut stmt_test, mut stmt_insert, conn| {
let mut newest_timestamp = 0;
let mut newest_location_id = 0;
for location in locations { for location in locations {
let exists = stmt_test.exists(params![location.timestamp, contact_id as i32])?; let exists =
stmt_test.exists(params![location.timestamp, contact_id as i32])?;
if independent || !exists { if independent || !exists {
stmt_insert.execute(params![ stmt_insert.execute(params![
location.timestamp,
contact_id as i32,
chat_id as i32,
location.latitude,
location.longitude,
location.accuracy,
independent,
])?;
if location.timestamp > newest_timestamp {
newest_timestamp = location.timestamp;
newest_location_id = sql::get_rowid2_with_conn(
context,
conn,
"locations",
"timestamp",
location.timestamp, location.timestamp,
"from_id",
contact_id as i32, contact_id as i32,
); chat_id as i32,
location.latitude,
location.longitude,
location.accuracy,
independent,
])?;
if location.timestamp > newest_timestamp {
newest_timestamp = location.timestamp;
newest_location_id = sql::get_rowid2_with_conn(
context,
conn,
"locations",
"timestamp",
location.timestamp,
"from_id",
contact_id as i32,
);
}
} }
} }
} Ok(newest_location_id)
Ok(newest_location_id) },
}, )
).map_err(Into::into) .map_err(Into::into)
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]

View File

@@ -191,82 +191,85 @@ impl Message {
!id.is_special(), !id.is_special(),
"Can not load special message IDs from DB." "Can not load special message IDs from DB."
); );
context.sql.query_row( context
concat!( .sql
"SELECT", .query_row(
" m.id AS id,", concat!(
" rfc724_mid AS rfc724mid,", "SELECT",
" m.mime_in_reply_to AS mime_in_reply_to,", " m.id AS id,",
" m.server_folder AS server_folder,", " rfc724_mid AS rfc724mid,",
" m.server_uid AS server_uid,", " m.mime_in_reply_to AS mime_in_reply_to,",
" m.chat_id AS chat_id,", " m.server_folder AS server_folder,",
" m.from_id AS from_id,", " m.server_uid AS server_uid,",
" m.to_id AS to_id,", " m.chat_id AS chat_id,",
" m.timestamp AS timestamp,", " m.from_id AS from_id,",
" m.timestamp_sent AS timestamp_sent,", " m.to_id AS to_id,",
" m.timestamp_rcvd AS timestamp_rcvd,", " m.timestamp AS timestamp,",
" m.type AS type,", " m.timestamp_sent AS timestamp_sent,",
" m.state AS state,", " m.timestamp_rcvd AS timestamp_rcvd,",
" m.msgrmsg AS msgrmsg,", " m.type AS type,",
" m.txt AS txt,", " m.state AS state,",
" m.param AS param,", " m.msgrmsg AS msgrmsg,",
" m.starred AS starred,", " m.txt AS txt,",
" m.hidden AS hidden,", " m.param AS param,",
" m.location_id AS location,", " m.starred AS starred,",
" c.blocked AS blocked", " m.hidden AS hidden,",
" FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id", " m.location_id AS location,",
" WHERE m.id=?;" " c.blocked AS blocked",
), " FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id",
params![id], " WHERE m.id=?;"
|row| { ),
let mut msg = Message::default(); params![id],
// msg.id = row.get::<_, AnyMsgId>("id")?; |row| {
msg.id = row.get("id")?; let mut msg = Message::default();
msg.rfc724_mid = row.get::<_, String>("rfc724mid")?; // msg.id = row.get::<_, AnyMsgId>("id")?;
msg.in_reply_to = row.get::<_, Option<String>>("mime_in_reply_to")?; msg.id = row.get("id")?;
msg.server_folder = row.get::<_, Option<String>>("server_folder")?; msg.rfc724_mid = row.get::<_, String>("rfc724mid")?;
msg.server_uid = row.get("server_uid")?; msg.in_reply_to = row.get::<_, Option<String>>("mime_in_reply_to")?;
msg.chat_id = row.get("chat_id")?; msg.server_folder = row.get::<_, Option<String>>("server_folder")?;
msg.from_id = row.get("from_id")?; msg.server_uid = row.get("server_uid")?;
msg.to_id = row.get("to_id")?; msg.chat_id = row.get("chat_id")?;
msg.timestamp_sort = row.get("timestamp")?; msg.from_id = row.get("from_id")?;
msg.timestamp_sent = row.get("timestamp_sent")?; msg.to_id = row.get("to_id")?;
msg.timestamp_rcvd = row.get("timestamp_rcvd")?; msg.timestamp_sort = row.get("timestamp")?;
msg.type_0 = row.get("type")?; msg.timestamp_sent = row.get("timestamp_sent")?;
msg.state = row.get("state")?; msg.timestamp_rcvd = row.get("timestamp_rcvd")?;
msg.is_dc_message = row.get("msgrmsg")?; msg.type_0 = row.get("type")?;
msg.state = row.get("state")?;
msg.is_dc_message = row.get("msgrmsg")?;
let text; let text;
if let rusqlite::types::ValueRef::Text(buf) = row.get_raw("txt") { if let rusqlite::types::ValueRef::Text(buf) = row.get_raw("txt") {
if let Ok(t) = String::from_utf8(buf.to_vec()) { if let Ok(t) = String::from_utf8(buf.to_vec()) {
text = t; text = t;
} else {
warn!(
context,
concat!(
"dc_msg_load_from_db: could not get ",
"text column as non-lossy utf8 id {}"
),
id
);
text = String::from_utf8_lossy(buf).into_owned();
}
} else { } else {
warn!( text = "".to_string();
context,
concat!(
"dc_msg_load_from_db: could not get ",
"text column as non-lossy utf8 id {}"
),
id
);
text = String::from_utf8_lossy(buf).into_owned();
} }
} else { msg.text = Some(text);
text = "".to_string();
}
msg.text = Some(text);
msg.param = row.get::<_, String>("param")?.parse().unwrap_or_default(); msg.param = row.get::<_, String>("param")?.parse().unwrap_or_default();
msg.starred = row.get("starred")?; msg.starred = row.get("starred")?;
msg.hidden = row.get("hidden")?; msg.hidden = row.get("hidden")?;
msg.location_id = row.get("location")?; msg.location_id = row.get("location")?;
msg.chat_blocked = row msg.chat_blocked = row
.get::<_, Option<Blocked>>("blocked")? .get::<_, Option<Blocked>>("blocked")?
.unwrap_or_default(); .unwrap_or_default();
Ok(msg) Ok(msg)
}, },
).map_err(Into::into) )
.map_err(Into::into)
} }
pub fn delete_from_db(context: &Context, msg_id: MsgId) { pub fn delete_from_db(context: &Context, msg_id: MsgId) {
@@ -1246,17 +1249,20 @@ pub(crate) fn rfc724_mid_exists(
) -> Result<(String, u32, MsgId), Error> { ) -> Result<(String, u32, MsgId), Error> {
ensure!(!rfc724_mid.is_empty(), "empty rfc724_mid"); ensure!(!rfc724_mid.is_empty(), "empty rfc724_mid");
context.sql.query_row( context
"SELECT server_folder, server_uid, id FROM msgs WHERE rfc724_mid=?", .sql
&[rfc724_mid], .query_row(
|row| { "SELECT server_folder, server_uid, id FROM msgs WHERE rfc724_mid=?",
let server_folder = row.get::<_, Option<String>>(0)?.unwrap_or_default(); &[rfc724_mid],
let server_uid = row.get(1)?; |row| {
let msg_id: MsgId = row.get(2)?; let server_folder = row.get::<_, Option<String>>(0)?.unwrap_or_default();
let server_uid = row.get(1)?;
let msg_id: MsgId = row.get(2)?;
Ok((server_folder, server_uid, msg_id)) Ok((server_folder, server_uid, msg_id))
}, },
).map_err(Into::into) )
.map_err(Into::into)
} }
pub fn update_server_uid( pub fn update_server_uid(