mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
convert some log infos and guard bindings against some misuse
This commit is contained in:
@@ -184,14 +184,18 @@ class Account(object):
|
|||||||
return list(iter_array(dc_array, lambda x: Contact(self._dc_context, x)))
|
return list(iter_array(dc_array, lambda x: Contact(self._dc_context, x)))
|
||||||
|
|
||||||
def create_chat_by_contact(self, contact):
|
def create_chat_by_contact(self, contact):
|
||||||
""" create or get an existing 1:1 chat object for the specified contact.
|
""" create or get an existing 1:1 chat object for the specified contact or contact id.
|
||||||
|
|
||||||
:param contact: chat_id (int) or contact object.
|
:param contact: chat_id (int) or contact object.
|
||||||
:returns: a :class:`deltachat.chatting.Chat` object.
|
:returns: a :class:`deltachat.chatting.Chat` object.
|
||||||
"""
|
"""
|
||||||
assert contact._dc_context == self._dc_context
|
if hasattr(contact, "id"):
|
||||||
contact_id = getattr(contact, "id", contact)
|
if contact._dc_context != self._dc_context:
|
||||||
assert isinstance(contact_id, int)
|
raise ValueError("Contact belongs to a different Account")
|
||||||
|
contact_id = getattr(contact, "id", contact)
|
||||||
|
else:
|
||||||
|
assert isinstance(contact, int)
|
||||||
|
contact_id = contact
|
||||||
chat_id = lib.dc_create_chat_by_contact_id(
|
chat_id = lib.dc_create_chat_by_contact_id(
|
||||||
self._dc_context, contact_id)
|
self._dc_context, contact_id)
|
||||||
return Chat(self._dc_context, chat_id)
|
return Chat(self._dc_context, chat_id)
|
||||||
@@ -203,6 +207,8 @@ class Account(object):
|
|||||||
:param message: messsage id or message instance.
|
:param message: messsage id or message instance.
|
||||||
:returns: a :class:`deltachat.chatting.Chat` object.
|
:returns: a :class:`deltachat.chatting.Chat` object.
|
||||||
"""
|
"""
|
||||||
|
if self._dc_context != message._dc_context:
|
||||||
|
raise ValueError("Message belongs to a different Account")
|
||||||
msg_id = getattr(message, "id", message)
|
msg_id = getattr(message, "id", message)
|
||||||
assert isinstance(msg_id, int)
|
assert isinstance(msg_id, int)
|
||||||
chat_id = lib.dc_create_chat_by_msg_id(self._dc_context, msg_id)
|
chat_id = lib.dc_create_chat_by_msg_id(self._dc_context, msg_id)
|
||||||
|
|||||||
@@ -180,6 +180,17 @@ class TestOfflineAccount:
|
|||||||
assert msg.filename.endswith(msg.basename)
|
assert msg.filename.endswith(msg.basename)
|
||||||
assert msg.filemime == typeout
|
assert msg.filemime == typeout
|
||||||
|
|
||||||
|
def test_create_chat_mismatch(self, acfactory):
|
||||||
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
|
ac2 = acfactory.get_configured_offline_account()
|
||||||
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
ac2.create_chat_by_contact(contact1)
|
||||||
|
chat1 = ac1.create_chat_by_contact(contact1)
|
||||||
|
msg = chat1.send_text("hello")
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
ac2.create_chat_by_message(msg)
|
||||||
|
|
||||||
def test_chat_message_distinctions(self, acfactory):
|
def test_chat_message_distinctions(self, acfactory):
|
||||||
ac1 = acfactory.get_configured_offline_account()
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
|
|||||||
@@ -1086,12 +1086,12 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
|||||||
);
|
);
|
||||||
context.sql.close(&context);
|
context.sql.close(&context);
|
||||||
closed = 1i32;
|
closed = 1i32;
|
||||||
dc_log_info(
|
info!(
|
||||||
context,
|
context,
|
||||||
0i32,
|
0,
|
||||||
b"Backup \"%s\" to \"%s\".\x00" as *const u8 as *const libc::c_char,
|
"Backup \"{}\" to \"{}\".",
|
||||||
context.get_dbfile(),
|
as_str(context.get_dbfile()),
|
||||||
dest_pathNfilename,
|
as_str(dest_pathNfilename),
|
||||||
);
|
);
|
||||||
if !(0 == dc_copy_file(context, context.get_dbfile(), dest_pathNfilename)) {
|
if !(0 == dc_copy_file(context, context.get_dbfile(), dest_pathNfilename)) {
|
||||||
context.sql.open(&context, as_path(context.get_dbfile()), 0);
|
context.sql.open(&context, as_path(context.get_dbfile()), 0);
|
||||||
@@ -1139,13 +1139,11 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
|||||||
// scan directory, pass 2: copy files
|
// scan directory, pass 2: copy files
|
||||||
let dir_handle = std::fs::read_dir(dir);
|
let dir_handle = std::fs::read_dir(dir);
|
||||||
if dir_handle.is_err() {
|
if dir_handle.is_err() {
|
||||||
dc_log_error(
|
error!(
|
||||||
context,
|
context,
|
||||||
0i32,
|
0,
|
||||||
b"Backup: Cannot copy from blob-directory \"%s\".\x00"
|
"Backup: Cannot copy from blob-directory \"{}\".",
|
||||||
as *const u8
|
as_str(context.get_blobdir()),
|
||||||
as *const libc::c_char,
|
|
||||||
context.get_blobdir(),
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let dir_handle = dir_handle.unwrap();
|
let dir_handle = dir_handle.unwrap();
|
||||||
@@ -1193,7 +1191,6 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
|||||||
let name_f = entry.file_name();
|
let name_f = entry.file_name();
|
||||||
let name = name_f.to_string_lossy();
|
let name = name_f.to_string_lossy();
|
||||||
if name.starts_with("delt-chat") && name.ends_with(".bak") {
|
if name.starts_with("delt-chat") && name.ends_with(".bak") {
|
||||||
// dc_log_info(context, 0, "Backup: Skipping \"%s\".", name);
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
info!(context, 0, "EXPORTing filename={}", name);
|
info!(context, 0, "EXPORTing filename={}", name);
|
||||||
@@ -1249,13 +1246,7 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dc_log_info(
|
info!(context, 0, "Backup: No files to copy.");
|
||||||
context,
|
|
||||||
0i32,
|
|
||||||
b"Backup: No files to copy.\x00" as *const u8
|
|
||||||
as *const libc::c_char,
|
|
||||||
context.get_blobdir(),
|
|
||||||
);
|
|
||||||
current_block = 2631791190359682872;
|
current_block = 2631791190359682872;
|
||||||
}
|
}
|
||||||
match current_block {
|
match current_block {
|
||||||
|
|||||||
Reference in New Issue
Block a user