From 1bd53de1f773024d000d06faff20809990061ce0 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Mon, 31 Oct 2022 18:51:52 +0100 Subject: [PATCH] unwrap mailinglist addr option in cffi so rust api and jsonrpc return the option --- deltachat-ffi/src/lib.rs | 2 +- deltachat-jsonrpc/src/api/types/chat.rs | 4 ++-- deltachat-jsonrpc/typescript/generated/types.ts | 2 +- src/chat.rs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 2b1594a7a..6a2b932e4 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2852,7 +2852,7 @@ pub unsafe extern "C" fn dc_chat_get_mailinglist_addr(chat: *mut dc_chat_t) -> * return "".strdup(); } let ffi_chat = &*chat; - ffi_chat.chat.get_mailinglist_addr().strdup() + ffi_chat.chat.get_mailinglist_addr().unwrap_or_default().strdup() } #[no_mangle] diff --git a/deltachat-jsonrpc/src/api/types/chat.rs b/deltachat-jsonrpc/src/api/types/chat.rs index f63243112..40308333d 100644 --- a/deltachat-jsonrpc/src/api/types/chat.rs +++ b/deltachat-jsonrpc/src/api/types/chat.rs @@ -37,7 +37,7 @@ pub struct FullChat { ephemeral_timer: u32, //TODO look if there are more important properties in newer core versions can_send: bool, was_seen_recently: bool, - mailing_list_address: String, + mailing_list_address: Option, } impl FullChat { @@ -81,7 +81,7 @@ impl FullChat { false }; - let mailing_list_address = chat.get_mailinglist_addr().to_string(); + let mailing_list_address = chat.get_mailinglist_addr().map(|s|s.to_string()); Ok(FullChat { id: chat_id, diff --git a/deltachat-jsonrpc/typescript/generated/types.ts b/deltachat-jsonrpc/typescript/generated/types.ts index d55bde227..c8d451b44 100644 --- a/deltachat-jsonrpc/typescript/generated/types.ts +++ b/deltachat-jsonrpc/typescript/generated/types.ts @@ -22,7 +22,7 @@ export type Contact={"address":string;"color":string;"authName":string;"status": * the contact's last seen timestamp */ "lastSeen":I64;"wasSeenRecently":boolean;}; -export type FullChat={"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"contacts":(Contact)[];"contactIds":(U32)[];"color":string;"freshMessageCounter":Usize;"isContactRequest":boolean;"isDeviceChat":boolean;"selfInGroup":boolean;"isMuted":boolean;"ephemeralTimer":U32;"canSend":boolean;"wasSeenRecently":boolean;"mailingListAddress":string;}; +export type FullChat={"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"contacts":(Contact)[];"contactIds":(U32)[];"color":string;"freshMessageCounter":Usize;"isContactRequest":boolean;"isDeviceChat":boolean;"selfInGroup":boolean;"isMuted":boolean;"ephemeralTimer":U32;"canSend":boolean;"wasSeenRecently":boolean;"mailingListAddress":(string|null);}; /** * cheaper version of fullchat, omits: diff --git a/src/chat.rs b/src/chat.rs index 7bda1598b..6e58d1d2d 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1130,8 +1130,8 @@ impl Chat { } /// Returns mailing list address where messages are sent to. - pub fn get_mailinglist_addr(&self) -> &str { - self.param.get(Param::ListPost).unwrap_or_default() + pub fn get_mailinglist_addr(&self) -> Option<&str> { + self.param.get(Param::ListPost) } /// Returns profile image path for the chat.