Skip to content

enable BccSelf by default #3612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- truncate incoming messages by lines instead of just length #3480
- emit separate `DC_EVENT_MSGS_CHANGED` for each expired message,
and `DC_EVENT_WEBXDC_INSTANCE_DELETED` when a message contains a webxdc #3605
- enable `bcc_self` by default #3612

### Fixes

Expand Down
34 changes: 16 additions & 18 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4554,26 +4554,24 @@ mod tests {
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_set_protection() {
async fn test_set_protection() -> Result<()> {
let t = TestContext::new_alice().await;
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await
.unwrap();
let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
t.set_config_bool(Config::BccSelf, false).await?;
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo").await?;
let chat = Chat::load_from_db(&t, chat_id).await?;
assert!(!chat.is_protected());
assert!(chat.is_unpromoted());

// enable protection on unpromoted chat, the info-message is added via add_info_msg()
chat_id
.set_protection(&t, ProtectionStatus::Protected)
.await
.unwrap();
.await?;

let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
let chat = Chat::load_from_db(&t, chat_id).await?;
assert!(chat.is_protected());
assert!(chat.is_unpromoted());

let msgs = get_chat_msgs(&t, chat_id, 0).await.unwrap();
let msgs = get_chat_msgs(&t, chat_id, 0).await?;
assert_eq!(msgs.len(), 1);

let msg = t.get_last_msg_in(chat_id).await;
Expand All @@ -4584,10 +4582,9 @@ mod tests {
// disable protection again, still unpromoted
chat_id
.set_protection(&t, ProtectionStatus::Unprotected)
.await
.unwrap();
.await?;

let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
let chat = Chat::load_from_db(&t, chat_id).await?;
assert!(!chat.is_protected());
assert!(chat.is_unpromoted());

Expand All @@ -4597,28 +4594,29 @@ mod tests {
assert_eq!(msg.get_state(), MessageState::InNoticed);

// send a message, this switches to promoted state
send_text_msg(&t, chat_id, "hi!".to_string()).await.unwrap();
send_text_msg(&t, chat_id, "hi!".to_string()).await?;

let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
let chat = Chat::load_from_db(&t, chat_id).await?;
assert!(!chat.is_protected());
assert!(!chat.is_unpromoted());

let msgs = get_chat_msgs(&t, chat_id, 0).await.unwrap();
let msgs = get_chat_msgs(&t, chat_id, 0).await?;
assert_eq!(msgs.len(), 3);

// enable protection on promoted chat, the info-message is sent via send_msg() this time
chat_id
.set_protection(&t, ProtectionStatus::Protected)
.await
.unwrap();
let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
.await?;
let chat = Chat::load_from_db(&t, chat_id).await?;
assert!(chat.is_protected());
assert!(!chat.is_unpromoted());

let msg = t.get_last_msg_in(chat_id).await;
assert!(msg.is_info());
assert_eq!(msg.get_info_type(), SystemMessage::ChatProtectionEnabled);
assert_eq!(msg.get_state(), MessageState::OutDelivered); // as bcc-self is disabled and there is nobody else in the chat

Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum Config {
Selfstatus,
Selfavatar,

#[strum(props(default = "0"))]
#[strum(props(default = "1"))]
BccSelf,

#[strum(props(default = "1"))]
Expand Down
1 change: 1 addition & 0 deletions src/webxdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ mod tests {
async fn test_resend_webxdc_instance_and_info() -> Result<()> {
// Alice uses webxdc in a group
let alice = TestContext::new_alice().await;
alice.set_config_bool(Config::BccSelf, false).await?;
let alice_grp = create_group_chat(&alice, ProtectionStatus::Unprotected, "grp").await?;
let alice_instance = send_webxdc_instance(&alice, alice_grp).await?;
assert_eq!(alice_grp.get_msg_cnt(&alice).await?, 1);
Expand Down