Skip to content

Commit 2b7544d

Browse files
committed
api!: jsonrpc: chat_type now contains a variant of a string
enum/union. Affected places: `FullChat.chat_type`, `BasicChat.chat_type`, `ChatListItemFetchResult::ChatListItem.chat_type`, `Event:: SecurejoinInviterProgress.chat_type` and `MessageSearchResult.chat_type`
1 parent 0bc9fe8 commit 2b7544d

File tree

4 files changed

+48
-12
lines changed

4 files changed

+48
-12
lines changed

deltachat-jsonrpc/src/api/types/chat.rs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use deltachat::chat::{Chat, ChatId};
66
use deltachat::constants::Chattype;
77
use deltachat::contact::{Contact, ContactId};
88
use deltachat::context::Context;
9-
use num_traits::cast::ToPrimitive;
109
use serde::{Deserialize, Serialize};
1110
use typescript_type_def::TypeDef;
1211

@@ -58,7 +57,7 @@ pub struct FullChat {
5857
archived: bool,
5958
pinned: bool,
6059
// subtitle - will be moved to frontend because it uses translation functions
61-
chat_type: u32,
60+
chat_type: JSONRPCChatType,
6261
is_unpromoted: bool,
6362
is_self_talk: bool,
6463
contacts: Vec<ContactObject>,
@@ -136,7 +135,7 @@ impl FullChat {
136135
profile_image, //BLOBS ?
137136
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
138137
pinned: chat.get_visibility() == chat::ChatVisibility::Pinned,
139-
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
138+
chat_type: chat.get_type().into(),
140139
is_unpromoted: chat.is_unpromoted(),
141140
is_self_talk: chat.is_self_talk(),
142141
contacts,
@@ -210,7 +209,7 @@ pub struct BasicChat {
210209
profile_image: Option<String>, //BLOBS ?
211210
archived: bool,
212211
pinned: bool,
213-
chat_type: u32,
212+
chat_type: JSONRPCChatType,
214213
is_unpromoted: bool,
215214
is_self_talk: bool,
216215
color: String,
@@ -239,7 +238,7 @@ impl BasicChat {
239238
profile_image, //BLOBS ?
240239
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
241240
pinned: chat.get_visibility() == chat::ChatVisibility::Pinned,
242-
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
241+
chat_type: chat.get_type().into(),
243242
is_unpromoted: chat.is_unpromoted(),
244243
is_self_talk: chat.is_self_talk(),
245244
color,
@@ -293,3 +292,37 @@ impl JSONRPCChatVisibility {
293292
}
294293
}
295294
}
295+
296+
#[derive(Clone, Serialize, Deserialize, PartialEq, TypeDef, schemars::JsonSchema)]
297+
#[serde(rename = "ChatType")]
298+
pub enum JSONRPCChatType {
299+
Single,
300+
Group,
301+
Mailinglist,
302+
OutBroadcast,
303+
InBroadcast,
304+
}
305+
306+
impl From<Chattype> for JSONRPCChatType {
307+
fn from(chattype: Chattype) -> Self {
308+
match chattype {
309+
Chattype::Single => JSONRPCChatType::Single,
310+
Chattype::Group => JSONRPCChatType::Group,
311+
Chattype::Mailinglist => JSONRPCChatType::Mailinglist,
312+
Chattype::OutBroadcast => JSONRPCChatType::OutBroadcast,
313+
Chattype::InBroadcast => JSONRPCChatType::InBroadcast,
314+
}
315+
}
316+
}
317+
318+
impl From<JSONRPCChatType> for Chattype {
319+
fn from(chattype: JSONRPCChatType) -> Self {
320+
match chattype {
321+
JSONRPCChatType::Single => Chattype::Single,
322+
JSONRPCChatType::Group => Chattype::Group,
323+
JSONRPCChatType::Mailinglist => Chattype::Mailinglist,
324+
JSONRPCChatType::OutBroadcast => Chattype::OutBroadcast,
325+
JSONRPCChatType::InBroadcast => Chattype::InBroadcast,
326+
}
327+
}
328+
}

deltachat-jsonrpc/src/api/types/chat_list.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use num_traits::cast::ToPrimitive;
1111
use serde::Serialize;
1212
use typescript_type_def::TypeDef;
1313

14+
use super::chat::JSONRPCChatType;
1415
use super::color_int_to_hex_string;
1516
use super::message::MessageViewtype;
1617

@@ -23,7 +24,7 @@ pub enum ChatListItemFetchResult {
2324
name: String,
2425
avatar_path: Option<String>,
2526
color: String,
26-
chat_type: u32,
27+
chat_type: JSONRPCChatType,
2728
last_updated: Option<i64>,
2829
summary_text1: String,
2930
summary_text2: String,
@@ -155,7 +156,7 @@ pub(crate) async fn get_chat_list_item_by_id(
155156
name: chat.get_name().to_owned(),
156157
avatar_path,
157158
color,
158-
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
159+
chat_type: chat.get_type().into(),
159160
last_updated,
160161
summary_text1,
161162
summary_text2,

deltachat-jsonrpc/src/api/types/events.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use deltachat::{Event as CoreEvent, EventType as CoreEventType};
2-
use num_traits::ToPrimitive;
32
use serde::Serialize;
43
use typescript_type_def::TypeDef;
54

5+
use super::chat::JSONRPCChatType;
6+
67
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
78
#[serde(rename_all = "camelCase")]
89
pub struct Event {
@@ -307,7 +308,7 @@ pub enum EventType {
307308
/// The type of the joined chat.
308309
/// This can take the same values
309310
/// as `BasicChat.chatType` ([`crate::api::types::chat::BasicChat::chat_type`]).
310-
chat_type: u32,
311+
chat_type: JSONRPCChatType,
311312
/// ID of the chat in case of success.
312313
chat_id: u32,
313314

@@ -570,7 +571,7 @@ impl From<CoreEventType> for EventType {
570571
progress,
571572
} => SecurejoinInviterProgress {
572573
contact_id: contact_id.to_u32(),
573-
chat_type: chat_type.to_u32().unwrap_or(0),
574+
chat_type: chat_type.into(),
574575
chat_id: chat_id.to_u32(),
575576
progress,
576577
},

deltachat-jsonrpc/src/api/types/message.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use num_traits::cast::ToPrimitive;
1616
use serde::{Deserialize, Serialize};
1717
use typescript_type_def::TypeDef;
1818

19+
use super::chat::JSONRPCChatType;
1920
use super::color_int_to_hex_string;
2021
use super::contact::ContactObject;
2122
use super::reactions::JSONRPCReactions;
@@ -531,7 +532,7 @@ pub struct MessageSearchResult {
531532
chat_profile_image: Option<String>,
532533
chat_color: String,
533534
chat_name: String,
534-
chat_type: u32,
535+
chat_type: JSONRPCChatType,
535536
is_chat_protected: bool,
536537
is_chat_contact_request: bool,
537538
is_chat_archived: bool,
@@ -570,7 +571,7 @@ impl MessageSearchResult {
570571
chat_id: chat.id.to_u32(),
571572
chat_name: chat.get_name().to_owned(),
572573
chat_color,
573-
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
574+
chat_type: chat.get_type().into(),
574575
chat_profile_image,
575576
is_chat_protected: chat.is_protected(),
576577
is_chat_contact_request: chat.is_contact_request(),

0 commit comments

Comments
 (0)