Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/chore/conversation-task' into ch…
Browse files Browse the repository at this point in the history
…ore/conversation-task
  • Loading branch information
dariusc93 committed Oct 20, 2023
2 parents 47dcb6d + e44dddb commit ba3f181
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
20 changes: 10 additions & 10 deletions extensions/warp-ipfs/examples/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ")
]);
Expand Down Expand Up @@ -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(" ")
]);
Expand Down Expand Up @@ -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(" ")
]);
Expand Down Expand Up @@ -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(" ")
]);
Expand Down Expand Up @@ -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(" ")
]);
Expand Down Expand Up @@ -1080,35 +1080,35 @@ async fn message_event_handle(
stdout,
"[{}] @> [SPAM!] {}",
username,
message.value().join("\n")
message.lines().join("\n")
)?;
}
None => {
writeln!(
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 => {
writeln!(
stdout,
"[{}] @> {}",
username,
message.value().join("\n")
message.lines().join("\n")
)?;
}
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/warp-ipfs/src/store/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -567,7 +567,7 @@ pub struct MessageDocument {

impl PartialOrd for MessageDocument {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.date.partial_cmp(&other.date)
Some(self.cmp(other))
}
}

Expand Down
1 change: 0 additions & 1 deletion extensions/warp-ipfs/src/store/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion extensions/warp-ipfs/src/store/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl KeyEntry {

impl PartialOrd for KeyEntry {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.id.partial_cmp(&other.id)
Some(self.cmp(other))
}
}

Expand Down
24 changes: 12 additions & 12 deletions extensions/warp-ipfs/src/store/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ impl MessageStore {
}

let lines_value_length: usize = message
.value()
.lines()
.iter()
.map(|s| s.trim())
.filter(|s| !s.is_empty())
Expand All @@ -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::<Vec<_>>()
Expand Down Expand Up @@ -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::<Vec<_>>()
Expand All @@ -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
Expand Down Expand Up @@ -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::<Vec<_>>()
Expand Down Expand Up @@ -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::<Vec<_>>()
Expand Down Expand Up @@ -2604,15 +2604,15 @@ 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 = [
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::<Vec<_>>()
Expand Down Expand Up @@ -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::<Vec<_>>()
Expand Down Expand Up @@ -3330,7 +3330,7 @@ impl Queue {

pub fn spam_check(message: &mut Message, filter: Arc<Option<SpamFilter>>) -> 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());
Expand Down
76 changes: 38 additions & 38 deletions warp/src/raygun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl MessagePage {

impl PartialOrd for MessagePage {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
self.id.partial_cmp(&other.id)
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -530,7 +530,7 @@ pub struct Message {
replied: Option<Uuid>,

/// Message context for `Message`
value: Vec<String>,
lines: Vec<String>,

/// List of Attachment
attachment: Vec<File>,
Expand All @@ -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(),
Expand All @@ -566,7 +566,7 @@ impl Default for Message {

impl PartialOrd for Message {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
self.date.partial_cmp(&other.date)
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -616,8 +616,8 @@ impl Message {
self.reactions.clone()
}

pub fn value(&self) -> Vec<String> {
self.value.clone()
pub fn lines(&self) -> Vec<String> {
self.lines.clone()
}

pub fn attachments(&self) -> Vec<File> {
Expand Down Expand Up @@ -670,8 +670,8 @@ impl Message {
self.reactions = reaction
}

pub fn set_value(&mut self, val: Vec<String>) {
self.value = val
pub fn set_lines(&mut self, val: Vec<String>) {
self.lines = val
}

pub fn set_attachment(&mut self, attachments: Vec<File>) {
Expand Down Expand Up @@ -701,8 +701,8 @@ impl Message {
&mut self.reactions
}

pub fn value_mut(&mut self) -> &mut Vec<String> {
&mut self.value
pub fn lines_mut(&mut self) -> &mut Vec<String> {
&mut self.lines
}

pub fn metadata_mut(&mut self) -> &mut HashMap<String, String> {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()))
}
Expand Down Expand Up @@ -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(
Expand All @@ -1749,8 +1749,8 @@ pub mod ffi {
.collect()
}

fn convert_timstamp(timestamp: i64) -> Option<DateTime<Utc>> {
NaiveDateTime::from_timestamp_opt(timestamp, 0)
.map(|naive| DateTime::<Utc>::from_naive_utc_and_offset(naive, Utc))
}
// fn convert_timstamp(timestamp: i64) -> Option<DateTime<Utc>> {
// NaiveDateTime::from_timestamp_opt(timestamp, 0)
// .map(|naive| DateTime::<Utc>::from_naive_utc_and_offset(naive, Utc))
// }
}

0 comments on commit ba3f181

Please sign in to comment.