Fix building the Messages in getMessage

This commit is contained in:
2021-12-16 18:13:21 +01:00
parent 7109a06b0c
commit f13f55224b
2 changed files with 73 additions and 41 deletions

View File

@@ -478,6 +478,17 @@ pub enum MsgType {
Text = 0,
}
impl TryFrom<u8> for MsgType {
type Error = String;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::Text),
_ => Err("Unknown MessageType".to_string()),
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct Query;
@@ -617,13 +628,12 @@ impl Query {
sender: message.try_get::<String, _>("sender_id")?.into(),
msg_type: message.try_get::<u8,_>("msg_type")?.try_into()?,
content: message.try_get("content")?,
hide_for: message.try_get("hide_for")?
hide_for: message.try_get::<Option<String>, _>("hide_for")?
.map(|array| from_sql_formatted_array(array, "hide_for"))
.transpose()?
.map(|u: String| u.into())
.collect(),
.map(|iter| iter.map(|u: String| u.into()).collect()),
seen_by: from_sql_formatted_array(message.try_get("seen_by")?, "seen_by")?
.map(|s| s.into())
.map(|s: String| s.into())
.collect(),
});
}