move can_send_edit_request() to send_edit_request()

This commit is contained in:
B. Petersen
2025-02-24 13:05:14 +01:00
parent 307b61a2c0
commit 2281f36ce5
5 changed files with 70 additions and 70 deletions

View File

@@ -3646,6 +3646,58 @@ async fn test_one_to_one_chat_no_group_member_timestamps() {
assert!(!payload.contains("Chat-Group-Member-Timestamps:"));
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn text_can_send_edit_request() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = tcm.alice().await;
let bob = tcm.bob().await;
let chat_id = alice
.create_group_with_members(ProtectionStatus::Unprotected, "My Group", &[&bob])
.await;
// Alice can edit her message
let sent1 = alice.send_text(chat_id, "foo").await;
assert!(can_send_edit_request(&alice, sent1.sender_msg_id).await?);
// Bob cannot edit Alice's message
let msg = bob.recv_msg(&sent1).await;
assert!(!can_send_edit_request(&bob, msg.id).await?);
// HTML messages cannot be edited
let mut msg = Message::new_text("plain text".to_string());
msg.set_html(Some("<b>html</b> text".to_string()));
let sent2 = alice.send_msg(chat_id, &mut msg).await;
assert!(!can_send_edit_request(&alice, sent2.sender_msg_id).await?);
// Info messages cannot be edited
set_chat_name(&alice, chat_id, "bar").await?;
let msg = alice.get_last_msg().await;
assert!(msg.is_info());
assert_eq!(msg.from_id, ContactId::SELF);
assert!(!can_send_edit_request(&alice, msg.id).await?);
// Videochat invitations cannot be edited
alice
.set_config(Config::WebrtcInstance, Some("https://foo.bar"))
.await?;
let msg_id = send_videochat_invitation(&alice, chat_id).await?;
assert!(!can_send_edit_request(&alice, msg_id).await?);
// If not text was given initally, there is nothing to edit
// (this also avoids complexity in UI element changes; focus is typos and rewordings)
let mut msg = Message::new(Viewtype::File);
msg.make_vcard(&alice, &[ContactId::SELF]).await?;
let sent3 = alice.send_msg(chat_id, &mut msg).await;
assert!(msg.text.is_empty());
assert!(!can_send_edit_request(&alice, sent3.sender_msg_id).await?);
// Messages in left groups cannot be edited any longer (as one cannot send to that group)
remove_contact_from_chat(&alice, chat_id, ContactId::SELF).await?;
assert!(!can_send_edit_request(&alice, sent1.sender_msg_id).await?);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_send_edit_request() -> Result<()> {
let mut tcm = TestContextManager::new();