MCPcopy Create free account
hub / github.com/chatmail/core / send_msg

Function send_msg

src/chat.rs:2607–2637  ·  view source on GitHub ↗

Sends a message object to a chat. Sends the event #DC_EVENT_MSGS_CHANGED on success. However, this does not imply, the message really reached the recipient - sending may be delayed eg. due to network problems. However, from your view, you're done with the message. Sooner or later it will find its way.

(context: &Context, chat_id: ChatId, msg: &mut Message)

Source from the content-addressed store, hash-verified

2605/// sending may be delayed eg. due to network problems. However, from your
2606/// view, you're done with the message. Sooner or later it will find its way.
2607pub async fn send_msg(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result<MsgId> {
2608 ensure!(
2609 !chat_id.is_special(),
2610 "chat_id cannot be a special chat: {chat_id}"
2611 );
2612
2613 if msg.state != MessageState::Undefined {
2614 msg.param.remove(Param::GuaranteeE2ee);
2615 msg.param.remove(Param::ForcePlaintext);
2616 // create_send_msg_jobs() will update `param` in the db.
2617 }
2618
2619 // protect all system messages against RTLO attacks
2620 if msg.is_system_message() {
2621 msg.text = sanitize_bidi_characters(&msg.text);
2622 }
2623
2624 if !prepare_send_msg(context, chat_id, msg).await?.is_empty() {
2625 if !msg.hidden {
2626 context.emit_msgs_changed(msg.chat_id, msg.id);
2627 }
2628
2629 if msg.param.exists(Param::SetLatitude) {
2630 context.emit_location_changed(Some(ContactId::SELF)).await?;
2631 }
2632
2633 context.scheduler.interrupt_smtp().await;
2634 }
2635
2636 Ok(msg.id)
2637}
2638
2639/// Tries to send a message synchronously.
2640///

Callers 15

cmdlineFunction · 0.85
dc_send_msgFunction · 0.85
send_stickerMethod · 0.85
send_msgMethod · 0.85
misc_send_msgMethod · 0.85
misc_send_draftMethod · 0.85
send_alice_handshake_msgFunction · 0.85
send_text_msgFunction · 0.85
send_edit_requestFunction · 0.85
add_contact_to_chat_exFunction · 0.85

Calls 9

sanitize_bidi_charactersFunction · 0.85
prepare_send_msgFunction · 0.85
emit_msgs_changedMethod · 0.80
emit_location_changedMethod · 0.80
interrupt_smtpMethod · 0.80
removeMethod · 0.45
is_system_messageMethod · 0.45
is_emptyMethod · 0.45
existsMethod · 0.45

Tested by 15

test_set_htmlFunction · 0.68
send_msgMethod · 0.68
test_can_communicateFunction · 0.68
test_can_reconnectFunction · 0.68
test_subject_mdnFunction · 0.68
first_subject_strFunction · 0.68
msg_to_subject_str_innerFunction · 0.68
test_render_replyFunction · 0.68
test_search_msgsFunction · 0.68
test_limit_search_msgsFunction · 0.68
test_draft_stable_idsFunction · 0.68