mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
Rename Chat.archive() into Chat.set_archived()
This commit is contained in:
@@ -1146,7 +1146,7 @@ pub unsafe extern "C" fn dc_archive_chat(
|
|||||||
ffi_context
|
ffi_context
|
||||||
.with_inner(|ctx| {
|
.with_inner(|ctx| {
|
||||||
ChatId::new(chat_id)
|
ChatId::new(chat_id)
|
||||||
.archive(ctx, archive)
|
.set_archived(ctx, archive)
|
||||||
.log_err(ctx, "Failed archive chat")
|
.log_err(ctx, "Failed archive chat")
|
||||||
.unwrap_or(())
|
.unwrap_or(())
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -847,7 +847,7 @@ pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> {
|
|||||||
"archive" | "unarchive" => {
|
"archive" | "unarchive" => {
|
||||||
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
||||||
let chat_id = ChatId::new(arg1.parse()?);
|
let chat_id = ChatId::new(arg1.parse()?);
|
||||||
chat_id.archive(context, arg0 == "archive")?;
|
chat_id.set_archived(context, arg0 == "archive")?;
|
||||||
}
|
}
|
||||||
"delchat" => {
|
"delchat" => {
|
||||||
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
||||||
|
|||||||
16
src/chat.rs
16
src/chat.rs
@@ -133,14 +133,14 @@ impl ChatId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Archives or unarchives a chat.
|
/// Archives or unarchives a chat.
|
||||||
pub fn archive(self, context: &Context, archive: bool) -> Result<(), Error> {
|
pub fn set_archived(self, context: &Context, new_archived: bool) -> Result<(), Error> {
|
||||||
ensure!(
|
ensure!(
|
||||||
!self.is_special(),
|
!self.is_special(),
|
||||||
"bad chat_id, can not be special chat: {}",
|
"bad chat_id, can not be special chat: {}",
|
||||||
self
|
self
|
||||||
);
|
);
|
||||||
|
|
||||||
if archive {
|
if new_archived {
|
||||||
sql::execute(
|
sql::execute(
|
||||||
context,
|
context,
|
||||||
&context.sql,
|
&context.sql,
|
||||||
@@ -153,7 +153,7 @@ impl ChatId {
|
|||||||
context,
|
context,
|
||||||
&context.sql,
|
&context.sql,
|
||||||
"UPDATE chats SET archived=? WHERE id=?;",
|
"UPDATE chats SET archived=? WHERE id=?;",
|
||||||
params![archive, self],
|
params![new_archived, self],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.call_cb(Event::MsgsChanged {
|
context.call_cb(Event::MsgsChanged {
|
||||||
@@ -2703,7 +2703,7 @@ mod tests {
|
|||||||
assert_eq!(DC_GCL_NO_SPECIALS, 0x02);
|
assert_eq!(DC_GCL_NO_SPECIALS, 0x02);
|
||||||
|
|
||||||
// archive first chat
|
// archive first chat
|
||||||
assert!(chat_id1.archive(&t.ctx, true).is_ok());
|
assert!(chat_id1.set_archived(&t.ctx, true).is_ok());
|
||||||
assert!(Chat::load_from_db(&t.ctx, chat_id1).unwrap().is_archived());
|
assert!(Chat::load_from_db(&t.ctx, chat_id1).unwrap().is_archived());
|
||||||
assert!(!Chat::load_from_db(&t.ctx, chat_id2).unwrap().is_archived());
|
assert!(!Chat::load_from_db(&t.ctx, chat_id2).unwrap().is_archived());
|
||||||
assert_eq!(get_chat_cnt(&t.ctx), 2);
|
assert_eq!(get_chat_cnt(&t.ctx), 2);
|
||||||
@@ -2712,7 +2712,7 @@ mod tests {
|
|||||||
assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY), 1);
|
assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY), 1);
|
||||||
|
|
||||||
// archive second chat
|
// archive second chat
|
||||||
assert!(chat_id2.archive(&t.ctx, true).is_ok());
|
assert!(chat_id2.set_archived(&t.ctx, true).is_ok());
|
||||||
assert!(Chat::load_from_db(&t.ctx, chat_id1).unwrap().is_archived());
|
assert!(Chat::load_from_db(&t.ctx, chat_id1).unwrap().is_archived());
|
||||||
assert!(Chat::load_from_db(&t.ctx, chat_id2).unwrap().is_archived());
|
assert!(Chat::load_from_db(&t.ctx, chat_id2).unwrap().is_archived());
|
||||||
assert_eq!(get_chat_cnt(&t.ctx), 2);
|
assert_eq!(get_chat_cnt(&t.ctx), 2);
|
||||||
@@ -2721,9 +2721,9 @@ mod tests {
|
|||||||
assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY), 2);
|
assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY), 2);
|
||||||
|
|
||||||
// archive already archived first chat, unarchive second chat two times
|
// archive already archived first chat, unarchive second chat two times
|
||||||
assert!(chat_id1.archive(&t.ctx, true).is_ok());
|
assert!(chat_id1.set_archived(&t.ctx, true).is_ok());
|
||||||
assert!(chat_id2.archive(&t.ctx, false).is_ok());
|
assert!(chat_id2.set_archived(&t.ctx, false).is_ok());
|
||||||
assert!(chat_id2.archive(&t.ctx, false).is_ok());
|
assert!(chat_id2.set_archived(&t.ctx, false).is_ok());
|
||||||
assert!(Chat::load_from_db(&t.ctx, chat_id1).unwrap().is_archived());
|
assert!(Chat::load_from_db(&t.ctx, chat_id1).unwrap().is_archived());
|
||||||
assert!(!Chat::load_from_db(&t.ctx, chat_id2).unwrap().is_archived());
|
assert!(!Chat::load_from_db(&t.ctx, chat_id2).unwrap().is_archived());
|
||||||
assert_eq!(get_chat_cnt(&t.ctx), 2);
|
assert_eq!(get_chat_cnt(&t.ctx), 2);
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ mod tests {
|
|||||||
let chats = Chatlist::try_load(&t.ctx, DC_GCL_ARCHIVED_ONLY, None, None).unwrap();
|
let chats = Chatlist::try_load(&t.ctx, DC_GCL_ARCHIVED_ONLY, None, None).unwrap();
|
||||||
assert_eq!(chats.len(), 0);
|
assert_eq!(chats.len(), 0);
|
||||||
|
|
||||||
chat_id1.archive(&t.ctx, true).ok();
|
chat_id1.set_archived(&t.ctx, true).ok();
|
||||||
let chats = Chatlist::try_load(&t.ctx, DC_GCL_ARCHIVED_ONLY, None, None).unwrap();
|
let chats = Chatlist::try_load(&t.ctx, DC_GCL_ARCHIVED_ONLY, None, None).unwrap();
|
||||||
assert_eq!(chats.len(), 1);
|
assert_eq!(chats.len(), 1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user