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)
| 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. |
| 2607 | pub 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 | /// |