Added from impls for chat
This commit is contained in:
parent
8f8f229956
commit
639f55a063
|
@ -1,4 +1,4 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use chrono::{DateTime, Utc, TimeZone};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{
|
||||
mysql::{MySqlTypeInfo, MySqlValueRef},
|
||||
|
@ -168,4 +168,23 @@ impl Default for ChatMessageContent {
|
|||
fn default() -> Self {
|
||||
Self::Text(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::client_types::chat_message::ChatMessage> for ChatMessage {
|
||||
fn from(value: crate::client_types::chat_message::ChatMessage) -> Self {
|
||||
Self {
|
||||
id: value.id,
|
||||
from_id: value.from_id,
|
||||
to_id: value.to_id,
|
||||
message: match value.message_content {
|
||||
crate::client_types::chat_message::MessageContentType::Text => ChatMessageContent::Text(String::from_utf8(value.message).unwrap()),
|
||||
crate::client_types::chat_message::MessageContentType::Image => ChatMessageContent::Image(value.message),
|
||||
crate::client_types::chat_message::MessageContentType::Video => ChatMessageContent::Video(value.message),
|
||||
crate::client_types::chat_message::MessageContentType::Audio => ChatMessageContent::Audio(value.message),
|
||||
},
|
||||
time_sent: Utc.timestamp_millis_opt(value.time_sent).unwrap(),
|
||||
time_delivered: TimeSensitiveActionVec { list: value.time_delivered.into_iter().map(|time_delivered| TimeSensitiveAction { time: Utc.timestamp_millis_opt(time_delivered.time).unwrap(), by: time_delivered.by }).collect() },
|
||||
time_seen: TimeSensitiveActionVec { list: value.time_seen.into_iter().map(|time_seen| TimeSensitiveAction { time: Utc.timestamp_millis_opt(time_seen.time).unwrap(), by: time_seen.by }).collect() },
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue