melib/jmap: move JmapSession to its own module

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/279/head
Manos Pitsidianakis 10 months ago
parent 29fd8522e6
commit b95f778335
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -28,7 +28,7 @@ use crate::error::NetworkErrorKind;
#[derive(Debug)] #[derive(Debug)]
pub struct JmapConnection { pub struct JmapConnection {
pub session: Arc<Mutex<JmapSession>>, pub session: Arc<Mutex<Session>>,
pub request_no: Arc<Mutex<usize>>, pub request_no: Arc<Mutex<usize>>,
pub client: Arc<HttpClient>, pub client: Arc<HttpClient>,
pub server_conf: JmapServerConf, pub server_conf: JmapServerConf,
@ -153,7 +153,7 @@ impl JmapConnection {
Ok(s) => s, Ok(s) => s,
}; };
let session: JmapSession = match deserialize_from_str(&res_text) { let session: Session = match deserialize_from_str(&res_text) {
Err(err) => { Err(err) => {
let err = Error::new(format!( let err = Error::new(format!(
"Could not connect to JMAP server endpoint for {}. Is your server url setting \ "Could not connect to JMAP server endpoint for {}. Is your server url setting \
@ -211,7 +211,7 @@ impl JmapConnection {
self.session.lock().unwrap().primary_accounts[JMAP_MAIL_CAPABILITY].clone() self.session.lock().unwrap().primary_accounts[JMAP_MAIL_CAPABILITY].clone()
} }
pub fn session_guard(&'_ self) -> MutexGuard<'_, JmapSession> { pub fn session_guard(&'_ self) -> MutexGuard<'_, Session> {
self.session.lock().unwrap() self.session.lock().unwrap()
} }

@ -79,6 +79,9 @@ use connection::*;
pub mod protocol; pub mod protocol;
use protocol::*; use protocol::*;
pub mod session;
use session::*;
pub mod rfc8620; pub mod rfc8620;
use rfc8620::*; use rfc8620::*;
@ -197,7 +200,7 @@ pub struct Store {
pub mailbox_state: Arc<Mutex<State<MailboxObject>>>, pub mailbox_state: Arc<Mutex<State<MailboxObject>>>,
pub online_status: Arc<FutureMutex<(Instant, Result<()>)>>, pub online_status: Arc<FutureMutex<(Instant, Result<()>)>>,
pub is_subscribed: Arc<IsSubscribedFn>, pub is_subscribed: Arc<IsSubscribedFn>,
pub core_capabilities: Arc<Mutex<IndexMap<String, rfc8620::CapabilitiesObject>>>, pub core_capabilities: Arc<Mutex<IndexMap<String, CapabilitiesObject>>>,
pub event_consumer: BackendEventConsumer, pub event_consumer: BackendEventConsumer,
} }

@ -22,16 +22,16 @@
use std::{ use std::{
hash::{Hash, Hasher}, hash::{Hash, Hasher},
marker::PhantomData, marker::PhantomData,
sync::Arc,
}; };
use indexmap::IndexMap;
use serde::{ use serde::{
de::DeserializeOwned, de::DeserializeOwned,
ser::{Serialize, SerializeStruct, Serializer}, ser::{Serialize, SerializeStruct, Serializer},
}; };
use serde_json::{value::RawValue, Value}; use serde_json::{value::RawValue, Value};
use crate::email::parser::BytesExt; use crate::{email::parser::BytesExt, jmap::session::Session};
mod filters; mod filters;
pub use filters::*; pub use filters::*;
@ -39,8 +39,6 @@ mod comparator;
pub use comparator::*; pub use comparator::*;
mod argument; mod argument;
pub use argument::*; pub use argument::*;
use indexmap::IndexMap;
pub type PatchObject = Value; pub type PatchObject = Value;
impl Object for PatchObject { impl Object for PatchObject {
@ -230,48 +228,6 @@ impl<OBJ> State<OBJ> {
} }
} }
#[derive(Deserialize, Serialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct JmapSession {
pub capabilities: IndexMap<String, CapabilitiesObject>,
pub accounts: IndexMap<Id<Account>, Account>,
pub primary_accounts: IndexMap<String, Id<Account>>,
pub username: String,
pub api_url: Arc<String>,
pub download_url: Arc<String>,
pub upload_url: Arc<String>,
pub event_source_url: Arc<String>,
pub state: State<JmapSession>,
#[serde(flatten)]
pub extra_properties: IndexMap<String, Value>,
}
impl Object for JmapSession {
const NAME: &'static str = "Session";
}
#[derive(Deserialize, Serialize, Clone, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CapabilitiesObject {
#[serde(default)]
pub max_size_upload: u64,
#[serde(default)]
pub max_concurrent_upload: u64,
#[serde(default)]
pub max_size_request: u64,
#[serde(default)]
pub max_concurrent_requests: u64,
#[serde(default)]
pub max_calls_in_request: u64,
#[serde(default)]
pub max_objects_in_get: u64,
#[serde(default)]
pub max_objects_in_set: u64,
#[serde(default)]
pub collation_algorithms: Vec<String>,
}
#[derive(Deserialize, Serialize, Clone, Debug)] #[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Account { pub struct Account {
@ -284,7 +240,7 @@ pub struct Account {
} }
impl Object for Account { impl Object for Account {
const NAME: &'static str = "Account"; const NAME: &'static str = stringify!(Account);
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -441,7 +397,7 @@ pub struct MethodResponse<'a> {
#[serde(default)] #[serde(default)]
pub created_ids: IndexMap<Id<String>, Id<String>>, pub created_ids: IndexMap<Id<String>, Id<String>>,
#[serde(default)] #[serde(default)]
pub session_state: State<JmapSession>, pub session_state: State<Session>,
} }
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]

@ -0,0 +1,69 @@
/*
* meli - jmap module.
*
* Copyright 2019 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
use std::sync::Arc;
use indexmap::IndexMap;
use serde_json::Value;
use crate::jmap::rfc8620::{Account, Id, Object, State};
#[derive(Deserialize, Serialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct Session {
pub capabilities: IndexMap<String, CapabilitiesObject>,
pub accounts: IndexMap<Id<Account>, Account>,
pub primary_accounts: IndexMap<String, Id<Account>>,
pub username: String,
pub api_url: Arc<String>,
pub download_url: Arc<String>,
pub upload_url: Arc<String>,
pub event_source_url: Arc<String>,
pub state: State<Session>,
#[serde(flatten)]
pub extra_properties: IndexMap<String, Value>,
}
impl Object for Session {
const NAME: &'static str = stringify!(Session);
}
#[derive(Deserialize, Serialize, Clone, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CapabilitiesObject {
#[serde(default)]
pub max_size_upload: u64,
#[serde(default)]
pub max_concurrent_upload: u64,
#[serde(default)]
pub max_size_request: u64,
#[serde(default)]
pub max_concurrent_requests: u64,
#[serde(default)]
pub max_calls_in_request: u64,
#[serde(default)]
pub max_objects_in_get: u64,
#[serde(default)]
pub max_objects_in_set: u64,
#[serde(default)]
pub collation_algorithms: Vec<String>,
}
Loading…
Cancel
Save