diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index a3f8f785a..040a3ec2b 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -2845,6 +2845,10 @@ char* dc_chat_get_profile_image (const dc_chat_t* chat); uint32_t dc_chat_get_color (const dc_chat_t* chat); +#define DC_CHAT_ARCHIVE_STATE_NORMAL 0 +#define DC_CHAT_ARCHIVE_STATE_ARCHIVED 1 +#define DC_CHAT_ARCHIVE_STATE_PINNED 2 + /** * Get archived state. * diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index a125037ef..fb514fe51 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -1203,7 +1203,7 @@ pub unsafe extern "C" fn dc_archive_chat( 1 => ArchiveState::Archived, 2 => ArchiveState::Pinned, _ => { - eprintln!("ignoring careless call to dc_archive_chat(): unknown archived state"); + ffi_context.warning("ignoring careless call to dc_archive_chat(): unknown archived state"); return; } }; diff --git a/python/src/deltachat/chat.py b/python/src/deltachat/chat.py index 46a743571..98b3220b5 100644 --- a/python/src/deltachat/chat.py +++ b/python/src/deltachat/chat.py @@ -423,28 +423,28 @@ class Chat(object): """return True if this chat is archived. :returns: True if archived. """ - return lib.dc_chat_get_archived(self._dc_chat) == 1 + return lib.dc_chat_get_archived(self._dc_chat) == const.DC_CHAT_ARCHIVE_STATE_ARCHIVED def is_pinned(self): """return True if this chat is pinned. :returns: True if pinned. """ - return lib.dc_chat_get_archived(self._dc_chat) == 2 + return lib.dc_chat_get_archived(self._dc_chat) == const.DC_CHAT_ARCHIVE_STATE_PINNED def archive(self): """archive the chat. """ - lib.dc_archive_chat(self._dc_context, self.id, 1) + lib.dc_archive_chat(self._dc_context, self.id, const.DC_CHAT_ARCHIVE_STATE_ARCHIVED) def unarchive(self): """unarchive the chat. """ - lib.dc_archive_chat(self._dc_context, self.id, 0) + lib.dc_archive_chat(self._dc_context, self.id, const.DC_CHAT_ARCHIVE_STATE_NORMAL) def pin(self): """pin the chat. """ - lib.dc_archive_chat(self._dc_context, self.id, 2) + lib.dc_archive_chat(self._dc_context, self.id, const.DC_CHAT_ARCHIVE_STATE_PINNED) def unpin(self): """unpin the chat. (same as unarchive) diff --git a/python/src/deltachat/const.py b/python/src/deltachat/const.py index baeaa2c11..0c898d6b7 100644 --- a/python/src/deltachat/const.py +++ b/python/src/deltachat/const.py @@ -33,6 +33,9 @@ DC_CHAT_TYPE_UNDEFINED = 0 DC_CHAT_TYPE_SINGLE = 100 DC_CHAT_TYPE_GROUP = 120 DC_CHAT_TYPE_VERIFIED_GROUP = 130 +DC_CHAT_ARCHIVE_STATE_NORMAL = 0 +DC_CHAT_ARCHIVE_STATE_ARCHIVED = 1 +DC_CHAT_ARCHIVE_STATE_PINNED = 2 DC_MSG_ID_MARKER1 = 1 DC_MSG_ID_DAYMARKER = 9 DC_MSG_ID_LAST_SPECIAL = 9 diff --git a/src/chat.rs b/src/chat.rs index 3ce2713b6..3e418d2c1 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -961,17 +961,15 @@ impl rusqlite::types::ToSql for ArchiveState { impl rusqlite::types::FromSql for ArchiveState { fn column_result(value: rusqlite::types::ValueRef) -> rusqlite::types::FromSqlResult { i64::column_result(value).and_then(|val| { - Ok({ - match val { - 2 => ArchiveState::Pinned, - 1 => ArchiveState::Archived, - 0 => ArchiveState::Normal, - _ => { - println!("unknown archived state, falling back to normal state (was this db opened with a newer deltachat version?)"); - ArchiveState::Normal - }, + match val { + 2 => Ok(ArchiveState::Pinned), + 1 => Ok(ArchiveState::Archived), + 0 => Ok(ArchiveState::Normal), + n => { + // unknown archived state, falling back to normal state (was this db opened with a newer deltachat version?) + Err(rusqlite::types::FromSqlError::OutOfRange(n)) } - }) + } }) } }