Skip to content

Commit 8f6ce74

Browse files
committed
Revert "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 (#7285)"
This reverts commit a3328ea.
1 parent 6514b4c commit 8f6ce74

File tree

6 files changed

+24
-73
lines changed

6 files changed

+24
-73
lines changed

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

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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;
910
use serde::{Deserialize, Serialize};
1011
use typescript_type_def::TypeDef;
1112

@@ -45,7 +46,7 @@ pub struct FullChat {
4546
archived: bool,
4647
pinned: bool,
4748
// subtitle - will be moved to frontend because it uses translation functions
48-
chat_type: JsonrpcChatType,
49+
chat_type: u32,
4950
is_unpromoted: bool,
5051
is_self_talk: bool,
5152
contacts: Vec<ContactObject>,
@@ -129,7 +130,7 @@ impl FullChat {
129130
profile_image, //BLOBS ?
130131
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
131132
pinned: chat.get_visibility() == chat::ChatVisibility::Pinned,
132-
chat_type: chat.get_type().into(),
133+
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
133134
is_unpromoted: chat.is_unpromoted(),
134135
is_self_talk: chat.is_self_talk(),
135136
contacts,
@@ -191,7 +192,7 @@ pub struct BasicChat {
191192
profile_image: Option<String>, //BLOBS ?
192193
archived: bool,
193194
pinned: bool,
194-
chat_type: JsonrpcChatType,
195+
chat_type: u32,
195196
is_unpromoted: bool,
196197
is_self_talk: bool,
197198
color: String,
@@ -219,7 +220,7 @@ impl BasicChat {
219220
profile_image, //BLOBS ?
220221
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
221222
pinned: chat.get_visibility() == chat::ChatVisibility::Pinned,
222-
chat_type: chat.get_type().into(),
223+
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
223224
is_unpromoted: chat.is_unpromoted(),
224225
is_self_talk: chat.is_self_talk(),
225226
color,
@@ -273,37 +274,3 @@ impl JsonrpcChatVisibility {
273274
}
274275
}
275276
}
276-
277-
#[derive(Clone, Serialize, Deserialize, PartialEq, TypeDef, schemars::JsonSchema)]
278-
#[serde(rename = "ChatType")]
279-
pub enum JsonrpcChatType {
280-
Single,
281-
Group,
282-
Mailinglist,
283-
OutBroadcast,
284-
InBroadcast,
285-
}
286-
287-
impl From<Chattype> for JsonrpcChatType {
288-
fn from(chattype: Chattype) -> Self {
289-
match chattype {
290-
Chattype::Single => JsonrpcChatType::Single,
291-
Chattype::Group => JsonrpcChatType::Group,
292-
Chattype::Mailinglist => JsonrpcChatType::Mailinglist,
293-
Chattype::OutBroadcast => JsonrpcChatType::OutBroadcast,
294-
Chattype::InBroadcast => JsonrpcChatType::InBroadcast,
295-
}
296-
}
297-
}
298-
299-
impl From<JsonrpcChatType> for Chattype {
300-
fn from(chattype: JsonrpcChatType) -> Self {
301-
match chattype {
302-
JsonrpcChatType::Single => Chattype::Single,
303-
JsonrpcChatType::Group => Chattype::Group,
304-
JsonrpcChatType::Mailinglist => Chattype::Mailinglist,
305-
JsonrpcChatType::OutBroadcast => Chattype::OutBroadcast,
306-
JsonrpcChatType::InBroadcast => Chattype::InBroadcast,
307-
}
308-
}
309-
}

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

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

14-
use super::chat::JsonrpcChatType;
1514
use super::color_int_to_hex_string;
1615
use super::message::MessageViewtype;
1716

@@ -24,7 +23,7 @@ pub enum ChatListItemFetchResult {
2423
name: String,
2524
avatar_path: Option<String>,
2625
color: String,
27-
chat_type: JsonrpcChatType,
26+
chat_type: u32,
2827
last_updated: Option<i64>,
2928
summary_text1: String,
3029
summary_text2: String,
@@ -152,7 +151,7 @@ pub(crate) async fn get_chat_list_item_by_id(
152151
name: chat.get_name().to_owned(),
153152
avatar_path,
154153
color,
155-
chat_type: chat.get_type().into(),
154+
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
156155
last_updated,
157156
summary_text1,
158157
summary_text2,

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

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

5-
use super::chat::JsonrpcChatType;
6-
76
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
87
#[serde(rename_all = "camelCase")]
98
pub struct Event {
@@ -308,7 +307,7 @@ pub enum EventType {
308307
/// The type of the joined chat.
309308
/// This can take the same values
310309
/// as `BasicChat.chatType` ([`crate::api::types::chat::BasicChat::chat_type`]).
311-
chat_type: JsonrpcChatType,
310+
chat_type: u32,
312311
/// ID of the chat in case of success.
313312
chat_id: u32,
314313

@@ -571,7 +570,7 @@ impl From<CoreEventType> for EventType {
571570
progress,
572571
} => SecurejoinInviterProgress {
573572
contact_id: contact_id.to_u32(),
574-
chat_type: chat_type.into(),
573+
chat_type: chat_type.to_u32().unwrap_or(0),
575574
chat_id: chat_id.to_u32(),
576575
progress,
577576
},

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

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

19-
use super::chat::JsonrpcChatType;
2019
use super::color_int_to_hex_string;
2120
use super::contact::ContactObject;
2221
use super::reactions::JsonrpcReactions;
@@ -532,7 +531,7 @@ pub struct MessageSearchResult {
532531
chat_profile_image: Option<String>,
533532
chat_color: String,
534533
chat_name: String,
535-
chat_type: JsonrpcChatType,
534+
chat_type: u32,
536535
is_chat_contact_request: bool,
537536
is_chat_archived: bool,
538537
message: String,
@@ -570,7 +569,7 @@ impl MessageSearchResult {
570569
chat_id: chat.id.to_u32(),
571570
chat_name: chat.get_name().to_owned(),
572571
chat_color,
573-
chat_type: chat.get_type().into(),
572+
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
574573
chat_profile_image,
575574
is_chat_contact_request: chat.is_contact_request(),
576575
is_chat_archived: chat.get_visibility() == ChatVisibility::Archived,

deltachat-jsonrpc/typescript/scripts/generate-constants.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,15 @@ const constants = data
4545
key.startsWith("DC_SOCKET_") ||
4646
key.startsWith("DC_LP_AUTH_") ||
4747
key.startsWith("DC_PUSH_") ||
48-
key.startsWith("DC_TEXT1_") ||
49-
key.startsWith("DC_CHAT_TYPE")
48+
key.startsWith("DC_TEXT1_")
5049
);
5150
})
5251
.map((row) => {
53-
return ` export const ${row.key} = ${row.value};`;
52+
return ` ${row.key}: ${row.value}`;
5453
})
55-
.join("\n");
54+
.join(",\n");
5655

5756
writeFileSync(
5857
resolve(__dirname, "../generated/constants.ts"),
59-
`// Generated!
60-
61-
export namespace C {
62-
${constants}
63-
/** @deprecated 10-8-2025 compare string directly with \`== "Group"\` */
64-
export const DC_CHAT_TYPE_GROUP = "Group";
65-
/** @deprecated 10-8-2025 compare string directly with \`== "InBroadcast"\`*/
66-
export const DC_CHAT_TYPE_IN_BROADCAST = "InBroadcast";
67-
/** @deprecated 10-8-2025 compare string directly with \`== "Mailinglist"\` */
68-
export const DC_CHAT_TYPE_MAILINGLIST = "Mailinglist";
69-
/** @deprecated 10-8-2025 compare string directly with \`== "OutBroadcast"\` */
70-
export const DC_CHAT_TYPE_OUT_BROADCAST = "OutBroadcast";
71-
/** @deprecated 10-8-2025 compare string directly with \`== "Single"\` */
72-
export const DC_CHAT_TYPE_SINGLE = "Single";
73-
}\n`,
58+
`// Generated!\n\nexport enum C {\n${constants.replace(/:/g, " =")},\n}\n`,
7459
);

deltachat-rpc-client/src/deltachat_rpc_client/const.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,19 @@ class ChatId(IntEnum):
9191
LAST_SPECIAL = 9
9292

9393

94-
class ChatType(str, Enum):
94+
class ChatType(IntEnum):
9595
"""Chat type."""
9696

97-
SINGLE = "Single"
97+
UNDEFINED = 0
98+
99+
SINGLE = 100
98100
"""1:1 chat, i.e. a direct chat with a single contact"""
99101

100-
GROUP = "Group"
102+
GROUP = 120
101103

102-
MAILINGLIST = "Mailinglist"
104+
MAILINGLIST = 140
103105

104-
OUT_BROADCAST = "OutBroadcast"
106+
OUT_BROADCAST = 160
105107
"""Outgoing broadcast channel, called "Channel" in the UI.
106108
107109
The user can send into this channel,
@@ -113,7 +115,7 @@ class ChatType(str, Enum):
113115
which would make it hard to grep for it.
114116
"""
115117

116-
IN_BROADCAST = "InBroadcast"
118+
IN_BROADCAST = 165
117119
"""Incoming broadcast channel, called "Channel" in the UI.
118120
119121
This channel is read-only,

0 commit comments

Comments
 (0)