mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
Tweak error halding a little
- Python should raise exceptions on error. Not return False. - Negative durations are nonense. - ChatID validity is already checked by the Rust API, let's not duplicate.
This commit is contained in:
@@ -1415,7 +1415,7 @@ pub unsafe extern "C" fn dc_set_chat_mute_duration(
|
|||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
duration: i64,
|
duration: i64,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 {
|
if context.is_null() {
|
||||||
eprintln!("ignoring careless call to dc_set_chat_mute_duration()");
|
eprintln!("ignoring careless call to dc_set_chat_mute_duration()");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,13 +101,15 @@ class Chat(object):
|
|||||||
""" mutes the chat
|
""" mutes the chat
|
||||||
|
|
||||||
:param duration: Number of seconds to mute the chat for. None to mute until unmuted again.
|
:param duration: Number of seconds to mute the chat for. None to mute until unmuted again.
|
||||||
:returns:
|
:returns: None
|
||||||
"""
|
"""
|
||||||
if duration is None:
|
if duration is None:
|
||||||
mute_duration = -1
|
mute_duration = -1
|
||||||
else:
|
else:
|
||||||
mute_duration = duration
|
mute_duration = duration
|
||||||
return bool(lib.dc_set_chat_mute_duration(self._dc_context, self.id, mute_duration))
|
ret = lib.dc_set_chat_mute_duration(self._dc_context, self.id, mute_duration)
|
||||||
|
if not bool(ret):
|
||||||
|
raise ValueError("Call to dc_set_chat_mute_duration failed")
|
||||||
|
|
||||||
def unmute(self):
|
def unmute(self):
|
||||||
""" unmutes the chat
|
""" unmutes the chat
|
||||||
|
|||||||
@@ -229,8 +229,8 @@ class TestOfflineChat:
|
|||||||
assert not chat.is_muted()
|
assert not chat.is_muted()
|
||||||
assert chat.mute(50)
|
assert chat.mute(50)
|
||||||
assert chat.is_muted()
|
assert chat.is_muted()
|
||||||
assert chat.mute(-51)
|
with pytest.raises(ValueError):
|
||||||
assert not chat.is_muted()
|
chat.mute(-51)
|
||||||
|
|
||||||
def test_delete_and_send_fails(self, ac1, chat1):
|
def test_delete_and_send_fails(self, ac1, chat1):
|
||||||
chat1.delete()
|
chat1.delete()
|
||||||
|
|||||||
Reference in New Issue
Block a user