diff --git a/src/dc_msg.rs b/src/dc_msg.rs index 586092375..180683c65 100644 --- a/src/dc_msg.rs +++ b/src/dc_msg.rs @@ -436,9 +436,6 @@ pub unsafe fn dc_msg_get_timestamp(msg: *const dc_msg_t) -> i64 { }; } -//pub fn dc_msg_load_from_db_r(context: &'a Context, id: u32) -> Result { -//} - pub fn dc_msg_load_from_db<'a>(msg: *mut dc_msg_t<'a>, context: &'a Context, id: u32) -> bool { if msg.is_null() { return false; @@ -475,13 +472,19 @@ pub fn dc_msg_load_from_db<'a>(msg: *mut dc_msg_t<'a>, context: &'a Context, id: (*msg).type_0 = row.get(12)?; (*msg).state = row.get(13)?; (*msg).is_dc_message = row.get(14)?; - (*msg).text = Some(match row.get(15) { - Ok(text) => text, - Err(e) => { - warn!(context, 0, "dc_msg_load_from_db: could not get text column for id {} because of {}", id, e); - "[ Could not read from db ]".to_string() + let text; + if let rusqlite::types::ValueRef::Text(buf) = row.get_raw(15) { + if let Ok(t) = String::from_utf8(buf.to_vec()) { + text = t; + } else { + warn!(context, 0, "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 { + warn!(context, 0, "dc_msg_load_from_db: could not get text column for id {}", id); + text = "[ Could not read from db ]".to_string() + } + (*msg).text = Some(text); (*msg).param = row.get::<_, String>(16)?.parse().unwrap_or_default(); (*msg).starred = row.get(17)?; (*msg).hidden = row.get(18)?; @@ -497,7 +500,7 @@ pub fn dc_msg_load_from_db<'a>(msg: *mut dc_msg_t<'a>, context: &'a Context, id: free(ptr.cast()); } }; - Ok(()) + Ok(()) } });