forward_msgs(): add a test, refine docs (#3446)

* improve dc_forward_msgs() documentation

* test that forwarded info-messages lose their info-state
This commit is contained in:
bjoern
2022-06-24 14:46:06 +02:00
committed by GitHub
parent 525b04e69e
commit fcdf766769
2 changed files with 32 additions and 1 deletions

View File

@@ -1791,6 +1791,11 @@ void dc_delete_msgs (dc_context_t* context, const uint3
/**
* Forward messages to another chat.
*
* All types of messages can be forwarded,
* however, they will be flagged as such (dc_msg_is_forwarded() is set).
*
* Original sender, info-state and webxdc updates are not forwarded on purpose.
*
* @memberof dc_context_t
* @param context The context object.
* @param msg_ids An array of uint32_t containing all message IDs that should be forwarded.
@@ -3979,7 +3984,7 @@ int dc_msg_is_sent (const dc_msg_t* msg);
*
* For privacy reasons, we do not provide the name or the e-mail address of the
* original author (in a typical GUI, you select the messages text and click on
* "forwared"; you won't expect other data to be send to the new recipient,
* "forwarded"; you won't expect other data to be send to the new recipient,
* esp. as the new recipient may not be in any relationship to the original author)
*
* @memberof dc_msg_t

View File

@@ -5041,6 +5041,32 @@ mod tests {
Ok(())
}
#[async_std::test]
async fn test_forward_info_msg() -> Result<()> {
let t = TestContext::new_alice().await;
let chat_id1 = create_group_chat(&t, ProtectionStatus::Unprotected, "a").await?;
send_text_msg(&t, chat_id1, "msg one".to_string()).await?;
let bob_id = Contact::create(&t, "", "bob@example.net").await?;
add_contact_to_chat(&t, chat_id1, bob_id).await?;
let msg1 = t.get_last_msg_in(chat_id1).await;
assert!(msg1.is_info());
assert!(msg1.get_text().unwrap().contains("bob@example.net"));
let chat_id2 = ChatId::create_for_contact(&t, bob_id).await?;
assert_eq!(get_chat_msgs(&t, chat_id2, 0).await?.len(), 0);
forward_msgs(&t, &[msg1.id], chat_id2).await?;
let msg2 = t.get_last_msg_in(chat_id2).await;
assert!(!msg2.is_info()); // forwarded info-messages lose their info-state
assert_eq!(msg2.get_info_type(), SystemMessage::Unknown);
assert_ne!(msg2.from_id, ContactId::INFO);
assert_ne!(msg2.to_id, ContactId::INFO);
assert_eq!(msg2.get_text().unwrap(), msg1.get_text().unwrap());
assert!(msg2.is_forwarded());
Ok(())
}
#[async_std::test]
async fn test_forward_quote() -> Result<()> {
let alice = TestContext::new_alice().await;