mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 10:26:29 +03:00
fix: Revert member addition if the corresponding message couldn't be sent (#5508)
This commit is contained in:
@@ -3760,7 +3760,10 @@ pub(crate) async fn add_contact_to_chat_ex(
|
||||
msg.param.set_cmd(SystemMessage::MemberAddedToGroup);
|
||||
msg.param.set(Param::Arg, contact_addr);
|
||||
msg.param.set_int(Param::Arg2, from_handshake.into());
|
||||
msg.id = send_msg(context, chat_id, &mut msg).await?;
|
||||
if let Err(e) = send_msg(context, chat_id, &mut msg).await {
|
||||
remove_from_chat_contacts_table(context, chat_id, contact_id).await?;
|
||||
return Err(e);
|
||||
}
|
||||
sync = Nosync;
|
||||
}
|
||||
context.emit_event(EventType::ChatModified(chat_id));
|
||||
|
||||
@@ -4502,7 +4502,7 @@ async fn test_leave_protected_group_missing_member_key() -> Result<()> {
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_protected_group_remove_member_missing_key() -> Result<()> {
|
||||
async fn test_protected_group_add_remove_member_missing_key() -> Result<()> {
|
||||
let mut tcm = TestContextManager::new();
|
||||
let alice = &tcm.alice().await;
|
||||
let bob = &tcm.bob().await;
|
||||
@@ -4516,6 +4516,18 @@ async fn test_protected_group_remove_member_missing_key() -> Result<()> {
|
||||
.sql
|
||||
.execute("DELETE FROM acpeerstates WHERE addr=?", (&bob_addr,))
|
||||
.await?;
|
||||
|
||||
let fiona = &tcm.fiona().await;
|
||||
mark_as_verified(alice, fiona).await;
|
||||
let alice_fiona_id = alice.add_or_lookup_contact(fiona).await.id;
|
||||
assert!(add_contact_to_chat(alice, group_id, alice_fiona_id)
|
||||
.await
|
||||
.is_err());
|
||||
assert!(!is_contact_in_chat(alice, group_id, alice_fiona_id).await?);
|
||||
// Now the chat has a message "You added member fiona@example.net. [INFO] !!" (with error) that
|
||||
// may be confusing, but if the error is displayed in UIs, it's more or less ok. This is not a
|
||||
// normal scenario anyway.
|
||||
|
||||
remove_contact_from_chat(alice, group_id, alice_bob_id).await?;
|
||||
assert!(!is_contact_in_chat(alice, group_id, alice_bob_id).await?);
|
||||
let msg = alice.get_last_msg_in(group_id).await;
|
||||
|
||||
Reference in New Issue
Block a user