melib/jmap: add last_method_response field to Connection

For book keeping.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/279/head
Manos Pitsidianakis 2023-08-13 14:29:00 +03:00
parent f7a4741bf1
commit c875dda496
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
3 changed files with 10 additions and 5 deletions

View File

@ -33,6 +33,7 @@ pub struct JmapConnection {
pub client: Arc<HttpClient>,
pub server_conf: JmapServerConf,
pub store: Arc<Store>,
pub last_method_response: Option<String>,
}
impl JmapConnection {
@ -73,6 +74,7 @@ impl JmapConnection {
client: Arc::new(client),
server_conf,
store,
last_method_response: None,
})
}

View File

@ -325,7 +325,7 @@ impl MailBackend for JmapType {
let mut fetch_state = protocol::EmailFetchState::Start { batch_size };
loop {
let res = fetch_state.fetch(
&conn,
&mut conn,
&store,
mailbox_hash,
).await?;
@ -383,7 +383,7 @@ impl MailBackend for JmapType {
let mut conn = connection.lock().await;
conn.connect().await?;
if store.mailboxes.read().unwrap().is_empty() {
let new_mailboxes = debug!(protocol::get_mailboxes(&conn).await)?;
let new_mailboxes = debug!(protocol::get_mailboxes(&mut conn).await)?;
*store.mailboxes.write().unwrap() = new_mailboxes;
}

View File

@ -78,7 +78,7 @@ impl Request {
}
}
pub async fn get_mailboxes(conn: &JmapConnection) -> Result<HashMap<MailboxHash, JmapMailbox>> {
pub async fn get_mailboxes(conn: &mut JmapConnection) -> Result<HashMap<MailboxHash, JmapMailbox>> {
let seq = get_request_no!(conn.request_no);
let res_text = conn
.send_request(serde_json::to_string(&json!({
@ -96,6 +96,7 @@ pub async fn get_mailboxes(conn: &JmapConnection) -> Result<HashMap<MailboxHash,
let GetResponse::<MailboxObject> {
list, account_id, ..
} = m;
conn.last_method_response = Some(res_text);
// Is account set as `personal`? (`isPersonal` property). Then, even if
// `isSubscribed` is false on a mailbox, it should be regarded as
// subscribed.
@ -167,7 +168,7 @@ pub async fn get_mailboxes(conn: &JmapConnection) -> Result<HashMap<MailboxHash,
}
pub async fn get_message_list(
conn: &JmapConnection,
conn: &mut JmapConnection,
mailbox: &JmapMailbox,
) -> Result<Vec<Id<EmailObject>>> {
let email_call: EmailQuery = EmailQuery::new(
@ -198,6 +199,7 @@ pub async fn get_message_list(
*conn.store.online_status.lock().await = (std::time::Instant::now(), Ok(()));
let m = QueryResponse::<EmailObject>::try_from(v.method_responses.remove(0))?;
let QueryResponse::<EmailObject> { ids, .. } = m;
conn.last_method_response = Some(res_text);
Ok(ids)
}
@ -268,7 +270,7 @@ impl EmailFetchState {
pub async fn fetch(
&mut self,
conn: &JmapConnection,
conn: &mut JmapConnection,
store: &Store,
mailbox_hash: MailboxHash,
) -> Result<Vec<Envelope>> {
@ -325,6 +327,7 @@ impl EmailFetchState {
let e =
GetResponse::<EmailObject>::try_from(v.method_responses.pop().unwrap())?;
let GetResponse::<EmailObject> { list, state, .. } = e;
conn.last_method_response = Some(res_text);
if self.must_update_state(conn, mailbox_hash, state).await? {
*self = Self::Start { batch_size };