|
@@ -11,8 +11,8 @@ use crate::models::{MailAddress, StrMessage};
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct SerializableThread{
|
|
pub struct SerializableThread{
|
|
- id: u32,
|
|
|
|
- messages: Vec<String>
|
|
|
|
|
|
+ pub id: u32,
|
|
|
|
+ pub messages: Vec<String>
|
|
}
|
|
}
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
@@ -173,21 +173,24 @@ impl Indexes {
|
|
|
|
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
-
|
|
|
|
- pub fn group_threads_by_subject(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<HashMap<String, Vec<u32>>>{
|
|
|
|
|
|
+
|
|
|
|
+ pub fn group_threads_by_subject(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<Vec<(String, Vec<u32>)>>{
|
|
let threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let mut map: HashMap<String, Vec<u32>> = HashMap::new();
|
|
let mut map: HashMap<String, Vec<u32>> = HashMap::new();
|
|
|
|
|
|
for thread in threads_for_list {
|
|
for thread in threads_for_list {
|
|
- map.entry(Self::get_last_from_list_from_thread(&thread, list.clone(), messages).unwrap().subject)
|
|
|
|
|
|
+ map.entry(Self::get_last_from_list_from_thread(&thread, list.clone(), messages).unwrap().subject.trim().to_string())
|
|
.or_insert_with(Vec::new)
|
|
.or_insert_with(Vec::new)
|
|
.push(thread.id);
|
|
.push(thread.id);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ let mut sorted_vec: Vec<(String, Vec<u32>)> = map.into_iter().collect();
|
|
|
|
+ sorted_vec.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
|
|
|
- Ok(map)
|
|
|
|
|
|
+ Ok(sorted_vec)
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn group_threads_by_date(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<HashMap<NaiveDate, Vec<u32>>> {
|
|
|
|
|
|
+ pub fn group_threads_by_date(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<Vec<(NaiveDate, Vec<u32>)>> {
|
|
let threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let mut map: HashMap<NaiveDate, Vec<(DateTime<Utc>, u32)>> = HashMap::new();
|
|
let mut map: HashMap<NaiveDate, Vec<(DateTime<Utc>, u32)>> = HashMap::new();
|
|
|
|
|
|
@@ -207,11 +210,14 @@ impl Indexes {
|
|
(date, sorted_ids)
|
|
(date, sorted_ids)
|
|
})
|
|
})
|
|
.collect();
|
|
.collect();
|
|
-
|
|
|
|
- Ok(sorted_map)
|
|
|
|
|
|
+
|
|
|
|
+ let mut sorted_vec: Vec<(NaiveDate, Vec<u32>)> = sorted_map.into_iter().collect();
|
|
|
|
+ sorted_vec.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
|
+
|
|
|
|
+ Ok(sorted_vec)
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn group_threads_by_sender(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<HashMap<String, Vec<u32>>>{
|
|
|
|
|
|
+ pub fn group_threads_by_sender(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<Vec<(String, Vec<u32>)>>{
|
|
let mut threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let mut threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let mut map: HashMap<String, Vec<u32>> = HashMap::new();
|
|
let mut map: HashMap<String, Vec<u32>> = HashMap::new();
|
|
|
|
|
|
@@ -221,10 +227,13 @@ impl Indexes {
|
|
.push(thread.id);
|
|
.push(thread.id);
|
|
}
|
|
}
|
|
|
|
|
|
- Ok(map)
|
|
|
|
|
|
+ let mut sorted_vec: Vec<(String, Vec<u32>)> = map.into_iter().collect();
|
|
|
|
+ sorted_vec.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
|
+
|
|
|
|
+ Ok(sorted_vec)
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn group_threads_by_receiver(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<HashMap<String, Vec<u32>>>{
|
|
|
|
|
|
+ pub fn group_threads_by_receiver(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<Vec<(String, Vec<u32>)>>{
|
|
let mut threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let mut threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let mut map: HashMap<String, Vec<u32>> = HashMap::new();
|
|
let mut map: HashMap<String, Vec<u32>> = HashMap::new();
|
|
|
|
|
|
@@ -236,10 +245,13 @@ impl Indexes {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- Ok(map)
|
|
|
|
|
|
+ let mut sorted_vec: Vec<(String, Vec<u32>)> = map.into_iter().collect();
|
|
|
|
+ sorted_vec.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
|
+
|
|
|
|
+ Ok(sorted_vec)
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn group_threads_by_cc(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<HashMap<String, Vec<u32>>>{
|
|
|
|
|
|
+ pub fn group_threads_by_cc(mut threads: &mut Vec<SerializableThread>, list: String, messages: &mut Vec<SerializableMessage>) -> anyhow::Result<Vec<(String, Vec<u32>)>>{
|
|
let mut threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let mut threads_for_list = Self::get_threads_for_list(list.clone(), threads, messages);
|
|
let mut map: HashMap<String, Vec<u32>> = HashMap::new();
|
|
let mut map: HashMap<String, Vec<u32>> = HashMap::new();
|
|
|
|
|
|
@@ -251,7 +263,10 @@ impl Indexes {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- Ok(map)
|
|
|
|
|
|
+ let mut sorted_vec: Vec<(String, Vec<u32>)> = map.into_iter().collect();
|
|
|
|
+ sorted_vec.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
|
+
|
|
|
|
+ Ok(sorted_vec)
|
|
}
|
|
}
|
|
|
|
|
|
fn get_threads_for_list(list: String, mut threads: &mut Vec<SerializableThread>, messages: &mut Vec<SerializableMessage>) -> Vec<SerializableThread>{
|
|
fn get_threads_for_list(list: String, mut threads: &mut Vec<SerializableThread>, messages: &mut Vec<SerializableMessage>) -> Vec<SerializableThread>{
|