mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 13:26:28 +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
|
||||
.with_inner(|ctx| {
|
||||
ChatId::new(chat_id)
|
||||
.archive(ctx, archive)
|
||||
.set_archived(ctx, archive)
|
||||
.log_err(ctx, "Failed archive chat")
|
||||
.unwrap_or(())
|
||||
})
|
||||
|
||||
@@ -847,7 +847,7 @@ pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> {
|
||||
"archive" | "unarchive" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
||||
let chat_id = ChatId::new(arg1.parse()?);
|
||||
chat_id.archive(context, arg0 == "archive")?;
|
||||
chat_id.set_archived(context, arg0 == "archive")?;
|
||||
}
|
||||
"delchat" => {
|
||||
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.
|
||||
pub fn archive(self, context: &Context, archive: bool) -> Result<(), Error> {
|
||||
pub fn set_archived(self, context: &Context, new_archived: bool) -> Result<(), Error> {
|
||||
ensure!(
|
||||
!self.is_special(),
|
||||
"bad chat_id, can not be special chat: {}",
|
||||
self
|
||||
);
|
||||
|
||||
if archive {
|
||||
if new_archived {
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
@@ -153,7 +153,7 @@ impl ChatId {
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET archived=? WHERE id=?;",
|
||||
params![archive, self],
|
||||
params![new_archived, self],
|
||||
)?;
|
||||
|
||||
context.call_cb(Event::MsgsChanged {
|
||||
@@ -2703,7 +2703,7 @@ mod tests {
|
||||
assert_eq!(DC_GCL_NO_SPECIALS, 0x02);
|
||||
|
||||
// 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_id2).unwrap().is_archived());
|
||||
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);
|
||||
|
||||
// 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_id2).unwrap().is_archived());
|
||||
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);
|
||||
|
||||
// archive already archived first chat, unarchive second chat two times
|
||||
assert!(chat_id1.archive(&t.ctx, true).is_ok());
|
||||
assert!(chat_id2.archive(&t.ctx, false).is_ok());
|
||||
assert!(chat_id2.archive(&t.ctx, false).is_ok());
|
||||
assert!(chat_id1.set_archived(&t.ctx, true).is_ok());
|
||||
assert!(chat_id2.set_archived(&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_id2).unwrap().is_archived());
|
||||
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();
|
||||
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();
|
||||
assert_eq!(chats.len(), 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user