Skip to content
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
4 changes: 1 addition & 3 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4263,9 +4263,7 @@ async fn set_chat_description_ex(

if chat.is_promoted() {
let mut msg = Message::new(Viewtype::Text);
msg.text =
"[Chat description changed. To see this and other new features, please update the app]"
.to_string();
msg.text = stock_str::msg_chat_description_changed(context, ContactId::SELF).await;
msg.param.set_cmd(SystemMessage::GroupDescriptionChanged);

msg.id = send_msg(context, chat_id, &mut msg).await?;
Expand Down
78 changes: 65 additions & 13 deletions src/chat/chat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3154,29 +3154,59 @@ async fn test_broadcasts_name_and_avatar() -> Result<()> {

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_chat_description_basic() {
test_chat_description("", false).await.unwrap()
test_chat_description("", false, Chattype::Group)
.await
.unwrap();
// Don't test with broadcast channels,
// because broadcast channels can only be joined via a QR code
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_chat_description_unpromoted_description() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe merge this into the previous test, at least to not duplicate the comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, everything is very systematic; there are 4 tests for the 4 combinations of the first 2 arguments. There are two places where readers might wonder why it's not tested for broadcast channels, therefore the duplicate comment

test_chat_description("Unpromoted description in the beginning", false)
.await
.unwrap()
test_chat_description(
"Unpromoted description in the beginning",
false,
Chattype::Group,
)
.await
.unwrap();
// Don't test with broadcast channels,
// because broadcast channels can only be joined via a QR code
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_chat_description_qr() {
test_chat_description("", true).await.unwrap()
test_chat_description("", true, Chattype::Group)
.await
.unwrap();
test_chat_description("", true, Chattype::OutBroadcast)
.await
.unwrap();
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_chat_description_unpromoted_description_qr() {
test_chat_description("Unpromoted description in the beginning", true)
.await
.unwrap()
test_chat_description(
"Unpromoted description in the beginning",
true,
Chattype::Group,
)
.await
.unwrap();
test_chat_description(
"Unpromoted description in the beginning",
true,
Chattype::OutBroadcast,
)
.await
.unwrap();
}

async fn test_chat_description(initial_description: &str, join_via_qr: bool) -> Result<()> {
async fn test_chat_description(
initial_description: &str,
join_via_qr: bool,
chattype: Chattype,
) -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let alice2 = &tcm.alice().await;
Expand All @@ -3186,12 +3216,29 @@ async fn test_chat_description(initial_description: &str, join_via_qr: bool) ->
alice2.set_config_bool(Config::SyncMsgs, true).await?;

tcm.section("Create a group chat, and add Bob");
let alice_chat_id = create_group(alice, "My Group").await?;
let alice_chat_id = if chattype == Chattype::Group {
create_group(alice, "My Group").await?
} else {
create_broadcast(alice, "My Channel".to_string()).await?
};
sync(alice, alice2).await;

if !initial_description.is_empty() {
set_chat_description(alice, alice_chat_id, initial_description).await?;

if chattype == Chattype::OutBroadcast {
// Broadcast channels are always promoted, so, a message is sent:
let sent = alice.pop_sent_msg().await;
assert_eq!(
sent.load_from_db().await.text,
"You changed the chat description."
);
let rcvd = alice2.recv_msg(&sent).await;
assert_eq!(rcvd.text, "You changed the chat description.");
} else {
sync(alice, alice2).await;
}
}
sync(alice, alice2).await;

let alice2_chat_id = get_chat_id_by_grpid(
alice2,
Expand Down Expand Up @@ -3219,18 +3266,23 @@ async fn test_chat_description(initial_description: &str, join_via_qr: bool) ->
initial_description
);

for description in ["This is a cool group", "", "ä ẟ 😂"] {
for description in ["This is a cool chat", "", "ä ẟ 😂"] {
tcm.section(&format!(
"Alice sets the chat description to '{description}'"
));
set_chat_description(alice, alice_chat_id, description).await?;
let sent = alice.pop_sent_msg().await;
assert_eq!(
sent.load_from_db().await.text,
"[Chat description changed. To see this and other new features, please update the app]"
"You changed the chat description."
);

tcm.section("Bob receives the description change");
let parsed = MimeMessage::from_bytes(bob, sent.payload().as_bytes()).await?;
assert_eq!(
parsed.parts[0].msg,
"[Chat description changed. To see this and other new features, please update the app]"
);
let rcvd = bob.recv_msg(&sent).await;
assert_eq!(rcvd.get_info_type(), SystemMessage::GroupDescriptionChanged);
assert_eq!(rcvd.text, "Chat description changed by alice@example.org.");
Expand Down
3 changes: 3 additions & 0 deletions src/mimefactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,9 @@ impl MimeFactory {
));
}
SystemMessage::GroupDescriptionChanged => {
placeholdertext = Some(
"[Chat description changed. To see this and other new features, please update the app]".to_string(),
);
headers.push((
"Chat-Group-Description-Changed",
mail_builder::headers::text::Text::new("").into(),
Expand Down