Skip to content

Commit c5658fb

Browse files
committed
remove default usage
1 parent c384387 commit c5658fb

File tree

4 files changed

+11
-40
lines changed

4 files changed

+11
-40
lines changed

deltachat-ffi/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use deltachat::*;
3737
use deltachat::{accounts::Accounts, log::LogExt};
3838
use deltachat_jsonrpc::api::CommandApi;
3939
use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession};
40+
use message::Viewtype;
4041
use num_traits::{FromPrimitive, ToPrimitive};
4142
use once_cell::sync::Lazy;
4243
use rand::Rng;
@@ -2076,7 +2077,7 @@ pub unsafe extern "C" fn dc_get_msg(context: *mut dc_context_t, msg_id: u32) ->
20762077
ctx,
20772078
"dc_get_msg called with special msg_id={msg_id}, returning empty msg"
20782079
);
2079-
message::Message::default()
2080+
message::Message::new(Viewtype::default())
20802081
} else {
20812082
warn!(ctx, "dc_get_msg could not retrieve msg_id {msg_id}: {e:#}");
20822083
return ptr::null_mut();

src/chat.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,10 @@ impl Chat {
20222022
let mut to_id = 0;
20232023
let mut location_id = 0;
20242024

2025+
if msg.rfc724_mid.is_empty() {
2026+
msg.rfc724_mid = create_outgoing_rfc724_mid();
2027+
}
2028+
20252029
if self.typ == Chattype::Single {
20262030
if let Some(id) = context
20272031
.sql
@@ -3864,7 +3868,7 @@ pub(crate) async fn add_contact_to_chat_ex(
38643868
) -> Result<bool> {
38653869
ensure!(!chat_id.is_special(), "can not add member to special chats");
38663870
let contact = Contact::get_by_id(context, contact_id).await?;
3867-
let mut msg = Message::default();
3871+
let mut msg = Message::new(Viewtype::default());
38683872

38693873
chat_id.reset_gossiped_timestamp(context).await?;
38703874

@@ -4091,7 +4095,7 @@ pub async fn remove_contact_from_chat(
40914095
"Cannot remove special contact"
40924096
);
40934097

4094-
let mut msg = Message::default();
4098+
let mut msg = Message::new(Viewtype::default());
40954099

40964100
let chat = Chat::load_from_db(context, chat_id).await?;
40974101
if chat.typ == Chattype::Group || chat.typ == Chattype::Broadcast {
@@ -4196,7 +4200,7 @@ async fn rename_ex(
41964200
ensure!(!chat_id.is_special(), "Invalid chat ID");
41974201

41984202
let chat = Chat::load_from_db(context, chat_id).await?;
4199-
let mut msg = Message::default();
4203+
let mut msg = Message::new(Viewtype::default());
42004204

42014205
if chat.typ == Chattype::Group
42024206
|| chat.typ == Chattype::Mailinglist

src/imex/key_transfer.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ pub async fn initiate_key_transfer(context: &Context) -> Result<String> {
3232
)?;
3333

3434
let chat_id = ChatId::create_for_contact(context, ContactId::SELF).await?;
35-
let mut msg = Message {
36-
viewtype: Viewtype::File,
37-
..Default::default()
38-
};
35+
let mut msg = Message::new(Viewtype::File);
3936
msg.param.set(Param::File, setup_file_blob.as_name());
4037
msg.param
4138
.set(Param::Filename, "autocrypt-setup-message.html");

src/message.rs

+1-32
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl Default for MessengerMessage {
432432
/// An object representing a single message in memory.
433433
/// The message object is not updated.
434434
/// If you want an update, you have to recreate the object.
435-
#[derive(Debug, Clone, Serialize, Deserialize)]
435+
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
436436
pub struct Message {
437437
/// Message ID.
438438
pub(crate) id: MsgId,
@@ -481,37 +481,6 @@ pub struct Message {
481481
pub(crate) param: Params,
482482
}
483483

484-
impl Default for Message {
485-
fn default() -> Self {
486-
Self {
487-
id: Default::default(),
488-
from_id: Default::default(),
489-
to_id: Default::default(),
490-
chat_id: Default::default(),
491-
viewtype: Default::default(),
492-
state: Default::default(),
493-
download_state: Default::default(),
494-
hidden: Default::default(),
495-
timestamp_sort: Default::default(),
496-
timestamp_sent: Default::default(),
497-
timestamp_rcvd: Default::default(),
498-
ephemeral_timer: Default::default(),
499-
ephemeral_timestamp: Default::default(),
500-
text: Default::default(),
501-
subject: Default::default(),
502-
rfc724_mid: create_outgoing_rfc724_mid(),
503-
in_reply_to: Default::default(),
504-
is_dc_message: Default::default(),
505-
original_msg_id: Default::default(),
506-
mime_modified: Default::default(),
507-
chat_blocked: Default::default(),
508-
location_id: Default::default(),
509-
error: Default::default(),
510-
param: Default::default(),
511-
}
512-
}
513-
}
514-
515484
impl Message {
516485
/// Creates a new message with given view type.
517486
pub fn new(viewtype: Viewtype) -> Self {

0 commit comments

Comments
 (0)