add more ser and de impls

This commit is contained in:
dignifiedquire
2020-02-11 23:22:55 +01:00
committed by holger krekel
parent beb91271de
commit 9cc99ffcd6
6 changed files with 491 additions and 513 deletions

918
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -28,7 +28,9 @@ use crate::stock::StockMessage;
/// ///
/// Some chat IDs are reserved to identify special chat types. This /// Some chat IDs are reserved to identify special chat types. This
/// type can represent both the special as well as normal chats. /// type can represent both the special as well as normal chats.
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] #[derive(
Debug, Copy, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Hash, PartialOrd, Ord,
)]
pub struct ChatId(u32); pub struct ChatId(u32);
impl ChatId { impl ChatId {
@@ -414,7 +416,7 @@ impl rusqlite::types::FromSql for ChatId {
/// Chat objects are created using eg. `Chat::load_from_db` /// Chat objects are created using eg. `Chat::load_from_db`
/// and are not updated on database changes; /// and are not updated on database changes;
/// if you want an update, you have to recreate the object. /// if you want an update, you have to recreate the object.
#[derive(Debug, Clone)] #[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Chat { pub struct Chat {
pub id: ChatId, pub id: ChatId,
pub typ: Chattype, pub typ: Chattype,

View File

@@ -278,8 +278,8 @@ impl Chatlist {
// This is because we may want to display drafts here or stuff as // This is because we may want to display drafts here or stuff as
// "is typing". // "is typing".
// Also, sth. as "No messages" would not work if the summary comes from a message. // Also, sth. as "No messages" would not work if the summary comes from a message.
let mut ret = Lot::new(); let mut ret = Lot::new();
if index >= self.ids.len() { if index >= self.ids.len() {
ret.text2 = Some("ErrBadChatlistIndex".to_string()); ret.text2 = Some("ErrBadChatlistIndex".to_string());
return ret; return ret;
@@ -321,6 +321,10 @@ impl Chatlist {
ret ret
} }
pub fn get_index_for_id(&self, id: ChatId) -> Option<usize> {
self.ids.iter().position(|(chat_id, _)| chat_id == &id)
}
} }
/// Returns the number of archived chats /// Returns the number of archived chats

View File

@@ -3,6 +3,7 @@
use deltachat_derive::*; use deltachat_derive::*;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
lazy_static! { lazy_static! {
pub static ref DC_VERSION_STR: String = env!("CARGO_PKG_VERSION").to_string(); pub static ref DC_VERSION_STR: String = env!("CARGO_PKG_VERSION").to_string();
@@ -15,7 +16,20 @@ const DC_SENTBOX_WATCH_DEFAULT: i32 = 1;
const DC_MVBOX_WATCH_DEFAULT: i32 = 1; const DC_MVBOX_WATCH_DEFAULT: i32 = 1;
const DC_MVBOX_MOVE_DEFAULT: i32 = 1; const DC_MVBOX_MOVE_DEFAULT: i32 = 1;
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql)] #[derive(
Debug,
Display,
Clone,
Copy,
PartialEq,
Eq,
FromPrimitive,
ToPrimitive,
FromSql,
ToSql,
Serialize,
Deserialize,
)]
#[repr(u8)] #[repr(u8)]
pub enum Blocked { pub enum Blocked {
Not = 0, Not = 0,
@@ -90,6 +104,8 @@ pub const DC_CHAT_ID_LAST_SPECIAL: u32 = 9;
FromSql, FromSql,
ToSql, ToSql,
IntoStaticStr, IntoStaticStr,
Serialize,
Deserialize,
)] )]
#[repr(u32)] #[repr(u32)]
pub enum Chattype { pub enum Chattype {
@@ -185,7 +201,20 @@ pub const DC_BOB_SUCCESS: i32 = 1;
// max. width/height of an avatar // max. width/height of an avatar
pub const AVATAR_SIZE: u32 = 192; pub const AVATAR_SIZE: u32 = 192;
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql)] #[derive(
Debug,
Display,
Clone,
Copy,
PartialEq,
Eq,
FromPrimitive,
ToPrimitive,
FromSql,
ToSql,
Serialize,
Deserialize,
)]
#[repr(i32)] #[repr(i32)]
pub enum Viewtype { pub enum Viewtype {
Unknown = 0, Unknown = 0,

View File

@@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
use deltachat_derive::{FromSql, ToSql}; use deltachat_derive::{FromSql, ToSql};
use failure::Fail; use failure::Fail;
use serde::{Deserialize, Serialize};
use crate::chat::{self, Chat, ChatId}; use crate::chat::{self, Chat, ChatId};
use crate::constants::*; use crate::constants::*;
@@ -29,7 +30,9 @@ const SUMMARY_CHARACTERS: usize = 160;
/// Some message IDs are reserved to identify special message types. /// Some message IDs are reserved to identify special message types.
/// This type can represent both the special as well as normal /// This type can represent both the special as well as normal
/// messages. /// messages.
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)] #[derive(
Debug, Copy, Clone, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize,
)]
pub struct MsgId(u32); pub struct MsgId(u32);
impl MsgId { impl MsgId {
@@ -145,7 +148,18 @@ impl rusqlite::types::FromSql for MsgId {
#[fail(display = "Invalid Message ID.")] #[fail(display = "Invalid Message ID.")]
pub struct InvalidMsgId; pub struct InvalidMsgId;
#[derive(Debug, Copy, Clone, PartialEq, FromPrimitive, ToPrimitive, FromSql, ToSql)] #[derive(
Debug,
Copy,
Clone,
PartialEq,
FromPrimitive,
ToPrimitive,
FromSql,
ToSql,
Serialize,
Deserialize,
)]
#[repr(u8)] #[repr(u8)]
pub enum MessengerMessage { pub enum MessengerMessage {
No = 0, No = 0,
@@ -168,7 +182,7 @@ impl Default for MessengerMessage {
/// to check if a mail was sent, use dc_msg_is_sent() /// to check if a mail was sent, use dc_msg_is_sent()
/// approx. max. length returned by dc_msg_get_text() /// approx. max. length returned by dc_msg_get_text()
/// approx. max. length returned by dc_get_msg_info() /// approx. max. length returned by dc_get_msg_info()
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Message { pub struct Message {
pub(crate) id: MsgId, pub(crate) id: MsgId,
pub(crate) from_id: u32, pub(crate) from_id: u32,
@@ -607,7 +621,19 @@ impl Message {
} }
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, ToSql, FromSql)] #[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
FromPrimitive,
ToPrimitive,
ToSql,
FromSql,
Serialize,
Deserialize,
)]
#[repr(i32)] #[repr(i32)]
pub enum MessageState { pub enum MessageState {
Undefined = 0, Undefined = 0,

View File

@@ -4,6 +4,7 @@ use std::path::PathBuf;
use std::str; use std::str;
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
use serde::{Deserialize, Serialize};
use crate::blob::{BlobError, BlobObject}; use crate::blob::{BlobError, BlobObject};
use crate::context::Context; use crate::context::Context;
@@ -12,7 +13,9 @@ use crate::message::MsgId;
use crate::mimeparser::SystemMessage; use crate::mimeparser::SystemMessage;
/// Available param keys. /// Available param keys.
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash, PartialOrd, Ord, FromPrimitive)] #[derive(
PartialEq, Eq, Debug, Clone, Copy, Hash, PartialOrd, Ord, FromPrimitive, Serialize, Deserialize,
)]
#[repr(u8)] #[repr(u8)]
pub enum Param { pub enum Param {
/// For messages and jobs /// For messages and jobs
@@ -135,7 +138,7 @@ pub enum ForcePlaintext {
/// The structure is serialized by calling `to_string()` on it. /// The structure is serialized by calling `to_string()` on it.
/// ///
/// Only for library-internal use. /// Only for library-internal use.
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct Params { pub struct Params {
inner: BTreeMap<Param, String>, inner: BTreeMap<Param, String>,
} }