Move to json_serde, add tests and implement missing python api

This commit is contained in:
jikstra
2019-11-26 22:10:52 +01:00
committed by holger krekel
parent 1b79f513a3
commit 6d30ccfc63
3 changed files with 34 additions and 31 deletions

View File

@@ -331,6 +331,12 @@ class Chat(object):
return None
return from_dc_charpointer(dc_res)
def get_color(self):
return lib.dc_chat_get_color(self._dc_chat)
def get_subtitle(self):
return from_dc_charpointer(lib.dc_chat_get_subtitle(self._dc_chat))
# ------ location streaming API ------------------------------
def is_sending_locations(self):
@@ -339,6 +345,9 @@ class Chat(object):
"""
return lib.dc_is_sending_locations_to_chat(self._dc_context, self.id)
def is_archived(self):
return lib.dc_chat_get_archived(self._dc_chat)
def enable_sending_locations(self, seconds):
"""enable sending locations for this chat.

View File

@@ -156,8 +156,16 @@ class TestOfflineChat:
assert chat.get_name() == "title2"
d = chat.get_summary()
assert d["chat_id"] == chat.id
print(d)
assert d["id"] == chat.id
assert d["type"] == chat.get_type()
assert d["name"] == chat.get_name()
assert d["archived"] == chat.is_archived()
#assert d["param"] == chat.param
assert d["color"] == chat.get_color()
assert d["profile_image"] == "" if chat.get_profile_image() is None else chat.get_profile_image()
assert d["subtitle"] == chat.get_subtitle()
assert d["draft"] == "" if chat.get_draft() is None else chat.get_draft()
def test_group_chat_creation_with_translation(self, ac1):
ac1.set_stock_translation(const.DC_STR_NEWGROUPDRAFT, "xyz %1$s")
ac1._evlogger.consume_events()

View File

@@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
use itertools::Itertools;
use num_traits::FromPrimitive;
use serde_json::json;
use crate::blob::{BlobError, BlobObject};
use crate::chatlist::*;
@@ -1936,36 +1937,21 @@ pub fn get_info_json(context: &Context, chat_id: u32) -> Result<String, Error> {
Err(_) => "".to_string()
};
let s = format!("{{\
\"id\": {:?},\
\"type\": {:?},\
\"name\": {:?},\
\"archived\": {:?},\
\"grpid\": {:?},\
\"blocked\": {:?},\
\"param\": {:?},\
\"gossiped_timestamp\": {:?},\
\"is_sending_locations\": {:?},\
\"color\": {:?},\
\"profile_image\": {:?},\
\"subtitle\": {:?},\
\"draft\": {:?}\
}}",
chat.id,
chat.typ as u32,
chat.name,
chat.archived,
chat.grpid,
chat.blocked as u32,
chat.param.to_string(),
chat.gossiped_timestamp,
chat.is_sending_locations,
chat.get_color(context),
profile_image,
chat.get_subtitle(context),
draft);
let s = json!({
"id": chat.id,
"type": chat.typ as u32,
"name": chat.name,
"archived": chat.archived,
"param": chat.param.to_string(),
"gossiped_timestamp": chat.gossiped_timestamp,
"is_sending_locations": chat.is_sending_locations,
"color": chat.get_color(context),
"profile_image": profile_image,
"subtitle": chat.get_subtitle(context),
"draft": draft
});
Ok(s)
Ok(s.to_string())
}
pub fn get_chat_contact_cnt(context: &Context, chat_id: u32) -> usize {