Compare commits

...

2 Commits

Author SHA1 Message Date
B. Petersen
d8efda152b update CHANGELOG 2022-08-15 11:49:27 +02:00
B. Petersen
7d292ceca9 remove Chat::get_info_json()
get_info_json() was added some years ago with the goal to
help desktop getting information about a a chat.

i came over this function when working on #3520,
i thought, that may be a nice function, just add a field, no new api, done.

however, looking at the code, drawbacks of get_info_json() are,
that it does no just write the internal chat info to json -
but also do quite some more expensive things that result in several db calls.

so, if we would have added the "mailing list" address here,
reading it would result in quite some overhead,
therefore i decided against it.

having a closer look,
the function seems unmaintained and also incomplete,
eg. pinning is missing.
diving deeper, it looks as if the function is mostly unused,
i could not find any reference to it even on desktop.

there is only one call to it with the bit misleading name `getSummary()` -
idk, if that is used.

if it turns out, the function is not used,
i suggest to remove it:
- desktop goes for a much broader json-rpc
- in general, i like the idea of getting a structure retuned like that,
  that may be also useful for ios/android, and json is alread in use meanwhile,
  but i would prefer not to mix returning already loaded structure fields
  and things that require database access,
  this is a waste of resources most times.
2022-08-15 11:48:03 +02:00
5 changed files with 1 additions and 119 deletions

View File

@@ -12,6 +12,7 @@
- node: json rpc methods #3463:
- `AccountManager.prototype.startJsonRpcHandler(callback: ((response: string) => void)): void`
- `AccountManager.prototype.jsonRpcRequest(message: string): void`
- remove `dc_chat_get_info_json()` #3523
### Added
- added a JSON RPC API, accessible through a WebSocket server, the CFFI bindings and the Node.js bindings #3463

View File

@@ -3165,24 +3165,6 @@ dc_lot_t* dc_chatlist_get_summary2 (dc_context_t* context, uint32_t ch
dc_context_t* dc_chatlist_get_context (dc_chatlist_t* chatlist);
/**
* Get info summary for a chat, in JSON format.
*
* The returned JSON string has the following key/values:
*
* id: chat id
* name: chat/group name
* color: color of this chat
* last-message-from: who sent the last message
* last-message-text: message (truncated)
* last-message-state: @ref DC_STATE constant
* last-message-date:
* avatar-path: path-to-blobfile
* is_verified: yes/no
* @return a UTF8-encoded JSON string containing all requested info. Must be freed using dc_str_unref(). NULL is never returned.
*/
char* dc_chat_get_info_json (dc_context_t* context, size_t chat_id);
/**
* @class dc_chat_t
*

View File

@@ -2943,41 +2943,6 @@ pub unsafe extern "C" fn dc_chat_get_remaining_mute_duration(chat: *mut dc_chat_
}
}
#[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_chat_get_info_json()");
return "".strdup();
}
let ctx = &*context;
block_on(async move {
let chat = match chat::Chat::load_from_db(ctx, ChatId::new(chat_id)).await {
Ok(chat) => chat,
Err(err) => {
error!(ctx, "dc_get_chat_info_json() failed to load chat: {}", err);
return "".strdup();
}
};
let info = match chat.get_info(ctx).await {
Ok(info) => info,
Err(err) => {
error!(
ctx,
"dc_get_chat_info_json() failed to get chat info: {}", err
);
return "".strdup();
}
};
serde_json::to_string(&info)
.unwrap_or_log_default(ctx, "dc_get_chat_info_json() failed to serialise to json")
.strdup()
})
}
// dc_msg_t
/// FFI struct for [dc_msg_t]

View File

@@ -171,12 +171,6 @@ class Chat(object):
"""
return lib.dc_chat_get_color(self._dc_chat)
def get_summary(self):
"""return dictionary with summary information."""
dc_res = lib.dc_chat_get_info_json(self.account._dc_context, self.id)
s = from_dc_charpointer(dc_res)
return json.loads(s)
def mute(self, duration: Optional[int] = None) -> None:
"""mutes the chat

View File

@@ -1172,35 +1172,6 @@ impl Chat {
Ok(color)
}
/// Returns a struct describing the current state of the chat.
///
/// This is somewhat experimental, even more so than the rest of
/// deltachat, and the data returned is still subject to change.
pub async fn get_info(&self, context: &Context) -> Result<ChatInfo> {
let draft = match self.id.get_draft(context).await? {
Some(message) => message.text.unwrap_or_default(),
_ => String::new(),
};
Ok(ChatInfo {
id: self.id,
type_: self.typ as u32,
name: self.name.clone(),
archived: self.visibility == ChatVisibility::Archived,
param: self.param.to_string(),
gossiped_timestamp: self.id.get_gossiped_timestamp(context).await?,
is_sending_locations: self.is_sending_locations,
color: self.get_color(context).await?,
profile_image: self
.get_profile_image(context)
.await?
.map(Into::into)
.unwrap_or_else(std::path::PathBuf::new),
draft,
is_muted: self.is_muted(),
ephemeral_timer: self.id.get_ephemeral_timer(context).await?,
})
}
pub fn get_visibility(&self) -> ChatVisibility {
self.visibility
}
@@ -3469,37 +3440,6 @@ mod tests {
use crate::receive_imf::receive_imf;
use crate::test_utils::TestContext;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_chat_info() {
let t = TestContext::new().await;
let chat = t.create_chat_with_contact("bob", "bob@example.com").await;
let info = chat.get_info(&t).await.unwrap();
// Ensure we can serialize this.
println!("{}", serde_json::to_string_pretty(&info).unwrap());
let expected = r#"
{
"id": 10,
"type": 100,
"name": "bob",
"archived": false,
"param": "",
"gossiped_timestamp": 0,
"is_sending_locations": false,
"color": 35391,
"profile_image": "",
"draft": "",
"is_muted": false,
"ephemeral_timer": "Disabled"
}
"#;
// Ensure we can deserialize this.
let loaded: ChatInfo = serde_json::from_str(expected).unwrap();
assert_eq!(info, loaded);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_get_draft_no_draft() {
let t = TestContext::new().await;