diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index c4c20ee23..a864d5bd7 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -2619,7 +2619,7 @@ dc_context_t* dc_chatlist_get_context (dc_chatlist_t* chatlist); * @return a utf8-encoded json string containing all requested info. Must be freed using dc_lot_unref(). NULL is never returned. */ -char* dc_chat_get_info_json(dc_context_t* context, size_t chat_id) +char* dc_chat_get_info_json (dc_context_t* context, size_t chat_id); /** * @class dc_chat_t diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index dbd21e068..d52b91470 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2377,6 +2377,27 @@ pub unsafe extern "C" fn dc_chat_is_sending_locations(chat: *mut dc_chat_t) -> l ffi_chat.chat.is_sending_locations() as libc::c_int } +#[no_mangle] +pub unsafe extern "C" fn dc_chat_get_info_json( + context: *mut dc_context_t, + chat_id: u32, +) -> *mut libc::c_char { + if context.is_null() { + eprintln!("ignoring careless call to dc_get_oauth2_url()"); + return ptr::null_mut(); // NULL explicitly defined as "unknown" + } + let ffi_context = &*context; + ffi_context + .with_inner(|ctx| match chat::get_info_json(ctx, chat_id) { + Ok(s) => s.strdup(), + Err(err) => { + error!(ctx, "get_info_json({}) returned: {}", chat_id, err); + "".strdup() + } + }) + .unwrap_or_else(|_| ptr::null_mut()) +} + // dc_msg_t /// FFI struct for [dc_msg_t] diff --git a/python/src/deltachat/chat.py b/python/src/deltachat/chat.py index 6fe0d9556..4e6000f9b 100644 --- a/python/src/deltachat/chat.py +++ b/python/src/deltachat/chat.py @@ -2,6 +2,7 @@ import mimetypes import calendar +import json from datetime import datetime import os from .cutil import as_dc_charpointer, from_dc_charpointer, iter_array @@ -242,6 +243,12 @@ class Chat(object): """ return lib.dc_marknoticed_chat(self._dc_context, self.id) + def get_summary(self): + """ return dictionary with summary information. """ + dc_res = lib.dc_chat_get_info_json(self._dc_context, self.id) + s = from_dc_charpointer(dc_res) + return json.loads(s) + # ------ group management API ------------------------------ def add_contact(self, contact): diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 88cd829cb..29a4b47ad 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -155,6 +155,9 @@ class TestOfflineChat: chat.set_name("title2") assert chat.get_name() == "title2" + d = chat.get_summary() + assert d["chat_id"] == chat.id + def test_group_chat_creation_with_translation(self, ac1): ac1.set_stock_translation(const.DC_STR_NEWGROUPDRAFT, "xyz %1$s") ac1._evlogger.consume_events() diff --git a/src/chat.rs b/src/chat.rs index cd0a238c0..e694354cd 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1903,6 +1903,11 @@ pub fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: u32) -> Resul Ok(()) } +pub fn get_info_json(context: &Context, chat_id: u32) -> Result { + let s = format!("{{\n {:?}: {:?}\n}}", "chat_id", chat_id); + Ok(s) +} + pub fn get_chat_contact_cnt(context: &Context, chat_id: u32) -> usize { context .sql