diff --git a/Cargo.toml b/Cargo.toml index 9d8995a6a..1668f1080 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,7 @@ cfg-if = "1.0" once_cell = "1.16" # Time crate -chrono = { version = "0.4" } +chrono = { version = "~0.4.27" } # Encoding and Serializing Crates serde = { version = "1.0", features = ["derive", "rc"] } diff --git a/extensions/warp-ipfs/examples/messenger.rs b/extensions/warp-ipfs/examples/messenger.rs index 04608c2a1..5f301c6f3 100644 --- a/extensions/warp-ipfs/examples/messenger.rs +++ b/extensions/warp-ipfs/examples/messenger.rs @@ -513,7 +513,7 @@ async fn main() -> anyhow::Result<()> { &message.date().to_string(), &message.modified().map(|d| d.to_string()).unwrap_or_else(|| "N/A".into()), &username, - &message.value().join("\n"), + &message.lines().join("\n"), &format!("{}", message.pinned()), &emojis.join(" ") ]); @@ -581,7 +581,7 @@ async fn main() -> anyhow::Result<()> { &message.date().to_string(), &message.modified().map(|d| d.to_string()).unwrap_or_else(|| "N/A".into()), &username, - &message.value().join("\n"), + &message.lines().join("\n"), &format!("{}", message.pinned()), &emojis.join(" ") ]); @@ -616,7 +616,7 @@ async fn main() -> anyhow::Result<()> { &message.date().to_string(), &message.modified().map(|d| d.to_string()).unwrap_or_else(|| "N/A".into()), &username, - &message.value().join("\n"), + &message.lines().join("\n"), &format!("{}", message.pinned()), &emojis.join(" ") ]); @@ -648,7 +648,7 @@ async fn main() -> anyhow::Result<()> { &message.date().to_string(), &message.modified().map(|d| d.to_string()).unwrap_or_else(|| "N/A".into()), &username, - &message.value().join("\n"), + &message.lines().join("\n"), &format!("{}", message.pinned()), &emojis.join(" ") ]); @@ -689,7 +689,7 @@ async fn main() -> anyhow::Result<()> { &message.date().to_string(), &message.modified().map(|d| d.to_string()).unwrap_or_else(|| "N/A".into()), &username, - &message.value().join("\n"), + &message.lines().join("\n"), &format!("{}", message.pinned()), &emojis.join(" ") ]); @@ -1080,7 +1080,7 @@ async fn message_event_handle( stdout, "[{}] @> [SPAM!] {}", username, - message.value().join("\n") + message.lines().join("\n") )?; } None => { @@ -1088,19 +1088,19 @@ async fn message_event_handle( stdout, "[{}] @> {}", username, - message.value().join("\n") + message.lines().join("\n") )?; } }, MessageType::Attachment => { - if !message.value().is_empty() { + if !message.lines().is_empty() { match message.metadata().get("is_spam") { Some(_) => { writeln!( stdout, "[{}] @> [SPAM!] {}", username, - message.value().join("\n") + message.lines().join("\n") )?; } None => { @@ -1108,7 +1108,7 @@ async fn message_event_handle( stdout, "[{}] @> {}", username, - message.value().join("\n") + message.lines().join("\n") )?; } } diff --git a/extensions/warp-ipfs/src/store/conversation.rs b/extensions/warp-ipfs/src/store/conversation.rs index b90452406..fb69b773a 100644 --- a/extensions/warp-ipfs/src/store/conversation.rs +++ b/extensions/warp-ipfs/src/store/conversation.rs @@ -382,7 +382,7 @@ impl ConversationDocument { } let should_yield = if let Some(keyword) = option.keyword() { message - .value() + .lines() .iter() .any(|line| line.to_lowercase().contains(&keyword.to_lowercase())) } else { @@ -567,7 +567,7 @@ pub struct MessageDocument { impl PartialOrd for MessageDocument { fn partial_cmp(&self, other: &Self) -> Option { - self.date.partial_cmp(&other.date) + Some(self.cmp(other)) } } diff --git a/extensions/warp-ipfs/src/store/identity.rs b/extensions/warp-ipfs/src/store/identity.rs index 10547ca74..832dd35df 100644 --- a/extensions/warp-ipfs/src/store/identity.rs +++ b/extensions/warp-ipfs/src/store/identity.rs @@ -1164,7 +1164,6 @@ impl IdentityStore { if cache.profile_picture == Some(cid) || cache.profile_banner == Some(cid) { tokio::spawn({ - let cid = cid; let mut store = self.clone(); async move { let added_cid = store diff --git a/extensions/warp-ipfs/src/store/keystore.rs b/extensions/warp-ipfs/src/store/keystore.rs index ce15fcbdd..1eaca6a59 100644 --- a/extensions/warp-ipfs/src/store/keystore.rs +++ b/extensions/warp-ipfs/src/store/keystore.rs @@ -135,7 +135,7 @@ impl KeyEntry { impl PartialOrd for KeyEntry { fn partial_cmp(&self, other: &Self) -> Option { - self.id.partial_cmp(&other.id) + Some(self.cmp(other)) } } diff --git a/extensions/warp-ipfs/src/store/message.rs b/extensions/warp-ipfs/src/store/message.rs index 89b0a62b9..8662a4cc8 100644 --- a/extensions/warp-ipfs/src/store/message.rs +++ b/extensions/warp-ipfs/src/store/message.rs @@ -750,7 +750,7 @@ impl MessageStore { } let lines_value_length: usize = message - .value() + .lines() .iter() .map(|s| s.trim()) .filter(|s| !s.is_empty()) @@ -775,7 +775,7 @@ impl MessageStore { message.conversation_id().into_bytes().to_vec(), sender.to_string().as_bytes().to_vec(), message - .value() + .lines() .iter() .map(|s| s.as_bytes()) .collect::>() @@ -859,7 +859,7 @@ impl MessageStore { message.conversation_id().into_bytes().to_vec(), sender.to_string().as_bytes().to_vec(), message - .value() + .lines() .iter() .map(|s| s.as_bytes()) .collect::>() @@ -886,7 +886,7 @@ impl MessageStore { } message.set_signature(Some(signature)); - *message.value_mut() = lines; + *message.lines_mut() = lines; message.set_modified(modified); message_document @@ -923,7 +923,7 @@ impl MessageStore { message.conversation_id().into_bytes().to_vec(), sender.to_string().as_bytes().to_vec(), message - .value() + .lines() .iter() .map(|s| s.as_bytes()) .collect::>() @@ -2472,14 +2472,14 @@ impl MessageStore { let mut message = Message::default(); message.set_conversation_id(conversation.id()); message.set_sender(own_did.clone()); - message.set_value(messages.clone()); + message.set_lines(messages.clone()); let construct = [ message.id().into_bytes().to_vec(), message.conversation_id().into_bytes().to_vec(), own_did.to_string().as_bytes().to_vec(), message - .value() + .lines() .iter() .map(|s| s.as_bytes()) .collect::>() @@ -2604,7 +2604,7 @@ impl MessageStore { let mut message = Message::default(); message.set_conversation_id(conversation.id()); message.set_sender(own_did.clone()); - message.set_value(messages); + message.set_lines(messages); message.set_replied(Some(message_id)); let construct = [ @@ -2612,7 +2612,7 @@ impl MessageStore { message.conversation_id().into_bytes().to_vec(), own_did.to_string().as_bytes().to_vec(), message - .value() + .lines() .iter() .map(|s| s.as_bytes()) .collect::>() @@ -2951,14 +2951,14 @@ impl MessageStore { message.set_conversation_id(conversation.id()); message.set_sender(own_did.clone()); message.set_attachment(attachments); - message.set_value(messages.clone()); + message.set_lines(messages.clone()); message.set_replied(message_id); let construct = [ message.id().into_bytes().to_vec(), message.conversation_id().into_bytes().to_vec(), own_did.to_string().as_bytes().to_vec(), message - .value() + .lines() .iter() .map(|s| s.as_bytes()) .collect::>() @@ -3330,7 +3330,7 @@ impl Queue { pub fn spam_check(message: &mut Message, filter: Arc>) -> anyhow::Result<()> { if let Some(filter) = filter.as_ref() { - if filter.process(&message.value().join(" "))? { + if filter.process(&message.lines().join(" "))? { message .metadata_mut() .insert("is_spam".to_owned(), "true".to_owned()); diff --git a/warp/src/raygun/mod.rs b/warp/src/raygun/mod.rs index f872ab01e..5b3875785 100644 --- a/warp/src/raygun/mod.rs +++ b/warp/src/raygun/mod.rs @@ -377,7 +377,7 @@ impl MessagePage { impl PartialOrd for MessagePage { fn partial_cmp(&self, other: &Self) -> Option { - self.id.partial_cmp(&other.id) + Some(self.cmp(other)) } } @@ -530,7 +530,7 @@ pub struct Message { replied: Option, /// Message context for `Message` - value: Vec, + lines: Vec, /// List of Attachment attachment: Vec, @@ -556,7 +556,7 @@ impl Default for Message { pinned: false, reactions: Vec::new(), replied: None, - value: Vec::new(), + lines: Vec::new(), attachment: Vec::new(), signature: Default::default(), metadata: HashMap::new(), @@ -566,7 +566,7 @@ impl Default for Message { impl PartialOrd for Message { fn partial_cmp(&self, other: &Self) -> Option { - self.date.partial_cmp(&other.date) + Some(self.cmp(other)) } } @@ -616,8 +616,8 @@ impl Message { self.reactions.clone() } - pub fn value(&self) -> Vec { - self.value.clone() + pub fn lines(&self) -> Vec { + self.lines.clone() } pub fn attachments(&self) -> Vec { @@ -670,8 +670,8 @@ impl Message { self.reactions = reaction } - pub fn set_value(&mut self, val: Vec) { - self.value = val + pub fn set_lines(&mut self, val: Vec) { + self.lines = val } pub fn set_attachment(&mut self, attachments: Vec) { @@ -701,8 +701,8 @@ impl Message { &mut self.reactions } - pub fn value_mut(&mut self) -> &mut Vec { - &mut self.value + pub fn lines_mut(&mut self) -> &mut Vec { + &mut self.lines } pub fn metadata_mut(&mut self) -> &mut HashMap { @@ -1015,7 +1015,7 @@ pub mod ffi { EmbedState, FFIResult_FFIVec_Message, FFIVec_Reaction, Message, MessageOptions, PinState, RayGunAdapter, Reaction, ReactionState, }; - use chrono::{DateTime, NaiveDateTime, Utc}; + // use chrono::{DateTime, NaiveDateTime, Utc}; use futures::StreamExt; use std::ffi::{CStr, CString}; use std::os::raw::c_char; @@ -1602,7 +1602,7 @@ pub mod ffi { return std::ptr::null_mut(); } let adapter = &*ctx; - let lines = adapter.value(); + let lines = adapter.lines(); Box::into_raw(Box::new(lines.into())) } @@ -1711,32 +1711,32 @@ pub mod ffi { Box::into_raw(Box::new(opt)) } - #[allow(clippy::missing_safety_doc)] - #[no_mangle] - pub unsafe extern "C" fn messageoptions_set_date_range( - option: *mut MessageOptions, - start: i64, - end: i64, - ) -> *mut MessageOptions { - if option.is_null() { - return std::ptr::null_mut(); - } + // #[allow(clippy::missing_safety_doc)] + // #[no_mangle] + // pub unsafe extern "C" fn messageoptions_set_date_range( + // option: *mut MessageOptions, + // start: i64, + // end: i64, + // ) -> *mut MessageOptions { + // if option.is_null() { + // return std::ptr::null_mut(); + // } - let opt = Box::from_raw(option); + // let opt = Box::from_raw(option); - let start = match convert_timstamp(start) { - Some(s) => s, - None => return std::ptr::null_mut(), - }; - let end = match convert_timstamp(end) { - Some(s) => s, - None => return std::ptr::null_mut(), - }; + // let start = match convert_timstamp(start) { + // Some(s) => s, + // None => return std::ptr::null_mut(), + // }; + // let end = match convert_timstamp(end) { + // Some(s) => s, + // None => return std::ptr::null_mut(), + // }; - let opt = opt.set_date_range(start..end); + // let opt = opt.set_date_range(start..end); - Box::into_raw(Box::new(opt)) - } + // Box::into_raw(Box::new(opt)) + // } #[allow(clippy::missing_safety_doc)] unsafe fn pointer_to_vec( @@ -1749,8 +1749,8 @@ pub mod ffi { .collect() } - fn convert_timstamp(timestamp: i64) -> Option> { - NaiveDateTime::from_timestamp_opt(timestamp, 0) - .map(|naive| DateTime::::from_naive_utc_and_offset(naive, Utc)) - } + // fn convert_timstamp(timestamp: i64) -> Option> { + // NaiveDateTime::from_timestamp_opt(timestamp, 0) + // .map(|naive| DateTime::::from_naive_utc_and_offset(naive, Utc)) + // } }