Commit 91c31374 authored by mairandomness's avatar mairandomness

trade some unwrap for unwrap_or_default

parent 6c68fd2d
Pipeline #64897 passed with stages
in 24 minutes and 59 seconds
......@@ -466,7 +466,7 @@ pub fn set_room_avatar(bk: &Backend, roomid: &str, avatar: &str) -> Result<(), E
pub fn attach_file(bk: &Backend, mut msg: Message) -> Result<(), Error> {
let fname = msg.url.clone().unwrap_or_default();
let mut extra_content: ExtraContent =
serde_json::from_value(msg.clone().extra_content.unwrap()).unwrap();
serde_json::from_value(msg.clone().extra_content.unwrap_or_default()).unwrap_or_default();
let thumb = extra_content.info.thumbnail_url.clone().unwrap_or_default();
let tx = bk.tx.clone();
......@@ -487,7 +487,8 @@ pub fn attach_file(bk: &Backend, mut msg: Message) -> Result<(), Error> {
Ok(thumb_uri) => {
msg.thumb = Some(thumb_uri.to_string());
extra_content.info.thumbnail_url = Some(thumb_uri);
msg.extra_content = Some(serde_json::to_value(&extra_content).unwrap());
msg.extra_content =
Some(serde_json::to_value(&extra_content).unwrap_or_default());
}
}
if let Err(_e) = std::fs::remove_file(&thumb) {
......
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Info {
pub thumbnail_url: Option<String>,
pub thumbnail_info: Option<JsonValue>,
......@@ -12,7 +12,7 @@ pub struct Info {
pub orientation: Option<i32>,
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct ExtraContent {
pub info: Info,
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment