mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
Move to json_serde, add tests and implement missing python api
This commit is contained in:
@@ -331,6 +331,12 @@ class Chat(object):
|
|||||||
return None
|
return None
|
||||||
return from_dc_charpointer(dc_res)
|
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 ------------------------------
|
# ------ location streaming API ------------------------------
|
||||||
|
|
||||||
def is_sending_locations(self):
|
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)
|
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):
|
def enable_sending_locations(self, seconds):
|
||||||
"""enable sending locations for this chat.
|
"""enable sending locations for this chat.
|
||||||
|
|
||||||
|
|||||||
@@ -156,8 +156,16 @@ class TestOfflineChat:
|
|||||||
assert chat.get_name() == "title2"
|
assert chat.get_name() == "title2"
|
||||||
|
|
||||||
d = chat.get_summary()
|
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):
|
def test_group_chat_creation_with_translation(self, ac1):
|
||||||
ac1.set_stock_translation(const.DC_STR_NEWGROUPDRAFT, "xyz %1$s")
|
ac1.set_stock_translation(const.DC_STR_NEWGROUPDRAFT, "xyz %1$s")
|
||||||
ac1._evlogger.consume_events()
|
ac1._evlogger.consume_events()
|
||||||
|
|||||||
44
src/chat.rs
44
src/chat.rs
@@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
|
|||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::blob::{BlobError, BlobObject};
|
use crate::blob::{BlobError, BlobObject};
|
||||||
use crate::chatlist::*;
|
use crate::chatlist::*;
|
||||||
@@ -1936,36 +1937,21 @@ pub fn get_info_json(context: &Context, chat_id: u32) -> Result<String, Error> {
|
|||||||
Err(_) => "".to_string()
|
Err(_) => "".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let s = format!("{{\
|
let s = json!({
|
||||||
\"id\": {:?},\
|
"id": chat.id,
|
||||||
\"type\": {:?},\
|
"type": chat.typ as u32,
|
||||||
\"name\": {:?},\
|
"name": chat.name,
|
||||||
\"archived\": {:?},\
|
"archived": chat.archived,
|
||||||
\"grpid\": {:?},\
|
"param": chat.param.to_string(),
|
||||||
\"blocked\": {:?},\
|
"gossiped_timestamp": chat.gossiped_timestamp,
|
||||||
\"param\": {:?},\
|
"is_sending_locations": chat.is_sending_locations,
|
||||||
\"gossiped_timestamp\": {:?},\
|
"color": chat.get_color(context),
|
||||||
\"is_sending_locations\": {:?},\
|
"profile_image": profile_image,
|
||||||
\"color\": {:?},\
|
"subtitle": chat.get_subtitle(context),
|
||||||
\"profile_image\": {:?},\
|
"draft": draft
|
||||||
\"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);
|
|
||||||
|
|
||||||
Ok(s)
|
Ok(s.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_chat_contact_cnt(context: &Context, chat_id: u32) -> usize {
|
pub fn get_chat_contact_cnt(context: &Context, chat_id: u32) -> usize {
|
||||||
|
|||||||
Reference in New Issue
Block a user