mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-21 18:40:19 +00:00
wip: fix thread id mapping
This commit is contained in:
parent
b773218c94
commit
16d273febc
2 changed files with 95 additions and 14 deletions
|
@ -25,7 +25,7 @@ use email::{
|
|||
list::{ListEnvelopes, ListEnvelopesOptions},
|
||||
thread::ThreadEnvelopes,
|
||||
watch::WatchEnvelopes,
|
||||
Id, SingleId, ThreadedEnvelopes,
|
||||
Id, SingleId,
|
||||
},
|
||||
flag::{add::AddFlags, remove::RemoveFlags, set::SetFlags, Flag, Flags},
|
||||
folder::{
|
||||
|
@ -46,7 +46,11 @@ use email::{
|
|||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{account::config::TomlAccountConfig, cache::IdMapper, envelope::Envelopes};
|
||||
use crate::{
|
||||
account::config::TomlAccountConfig,
|
||||
cache::IdMapper,
|
||||
envelope::{Envelopes, ThreadedEnvelopes},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
|
@ -713,8 +717,7 @@ impl Backend {
|
|||
let backend_kind = self.toml_account_config.thread_envelopes_kind();
|
||||
let id_mapper = self.build_id_mapper(folder, backend_kind)?;
|
||||
let envelopes = self.backend.thread_envelopes(folder, opts).await?;
|
||||
// let envelopes =
|
||||
// Envelopes::from_backend(&self.backend.account_config, &id_mapper, envelopes)?;
|
||||
let envelopes = ThreadedEnvelopes::try_from_backend(&id_mapper, envelopes)?;
|
||||
Ok(envelopes)
|
||||
}
|
||||
|
||||
|
@ -726,12 +729,12 @@ impl Backend {
|
|||
) -> Result<ThreadedEnvelopes> {
|
||||
let backend_kind = self.toml_account_config.thread_envelopes_kind();
|
||||
let id_mapper = self.build_id_mapper(folder, backend_kind)?;
|
||||
let id = id_mapper.get_id(id)?;
|
||||
let envelopes = self
|
||||
.backend
|
||||
.thread_envelope(folder, SingleId::from(id), opts)
|
||||
.await?;
|
||||
// let envelopes =
|
||||
// Envelopes::from_backend(&self.backend.account_config, &id_mapper, envelopes)?;
|
||||
let envelopes = ThreadedEnvelopes::try_from_backend(&id_mapper, envelopes)?;
|
||||
Ok(envelopes)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,13 +6,10 @@ pub mod flag;
|
|||
use color_eyre::Result;
|
||||
use comfy_table::{presets, Attribute, Cell, ContentArrangement, Row, Table};
|
||||
use crossterm::{cursor, style::Stylize, terminal};
|
||||
use email::{
|
||||
account::config::AccountConfig,
|
||||
envelope::{ThreadedEnvelope, ThreadedEnvelopes},
|
||||
};
|
||||
use email::{account::config::AccountConfig, envelope::ThreadedEnvelope};
|
||||
use petgraph::graphmap::DiGraphMap;
|
||||
use serde::{Serialize, Serializer};
|
||||
use std::{fmt, ops::Deref, sync::Arc};
|
||||
use std::{collections::HashMap, fmt, ops::Deref, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
cache::IdMapper,
|
||||
|
@ -156,7 +153,6 @@ impl From<&Envelope> for Row {
|
|||
}
|
||||
}
|
||||
|
||||
/// Represents the list of envelopes.
|
||||
#[derive(Clone, Debug, Default, Serialize)]
|
||||
pub struct Envelopes(Vec<Envelope>);
|
||||
|
||||
|
@ -261,6 +257,80 @@ impl Serialize for EnvelopesTable {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ThreadedEnvelopes(email::envelope::ThreadedEnvelopes);
|
||||
|
||||
impl ThreadedEnvelopes {
|
||||
pub fn try_from_backend(
|
||||
id_mapper: &IdMapper,
|
||||
envelopes: email::envelope::ThreadedEnvelopes,
|
||||
) -> Result<ThreadedEnvelopes> {
|
||||
let prev_edges = envelopes
|
||||
.graph()
|
||||
.all_edges()
|
||||
.map(|(a, b, w)| {
|
||||
let a = id_mapper.get_or_create_alias(&a.id)?;
|
||||
let b = id_mapper.get_or_create_alias(&b.id)?;
|
||||
Ok((a, b, *w))
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
let envelopes = envelopes
|
||||
.map()
|
||||
.iter()
|
||||
.map(|(_, envelope)| {
|
||||
let id = id_mapper.get_or_create_alias(&envelope.id)?;
|
||||
let envelope = email::envelope::Envelope {
|
||||
id: id.clone(),
|
||||
message_id: envelope.message_id.clone(),
|
||||
in_reply_to: envelope.in_reply_to.clone(),
|
||||
flags: envelope.flags.clone(),
|
||||
subject: envelope.subject.clone(),
|
||||
from: envelope.from.clone(),
|
||||
to: envelope.to.clone(),
|
||||
date: envelope.date.clone(),
|
||||
};
|
||||
|
||||
Ok((id, envelope))
|
||||
})
|
||||
.collect::<Result<HashMap<_, _>>>()?;
|
||||
|
||||
let envelopes = email::envelope::ThreadedEnvelopes::build(envelopes, move |envelopes| {
|
||||
let mut graph = DiGraphMap::<ThreadedEnvelope, u8>::new();
|
||||
|
||||
for (a, b, w) in prev_edges.clone() {
|
||||
let eb = envelopes.get(&b).unwrap();
|
||||
match envelopes.get(&a) {
|
||||
Some(ea) => {
|
||||
graph.add_edge(ea.as_threaded(), eb.as_threaded(), w);
|
||||
}
|
||||
None => {
|
||||
let ea = ThreadedEnvelope {
|
||||
id: "0",
|
||||
message_id: "0",
|
||||
subject: "",
|
||||
from: "",
|
||||
date: Default::default(),
|
||||
};
|
||||
graph.add_edge(ea, eb.as_threaded(), w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
graph
|
||||
});
|
||||
|
||||
Ok(ThreadedEnvelopes(envelopes))
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for ThreadedEnvelopes {
|
||||
type Target = email::envelope::ThreadedEnvelopes;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnvelopesTree {
|
||||
config: Arc<AccountConfig>,
|
||||
envelopes: ThreadedEnvelopes,
|
||||
|
@ -339,7 +409,7 @@ impl fmt::Display for EnvelopesTree {
|
|||
EnvelopesTree::fmt(
|
||||
f,
|
||||
&self.config,
|
||||
self.envelopes.graph(),
|
||||
self.envelopes.0.graph(),
|
||||
ThreadedEnvelope {
|
||||
id: "0",
|
||||
message_id: "0",
|
||||
|
@ -358,6 +428,14 @@ impl Serialize for EnvelopesTree {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.envelopes.serialize(serializer)
|
||||
self.envelopes.0.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for EnvelopesTree {
|
||||
type Target = ThreadedEnvelopes;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.envelopes
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue