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

Method prepare_msg_raw

src/chat.rs:1756–2025  ·  view source on GitHub ↗

Adds missing values to the msg object, writes the record to the database. If `update_msg_id` is set, that record is reused; if `update_msg_id` is None, a new record is created.

(
        &mut self,
        context: &Context,
        msg: &mut Message,
        update_msg_id: Option<MsgId>,
    )

Source from the content-addressed store, hash-verified

1754 /// If `update_msg_id` is set, that record is reused;
1755 /// if `update_msg_id` is None, a new record is created.
1756 async fn prepare_msg_raw(
1757 &mut self,
1758 context: &Context,
1759 msg: &mut Message,
1760 update_msg_id: Option<MsgId>,
1761 ) -> Result<()> {
1762 let mut to_id = 0;
1763 let mut location_id = 0;
1764
1765 if msg.rfc724_mid.is_empty() {
1766 msg.rfc724_mid = create_outgoing_rfc724_mid();
1767 }
1768
1769 if self.typ == Chattype::Single {
1770 if let Some(id) = context
1771 .sql
1772 .query_get_value(
1773 "SELECT contact_id FROM chats_contacts WHERE chat_id=?;",
1774 (self.id,),
1775 )
1776 .await?
1777 {
1778 to_id = id;
1779 } else {
1780 error!(
1781 context,
1782 "Cannot send message, contact for {} not found.", self.id,
1783 );
1784 bail!("Cannot set message, contact for {} not found.", self.id);
1785 }
1786 } else if self.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 {
1787 ensure_and_debug_assert_eq!(self.typ, Chattype::Group,);
1788 msg.param.set_int(Param::AttachChatAvatarAndDescription, 1);
1789 self.param
1790 .remove(Param::Unpromoted)
1791 .set_i64(Param::GroupNameTimestamp, msg.timestamp_sort)
1792 .set_i64(Param::GroupDescriptionTimestamp, msg.timestamp_sort);
1793 self.update_param(context).await?;
1794 }
1795
1796 let is_bot = context.get_config_bool(Config::Bot).await?;
1797 msg.param
1798 .set_optional(Param::Bot, Some("1").filter(|_| is_bot));
1799
1800 // Set "In-Reply-To:" to identify the message to which the composed message is a reply.
1801 // Set "References:" to identify the "thread" of the conversation.
1802 // Both according to [RFC 5322 3.6.4, page 25](https://www.rfc-editor.org/rfc/rfc5322#section-3.6.4).
1803 let new_references;
1804 if self.is_self_talk() {
1805 // As self-talks are mainly used to transfer data between devices,
1806 // we do not set In-Reply-To/References in this case.
1807 new_references = String::new();
1808 } else if let Some((parent_rfc724_mid, parent_in_reply_to, parent_references)) =
1809 // We don't filter `OutPending` and `OutFailed` messages because the new message for
1810 // which `parent_query()` is done may assume that it will be received in a context
1811 // affected by those messages, e.g. they could add new members to a group and the
1812 // new message will contain them in "To:". Anyway recipients must be prepared to
1813 // orphaned references.

Callers 2

prepare_send_msgFunction · 0.80
forward_msgs_2ctxFunction · 0.80

Calls 15

timeFunction · 0.85
truncate_msg_textFunction · 0.85
buf_compressFunction · 0.85
maybe_set_logging_xdcFunction · 0.85
query_get_valueMethod · 0.80
get_intMethod · 0.80
set_intMethod · 0.80
set_i64Method · 0.80
get_config_boolMethod · 0.80
set_optionalMethod · 0.80

Tested by

no test coverage detected