Skip to content

Commit fcdf766

Browse files
authored
forward_msgs(): add a test, refine docs (#3446)
* improve dc_forward_msgs() documentation * test that forwarded info-messages lose their info-state
1 parent 525b04e commit fcdf766

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

deltachat-ffi/deltachat.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,11 @@ void dc_delete_msgs (dc_context_t* context, const uint3
17911791
/**
17921792
* Forward messages to another chat.
17931793
*
1794+
* All types of messages can be forwarded,
1795+
* however, they will be flagged as such (dc_msg_is_forwarded() is set).
1796+
*
1797+
* Original sender, info-state and webxdc updates are not forwarded on purpose.
1798+
*
17941799
* @memberof dc_context_t
17951800
* @param context The context object.
17961801
* @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);
39793984
*
39803985
* For privacy reasons, we do not provide the name or the e-mail address of the
39813986
* original author (in a typical GUI, you select the messages text and click on
3982-
* "forwared"; you won't expect other data to be send to the new recipient,
3987+
* "forwarded"; you won't expect other data to be send to the new recipient,
39833988
* esp. as the new recipient may not be in any relationship to the original author)
39843989
*
39853990
* @memberof dc_msg_t

src/chat.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5041,6 +5041,32 @@ mod tests {
50415041
Ok(())
50425042
}
50435043

5044+
#[async_std::test]
5045+
async fn test_forward_info_msg() -> Result<()> {
5046+
let t = TestContext::new_alice().await;
5047+
5048+
let chat_id1 = create_group_chat(&t, ProtectionStatus::Unprotected, "a").await?;
5049+
send_text_msg(&t, chat_id1, "msg one".to_string()).await?;
5050+
let bob_id = Contact::create(&t, "", "[email protected]").await?;
5051+
add_contact_to_chat(&t, chat_id1, bob_id).await?;
5052+
let msg1 = t.get_last_msg_in(chat_id1).await;
5053+
assert!(msg1.is_info());
5054+
assert!(msg1.get_text().unwrap().contains("[email protected]"));
5055+
5056+
let chat_id2 = ChatId::create_for_contact(&t, bob_id).await?;
5057+
assert_eq!(get_chat_msgs(&t, chat_id2, 0).await?.len(), 0);
5058+
forward_msgs(&t, &[msg1.id], chat_id2).await?;
5059+
let msg2 = t.get_last_msg_in(chat_id2).await;
5060+
assert!(!msg2.is_info()); // forwarded info-messages lose their info-state
5061+
assert_eq!(msg2.get_info_type(), SystemMessage::Unknown);
5062+
assert_ne!(msg2.from_id, ContactId::INFO);
5063+
assert_ne!(msg2.to_id, ContactId::INFO);
5064+
assert_eq!(msg2.get_text().unwrap(), msg1.get_text().unwrap());
5065+
assert!(msg2.is_forwarded());
5066+
5067+
Ok(())
5068+
}
5069+
50445070
#[async_std::test]
50455071
async fn test_forward_quote() -> Result<()> {
50465072
let alice = TestContext::new_alice().await;

0 commit comments

Comments
 (0)