mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 13:56:30 +03:00
Rename type_0 into viewtype
This commit is contained in:
32
src/chat.rs
32
src/chat.rs
@@ -489,7 +489,7 @@ impl Chat {
|
|||||||
DC_CONTACT_ID_SELF,
|
DC_CONTACT_ID_SELF,
|
||||||
to_id as i32,
|
to_id as i32,
|
||||||
timestamp,
|
timestamp,
|
||||||
msg.type_0,
|
msg.viewtype,
|
||||||
msg.state,
|
msg.state,
|
||||||
msg.text.as_ref().map_or("", String::as_str),
|
msg.text.as_ref().map_or("", String::as_str),
|
||||||
msg.param.to_string(),
|
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> {
|
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
|
// 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
|
let blob = msg
|
||||||
.param
|
.param
|
||||||
.get_blob(Param::File, context, !msg.is_increation())?
|
.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());
|
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
|
// Correct the type, take care not to correct already very special
|
||||||
// formats as GIF or VOICE.
|
// 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)) =
|
if let Some((better_type, better_mime)) =
|
||||||
message::guess_msgtype_from_suffix(&blob.to_abs_path())
|
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);
|
msg.param.set(Param::MimeType, better_mime);
|
||||||
}
|
}
|
||||||
} else if !msg.param.exists(Param::MimeType) {
|
} else if !msg.param.exists(Param::MimeType) {
|
||||||
@@ -872,10 +874,10 @@ fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<(), Error> {
|
|||||||
context,
|
context,
|
||||||
"Attaching \"{}\" for message type #{}.",
|
"Attaching \"{}\" for message type #{}.",
|
||||||
blob.to_abs_path().display(),
|
blob.to_abs_path().display(),
|
||||||
msg.type_0
|
msg.viewtype
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
bail!("Cannot send messages of type #{}.", msg.type_0);
|
bail!("Cannot send messages of type #{}.", msg.viewtype);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1058,7 +1060,7 @@ fn maybe_delete_draft(context: &Context, chat_id: u32) -> bool {
|
|||||||
///
|
///
|
||||||
/// Return true on success, false on database error.
|
/// Return true on success, false on database error.
|
||||||
fn do_set_draft(context: &Context, chat_id: u32, msg: &mut Message) -> Result<(), 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::Unknown => bail!("Can not set draft of unknown type."),
|
||||||
Viewtype::Text => match msg.text.as_ref() {
|
Viewtype::Text => match msg.text.as_ref() {
|
||||||
Some(text) => {
|
Some(text) => {
|
||||||
@@ -1085,7 +1087,7 @@ fn do_set_draft(context: &Context, chat_id: u32, msg: &mut Message) -> Result<()
|
|||||||
chat_id as i32,
|
chat_id as i32,
|
||||||
DC_CONTACT_ID_SELF,
|
DC_CONTACT_ID_SELF,
|
||||||
time(),
|
time(),
|
||||||
msg.type_0,
|
msg.viewtype,
|
||||||
MessageState::OutDraft,
|
MessageState::OutDraft,
|
||||||
msg.text.as_ref().map(String::as_str).unwrap_or(""),
|
msg.text.as_ref().map(String::as_str).unwrap_or(""),
|
||||||
msg.param.to_string(),
|
msg.param.to_string(),
|
||||||
@@ -1360,7 +1362,7 @@ pub fn get_next_media(
|
|||||||
if msg_type != Viewtype::Unknown {
|
if msg_type != Viewtype::Unknown {
|
||||||
msg_type
|
msg_type
|
||||||
} else {
|
} else {
|
||||||
msg.type_0
|
msg.viewtype
|
||||||
},
|
},
|
||||||
msg_type2,
|
msg_type2,
|
||||||
msg_type3,
|
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 {
|
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(
|
msg.text = Some(context.stock_system_msg(
|
||||||
StockMessage::MsgAddMember,
|
StockMessage::MsgAddMember,
|
||||||
contact.get_addr(),
|
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! */
|
/* 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 let Ok(contact) = Contact::get_by_id(context, contact_id) {
|
||||||
if chat.is_promoted() {
|
if chat.is_promoted() {
|
||||||
msg.type_0 = Viewtype::Text;
|
msg.viewtype = Viewtype::Text;
|
||||||
if contact.id == DC_CONTACT_ID_SELF {
|
if contact.id == DC_CONTACT_ID_SELF {
|
||||||
set_group_explicitly_left(context, chat.grpid)?;
|
set_group_explicitly_left(context, chat.grpid)?;
|
||||||
msg.text = Some(context.stock_system_msg(
|
msg.text = Some(context.stock_system_msg(
|
||||||
@@ -1910,7 +1912,7 @@ pub fn set_chat_name(
|
|||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
if chat.is_promoted() {
|
if chat.is_promoted() {
|
||||||
msg.type_0 = Viewtype::Text;
|
msg.viewtype = Viewtype::Text;
|
||||||
msg.text = Some(context.stock_system_msg(
|
msg.text = Some(context.stock_system_msg(
|
||||||
StockMessage::MsgGrpName,
|
StockMessage::MsgGrpName,
|
||||||
&chat.name,
|
&chat.name,
|
||||||
@@ -2174,7 +2176,7 @@ pub fn add_device_msg(
|
|||||||
DC_CONTACT_ID_DEVICE,
|
DC_CONTACT_ID_DEVICE,
|
||||||
DC_CONTACT_ID_SELF,
|
DC_CONTACT_ID_SELF,
|
||||||
dc_create_smeared_timestamp(context),
|
dc_create_smeared_timestamp(context),
|
||||||
msg.type_0,
|
msg.viewtype,
|
||||||
MessageState::InFresh,
|
MessageState::InFresh,
|
||||||
msg.text.as_ref().map_or("", String::as_str),
|
msg.text.as_ref().map_or("", String::as_str),
|
||||||
msg.param.to_string(),
|
msg.param.to_string(),
|
||||||
|
|||||||
@@ -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)?;
|
let chat_id = chat::create_by_contact_id(context, DC_CONTACT_ID_SELF)?;
|
||||||
msg = Message::default();
|
msg = Message::default();
|
||||||
msg.type_0 = Viewtype::File;
|
msg.viewtype = Viewtype::File;
|
||||||
msg.param.set(Param::File, setup_file_blob.as_name());
|
msg.param.set(Param::File, setup_file_blob.as_name());
|
||||||
|
|
||||||
msg.param
|
msg.param
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ pub struct Message {
|
|||||||
pub(crate) from_id: u32,
|
pub(crate) from_id: u32,
|
||||||
pub(crate) to_id: u32,
|
pub(crate) to_id: u32,
|
||||||
pub(crate) chat_id: u32,
|
pub(crate) chat_id: u32,
|
||||||
pub(crate) type_0: Viewtype,
|
pub(crate) viewtype: Viewtype,
|
||||||
pub(crate) state: MessageState,
|
pub(crate) state: MessageState,
|
||||||
pub(crate) hidden: bool,
|
pub(crate) hidden: bool,
|
||||||
pub(crate) timestamp_sort: i64,
|
pub(crate) timestamp_sort: i64,
|
||||||
@@ -183,7 +183,7 @@ pub struct Message {
|
|||||||
impl Message {
|
impl Message {
|
||||||
pub fn new(viewtype: Viewtype) -> Self {
|
pub fn new(viewtype: Viewtype) -> Self {
|
||||||
let mut msg = Message::default();
|
let mut msg = Message::default();
|
||||||
msg.type_0 = viewtype;
|
msg.viewtype = viewtype;
|
||||||
|
|
||||||
msg
|
msg
|
||||||
}
|
}
|
||||||
@@ -236,7 +236,7 @@ impl Message {
|
|||||||
msg.timestamp_sort = row.get("timestamp")?;
|
msg.timestamp_sort = row.get("timestamp")?;
|
||||||
msg.timestamp_sent = row.get("timestamp_sent")?;
|
msg.timestamp_sent = row.get("timestamp_sent")?;
|
||||||
msg.timestamp_rcvd = row.get("timestamp_rcvd")?;
|
msg.timestamp_rcvd = row.get("timestamp_rcvd")?;
|
||||||
msg.type_0 = row.get("type")?;
|
msg.viewtype = row.get("type")?;
|
||||||
msg.state = row.get("state")?;
|
msg.state = row.get("state")?;
|
||||||
msg.is_dc_message = row.get("msgrmsg")?;
|
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> {
|
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)?;
|
let file_param = self.param.get_path(Param::File, context)?;
|
||||||
if let Some(path_and_filename) = file_param {
|
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.exists(Param::Width)
|
||||||
{
|
{
|
||||||
self.param.set_int(Param::Width, 0);
|
self.param.set_int(Param::Width, 0);
|
||||||
@@ -394,7 +394,7 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_viewtype(&self) -> Viewtype {
|
pub fn get_viewtype(&self) -> Viewtype {
|
||||||
self.type_0
|
self.viewtype
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_state(&self) -> MessageState {
|
pub fn get_state(&self) -> MessageState {
|
||||||
@@ -474,7 +474,7 @@ impl Message {
|
|||||||
|
|
||||||
pub fn get_summarytext(&self, context: &Context, approx_characters: usize) -> String {
|
pub fn get_summarytext(&self, context: &Context, approx_characters: usize) -> String {
|
||||||
get_summarytext_by_raw(
|
get_summarytext_by_raw(
|
||||||
self.type_0,
|
self.viewtype,
|
||||||
self.text.as_ref(),
|
self.text.as_ref(),
|
||||||
&self.param,
|
&self.param,
|
||||||
approx_characters,
|
approx_characters,
|
||||||
@@ -518,11 +518,11 @@ impl Message {
|
|||||||
/// copied to the blobdir. Thus those attachments need to be
|
/// copied to the blobdir. Thus those attachments need to be
|
||||||
/// created immediately in the blobdir with a valid filename.
|
/// created immediately in the blobdir with a valid filename.
|
||||||
pub fn is_increation(&self) -> bool {
|
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 {
|
pub fn is_setupmessage(&self) -> bool {
|
||||||
if self.type_0 != Viewtype::File {
|
if self.viewtype != Viewtype::File {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,7 +687,7 @@ impl Lot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.text2 = Some(get_summarytext_by_raw(
|
self.text2 = Some(get_summarytext_by_raw(
|
||||||
msg.type_0,
|
msg.viewtype,
|
||||||
msg.text.as_ref(),
|
msg.text.as_ref(),
|
||||||
&msg.param,
|
&msg.param,
|
||||||
SUMMARY_CHARACTERS,
|
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);
|
ret += &format!("\nFile: {}, {}, bytes\n", path.display(), bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.type_0 != Viewtype::Text {
|
if msg.viewtype != Viewtype::Text {
|
||||||
ret += "Type: ";
|
ret += "Type: ";
|
||||||
ret += &format!("{}", msg.type_0);
|
ret += &format!("{}", msg.viewtype);
|
||||||
ret += "\n";
|
ret += "\n";
|
||||||
ret += &format!("Mimetype: {}\n", &msg.get_filemime().unwrap_or_default());
|
ret += &format!("Mimetype: {}\n", &msg.get_filemime().unwrap_or_default());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -352,7 +352,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
match self.chat {
|
match self.chat {
|
||||||
Some(ref chat) => {
|
Some(ref chat) => {
|
||||||
let raw = message::get_summarytext_by_raw(
|
let raw = message::get_summarytext_by_raw(
|
||||||
self.msg.type_0,
|
self.msg.viewtype,
|
||||||
self.msg.text.as_ref(),
|
self.msg.text.as_ref(),
|
||||||
&self.msg.param,
|
&self.msg.param,
|
||||||
32,
|
32,
|
||||||
@@ -761,7 +761,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
if let Some(grpimage) = grpimage {
|
if let Some(grpimage) = grpimage {
|
||||||
info!(self.context, "setting group image '{}'", grpimage);
|
info!(self.context, "setting group image '{}'", grpimage);
|
||||||
let mut meta = Message::default();
|
let mut meta = Message::default();
|
||||||
meta.type_0 = Viewtype::Image;
|
meta.viewtype = Viewtype::Image;
|
||||||
meta.param.set(Param::File, grpimage);
|
meta.param.set(Param::File, grpimage);
|
||||||
|
|
||||||
let (mail, filename_as_sent) = build_body_file(context, &meta, "group-image")?;
|
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()));
|
protected_headers.push(Header::new("Chat-Content".into(), "sticker".into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.msg.type_0 == Viewtype::Voice
|
if self.msg.viewtype == Viewtype::Voice
|
||||||
|| self.msg.type_0 == Viewtype::Audio
|
|| self.msg.viewtype == Viewtype::Audio
|
||||||
|| self.msg.type_0 == Viewtype::Video
|
|| 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()));
|
protected_headers.push(Header::new("Chat-Voice-Message".into(), "1".into()));
|
||||||
}
|
}
|
||||||
let duration_ms = self.msg.param.get_int(Param::Duration).unwrap_or_default();
|
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)];
|
.body(message_text)];
|
||||||
|
|
||||||
// add attachment part
|
// 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) {
|
if !is_file_size_okay(context, &self.msg) {
|
||||||
bail!(
|
bail!(
|
||||||
"Message exceeds the recommended {} MB.",
|
"Message exceeds the recommended {} MB.",
|
||||||
@@ -939,7 +939,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
/// Render an MDN
|
/// Render an MDN
|
||||||
fn render_mdn(&mut self) -> Result<PartBuilder, Error> {
|
fn render_mdn(&mut self) -> Result<PartBuilder, Error> {
|
||||||
// RFC 6522, this also requires the `report-type` parameter which is equal
|
// 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:
|
// 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
|
// - 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
|
// not transfer the original filenames eg. for images; these names
|
||||||
// are normally not needed and contain timestamps, running numbers
|
// are normally not needed and contain timestamps, running numbers
|
||||||
// etc.
|
// etc.
|
||||||
let filename_to_send: String = match msg.type_0 {
|
let filename_to_send: String = match msg.viewtype {
|
||||||
Viewtype::Voice => chrono::Utc
|
Viewtype::Voice => chrono::Utc
|
||||||
.timestamp(msg.timestamp_sort as i64, 0)
|
.timestamp(msg.timestamp_sort as i64, 0)
|
||||||
.format(&format!("voice-message_%Y-%m-%d_%H-%M-%S.{}", &suffix))
|
.format(&format!("voice-message_%Y-%m-%d_%H-%M-%S.{}", &suffix))
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ fn send_handshake_msg(
|
|||||||
grpid: impl AsRef<str>,
|
grpid: impl AsRef<str>,
|
||||||
) {
|
) {
|
||||||
let mut msg = Message::default();
|
let mut msg = Message::default();
|
||||||
msg.type_0 = Viewtype::Text;
|
msg.viewtype = Viewtype::Text;
|
||||||
msg.text = Some(format!("Secure-Join: {}", step));
|
msg.text = Some(format!("Secure-Join: {}", step));
|
||||||
msg.hidden = true;
|
msg.hidden = true;
|
||||||
msg.param.set_cmd(SystemMessage::SecurejoinMessage);
|
msg.param.set_cmd(SystemMessage::SecurejoinMessage);
|
||||||
|
|||||||
Reference in New Issue
Block a user