Rename type_0 into viewtype

This commit is contained in:
Alexander Krotov
2020-01-08 11:50:15 +03:00
parent 72cfb70e35
commit 12cd56e3e8
5 changed files with 41 additions and 39 deletions

View File

@@ -489,7 +489,7 @@ impl Chat {
DC_CONTACT_ID_SELF,
to_id as i32,
timestamp,
msg.type_0,
msg.viewtype,
msg.state,
msg.text.as_ref().map_or("", String::as_str),
msg.param.to_string(),
@@ -841,16 +841,18 @@ pub fn msgtype_has_file(msgtype: Viewtype) -> bool {
}
fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<(), Error> {
if msg.type_0 == Viewtype::Text {
if msg.viewtype == Viewtype::Text {
// the caller should check if the message text is empty
} else if msgtype_has_file(msg.type_0) {
} else if msgtype_has_file(msg.viewtype) {
let blob = msg
.param
.get_blob(Param::File, context, !msg.is_increation())?
.ok_or_else(|| format_err!("Attachment missing for message of type #{}", msg.type_0))?;
.ok_or_else(|| {
format_err!("Attachment missing for message of type #{}", msg.viewtype)
})?;
msg.param.set(Param::File, blob.as_name());
if msg.type_0 == Viewtype::File || msg.type_0 == Viewtype::Image {
if msg.viewtype == Viewtype::File || msg.viewtype == Viewtype::Image {
// Correct the type, take care not to correct already very special
// formats as GIF or VOICE.
//
@@ -860,7 +862,7 @@ fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<(), Error> {
if let Some((better_type, better_mime)) =
message::guess_msgtype_from_suffix(&blob.to_abs_path())
{
msg.type_0 = better_type;
msg.viewtype = better_type;
msg.param.set(Param::MimeType, better_mime);
}
} else if !msg.param.exists(Param::MimeType) {
@@ -872,10 +874,10 @@ fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<(), Error> {
context,
"Attaching \"{}\" for message type #{}.",
blob.to_abs_path().display(),
msg.type_0
msg.viewtype
);
} else {
bail!("Cannot send messages of type #{}.", msg.type_0);
bail!("Cannot send messages of type #{}.", msg.viewtype);
}
Ok(())
}
@@ -1058,7 +1060,7 @@ fn maybe_delete_draft(context: &Context, chat_id: u32) -> bool {
///
/// Return true on success, false on database error.
fn do_set_draft(context: &Context, chat_id: u32, msg: &mut Message) -> Result<(), Error> {
match msg.type_0 {
match msg.viewtype {
Viewtype::Unknown => bail!("Can not set draft of unknown type."),
Viewtype::Text => match msg.text.as_ref() {
Some(text) => {
@@ -1085,7 +1087,7 @@ fn do_set_draft(context: &Context, chat_id: u32, msg: &mut Message) -> Result<()
chat_id as i32,
DC_CONTACT_ID_SELF,
time(),
msg.type_0,
msg.viewtype,
MessageState::OutDraft,
msg.text.as_ref().map(String::as_str).unwrap_or(""),
msg.param.to_string(),
@@ -1360,7 +1362,7 @@ pub fn get_next_media(
if msg_type != Viewtype::Unknown {
msg_type
} else {
msg.type_0
msg.viewtype
},
msg_type2,
msg_type3,
@@ -1637,7 +1639,7 @@ pub(crate) fn add_contact_to_chat_ex(
}
}
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
msg.type_0 = Viewtype::Text;
msg.viewtype = Viewtype::Text;
msg.text = Some(context.stock_system_msg(
StockMessage::MsgAddMember,
contact.get_addr(),
@@ -1806,7 +1808,7 @@ pub fn remove_contact_from_chat(
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
if let Ok(contact) = Contact::get_by_id(context, contact_id) {
if chat.is_promoted() {
msg.type_0 = Viewtype::Text;
msg.viewtype = Viewtype::Text;
if contact.id == DC_CONTACT_ID_SELF {
set_group_explicitly_left(context, chat.grpid)?;
msg.text = Some(context.stock_system_msg(
@@ -1910,7 +1912,7 @@ pub fn set_chat_name(
.is_ok()
{
if chat.is_promoted() {
msg.type_0 = Viewtype::Text;
msg.viewtype = Viewtype::Text;
msg.text = Some(context.stock_system_msg(
StockMessage::MsgGrpName,
&chat.name,
@@ -2174,7 +2176,7 @@ pub fn add_device_msg(
DC_CONTACT_ID_DEVICE,
DC_CONTACT_ID_SELF,
dc_create_smeared_timestamp(context),
msg.type_0,
msg.viewtype,
MessageState::InFresh,
msg.text.as_ref().map_or("", String::as_str),
msg.param.to_string(),

View File

@@ -137,7 +137,7 @@ fn do_initiate_key_transfer(context: &Context) -> Result<String> {
let chat_id = chat::create_by_contact_id(context, DC_CONTACT_ID_SELF)?;
msg = Message::default();
msg.type_0 = Viewtype::File;
msg.viewtype = Viewtype::File;
msg.param.set(Param::File, setup_file_blob.as_name());
msg.param

View File

@@ -161,7 +161,7 @@ pub struct Message {
pub(crate) from_id: u32,
pub(crate) to_id: u32,
pub(crate) chat_id: u32,
pub(crate) type_0: Viewtype,
pub(crate) viewtype: Viewtype,
pub(crate) state: MessageState,
pub(crate) hidden: bool,
pub(crate) timestamp_sort: i64,
@@ -183,7 +183,7 @@ pub struct Message {
impl Message {
pub fn new(viewtype: Viewtype) -> Self {
let mut msg = Message::default();
msg.type_0 = viewtype;
msg.viewtype = viewtype;
msg
}
@@ -236,7 +236,7 @@ impl Message {
msg.timestamp_sort = row.get("timestamp")?;
msg.timestamp_sent = row.get("timestamp_sent")?;
msg.timestamp_rcvd = row.get("timestamp_rcvd")?;
msg.type_0 = row.get("type")?;
msg.viewtype = row.get("type")?;
msg.state = row.get("state")?;
msg.is_dc_message = row.get("msgrmsg")?;
@@ -312,10 +312,10 @@ impl Message {
}
pub fn try_calc_and_set_dimensions(&mut self, context: &Context) -> Result<(), Error> {
if chat::msgtype_has_file(self.type_0) {
if chat::msgtype_has_file(self.viewtype) {
let file_param = self.param.get_path(Param::File, context)?;
if let Some(path_and_filename) = file_param {
if (self.type_0 == Viewtype::Image || self.type_0 == Viewtype::Gif)
if (self.viewtype == Viewtype::Image || self.viewtype == Viewtype::Gif)
&& !self.param.exists(Param::Width)
{
self.param.set_int(Param::Width, 0);
@@ -394,7 +394,7 @@ impl Message {
}
pub fn get_viewtype(&self) -> Viewtype {
self.type_0
self.viewtype
}
pub fn get_state(&self) -> MessageState {
@@ -474,7 +474,7 @@ impl Message {
pub fn get_summarytext(&self, context: &Context, approx_characters: usize) -> String {
get_summarytext_by_raw(
self.type_0,
self.viewtype,
self.text.as_ref(),
&self.param,
approx_characters,
@@ -518,11 +518,11 @@ impl Message {
/// copied to the blobdir. Thus those attachments need to be
/// created immediately in the blobdir with a valid filename.
pub fn is_increation(&self) -> bool {
chat::msgtype_has_file(self.type_0) && self.state == MessageState::OutPreparing
chat::msgtype_has_file(self.viewtype) && self.state == MessageState::OutPreparing
}
pub fn is_setupmessage(&self) -> bool {
if self.type_0 != Viewtype::File {
if self.viewtype != Viewtype::File {
return false;
}
@@ -687,7 +687,7 @@ impl Lot {
}
self.text2 = Some(get_summarytext_by_raw(
msg.type_0,
msg.viewtype,
msg.text.as_ref(),
&msg.param,
SUMMARY_CHARACTERS,
@@ -808,9 +808,9 @@ pub fn get_msg_info(context: &Context, msg_id: MsgId) -> String {
ret += &format!("\nFile: {}, {}, bytes\n", path.display(), bytes);
}
if msg.type_0 != Viewtype::Text {
if msg.viewtype != Viewtype::Text {
ret += "Type: ";
ret += &format!("{}", msg.type_0);
ret += &format!("{}", msg.viewtype);
ret += "\n";
ret += &format!("Mimetype: {}\n", &msg.get_filemime().unwrap_or_default());
}

View File

@@ -352,7 +352,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
match self.chat {
Some(ref chat) => {
let raw = message::get_summarytext_by_raw(
self.msg.type_0,
self.msg.viewtype,
self.msg.text.as_ref(),
&self.msg.param,
32,
@@ -761,7 +761,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
if let Some(grpimage) = grpimage {
info!(self.context, "setting group image '{}'", grpimage);
let mut meta = Message::default();
meta.type_0 = Viewtype::Image;
meta.viewtype = Viewtype::Image;
meta.param.set(Param::File, grpimage);
let (mail, filename_as_sent) = build_body_file(context, &meta, "group-image")?;
@@ -780,15 +780,15 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
}
}
if self.msg.type_0 == Viewtype::Sticker {
if self.msg.viewtype == Viewtype::Sticker {
protected_headers.push(Header::new("Chat-Content".into(), "sticker".into()));
}
if self.msg.type_0 == Viewtype::Voice
|| self.msg.type_0 == Viewtype::Audio
|| self.msg.type_0 == Viewtype::Video
if self.msg.viewtype == Viewtype::Voice
|| self.msg.viewtype == Viewtype::Audio
|| self.msg.viewtype == Viewtype::Video
{
if self.msg.type_0 == Viewtype::Voice {
if self.msg.viewtype == Viewtype::Voice {
protected_headers.push(Header::new("Chat-Voice-Message".into(), "1".into()));
}
let duration_ms = self.msg.param.get_int(Param::Duration).unwrap_or_default();
@@ -844,7 +844,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
.body(message_text)];
// add attachment part
if chat::msgtype_has_file(self.msg.type_0) {
if chat::msgtype_has_file(self.msg.viewtype) {
if !is_file_size_okay(context, &self.msg) {
bail!(
"Message exceeds the recommended {} MB.",
@@ -939,7 +939,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
/// Render an MDN
fn render_mdn(&mut self) -> Result<PartBuilder, Error> {
// RFC 6522, this also requires the `report-type` parameter which is equal
// to the MIME subtype of the second body part of the multipart/report */
// to the MIME subtype of the second body part of the multipart/report
//
// currently, we do not send MDNs encrypted:
// - in a multi-device-setup that is not set up properly, MDNs would disturb the communication as they
@@ -1031,7 +1031,7 @@ fn build_body_file(
// not transfer the original filenames eg. for images; these names
// are normally not needed and contain timestamps, running numbers
// etc.
let filename_to_send: String = match msg.type_0 {
let filename_to_send: String = match msg.viewtype {
Viewtype::Voice => chrono::Utc
.timestamp(msg.timestamp_sort as i64, 0)
.format(&format!("voice-message_%Y-%m-%d_%H-%M-%S.{}", &suffix))

View File

@@ -258,7 +258,7 @@ fn send_handshake_msg(
grpid: impl AsRef<str>,
) {
let mut msg = Message::default();
msg.type_0 = Viewtype::Text;
msg.viewtype = Viewtype::Text;
msg.text = Some(format!("Secure-Join: {}", step));
msg.hidden = true;
msg.param.set_cmd(SystemMessage::SecurejoinMessage);