Add MessengerMessage type for is_dc_message field

This commit is contained in:
Alexander Krotov
2020-01-08 12:01:21 +03:00
parent 12cd56e3e8
commit 02bb41697d
3 changed files with 45 additions and 24 deletions

View File

@@ -17,7 +17,7 @@ use crate::job_thread::JobThread;
use crate::key::*; use crate::key::*;
use crate::login_param::LoginParam; use crate::login_param::LoginParam;
use crate::lot::Lot; use crate::lot::Lot;
use crate::message::{self, Message, MsgId}; use crate::message::{self, Message, MessengerMessage, MsgId};
use crate::param::Params; use crate::param::Params;
use crate::smtp::Smtp; use crate::smtp::Smtp;
use crate::sql::Sql; use crate::sql::Sql;
@@ -440,15 +440,17 @@ impl Context {
return; return;
} }
// 1 = dc message, 2 = reply to dc message match msg.is_dc_message {
if 0 != msg.is_dc_message { MessengerMessage::No => {}
job_add( MessengerMessage::Yes | MessengerMessage::Reply => {
self, job_add(
Action::MoveMsg, self,
msg.id.to_u32() as i32, Action::MoveMsg,
Params::new(), msg.id.to_u32() as i32,
0, Params::new(),
); 0,
);
}
} }
} }
} }

View File

@@ -13,7 +13,7 @@ use crate::error::Result;
use crate::events::Event; use crate::events::Event;
use crate::headerdef::HeaderDef; use crate::headerdef::HeaderDef;
use crate::job::*; use crate::job::*;
use crate::message::{self, MessageState, MsgId}; use crate::message::{self, MessageState, MessengerMessage, MsgId};
use crate::mimeparser::*; use crate::mimeparser::*;
use crate::param::*; use crate::param::*;
use crate::peerstate::*; use crate::peerstate::*;
@@ -271,7 +271,6 @@ fn add_parts(
create_event_to_send: &mut Option<CreateEvent>, create_event_to_send: &mut Option<CreateEvent>,
) -> Result<()> { ) -> Result<()> {
let mut state: MessageState; let mut state: MessageState;
let mut msgrmsg: i32;
let mut chat_id_blocked = Blocked::Not; let mut chat_id_blocked = Blocked::Not;
let mut sort_timestamp = 0; let mut sort_timestamp = 0;
let mut rcvd_timestamp = 0; let mut rcvd_timestamp = 0;
@@ -292,18 +291,21 @@ fn add_parts(
bail!("Message already in DB"); bail!("Message already in DB");
} }
// 1 or 0 for yes/no let mut msgrmsg = if mime_parser.has_chat_version() {
msgrmsg = mime_parser.has_chat_version() as _; MessengerMessage::Yes
if msgrmsg == 0 && is_reply_to_messenger_message(context, mime_parser) { } else if is_reply_to_messenger_message(context, mime_parser) {
// 2=no, but is reply to messenger message MessengerMessage::Reply
msgrmsg = 2; } else {
} MessengerMessage::No
};
// incoming non-chat messages may be discarded; // incoming non-chat messages may be discarded;
// maybe this can be optimized later, by checking the state before the message body is downloaded // maybe this can be optimized later, by checking the state before the message body is downloaded
let mut allow_creation = true; let mut allow_creation = true;
let show_emails = let show_emails =
ShowEmails::from_i32(context.get_config_int(Config::ShowEmails)).unwrap_or_default(); ShowEmails::from_i32(context.get_config_int(Config::ShowEmails)).unwrap_or_default();
if mime_parser.is_system_message != SystemMessage::AutocryptSetupMessage && msgrmsg == 0 { if mime_parser.is_system_message != SystemMessage::AutocryptSetupMessage
&& msgrmsg == MessengerMessage::No
{
// this message is a classic email not a chat-message nor a reply to one // this message is a classic email not a chat-message nor a reply to one
if show_emails == ShowEmails::Off { if show_emails == ShowEmails::Off {
*chat_id = DC_CHAT_ID_TRASH; *chat_id = DC_CHAT_ID_TRASH;
@@ -332,7 +334,7 @@ fn add_parts(
// (eg. contacs may be marked as verified) // (eg. contacs may be marked as verified)
if mime_parser.get(HeaderDef::SecureJoin).is_some() { if mime_parser.get(HeaderDef::SecureJoin).is_some() {
// avoid discarding by show_emails setting // avoid discarding by show_emails setting
msgrmsg = 1; msgrmsg = MessengerMessage::Yes;
*chat_id = 0; *chat_id = 0;
allow_creation = true; allow_creation = true;
match handle_securejoin_handshake(context, mime_parser, from_id) { match handle_securejoin_handshake(context, mime_parser, from_id) {
@@ -447,7 +449,7 @@ fn add_parts(
if Blocked::Not != chat_id_blocked if Blocked::Not != chat_id_blocked
&& state == MessageState::InFresh && state == MessageState::InFresh
&& !incoming_origin.is_known() && !incoming_origin.is_known()
&& msgrmsg == 0 && msgrmsg == MessengerMessage::No
&& show_emails != ShowEmails::All && show_emails != ShowEmails::All
{ {
state = MessageState::InNoticed; state = MessageState::InNoticed;
@@ -485,7 +487,9 @@ fn add_parts(
} }
} }
if *chat_id == 0 && allow_creation { if *chat_id == 0 && allow_creation {
let create_blocked = if 0 != msgrmsg && !Contact::is_blocked_load(context, to_id) { let create_blocked = if MessengerMessage::No != msgrmsg
&& !Contact::is_blocked_load(context, to_id)
{
Blocked::Not Blocked::Not
} else { } else {
Blocked::Deaddrop Blocked::Deaddrop

View File

@@ -148,6 +148,22 @@ impl rusqlite::types::FromSql for MsgId {
#[fail(display = "Invalid Message ID.")] #[fail(display = "Invalid Message ID.")]
pub struct InvalidMsgId; pub struct InvalidMsgId;
#[derive(Debug, Copy, Clone, PartialEq, FromPrimitive, ToPrimitive, FromSql, ToSql)]
#[repr(u8)]
pub enum MessengerMessage {
No = 0,
Yes = 1,
/// No, but reply to messenger message.
Reply = 2,
}
impl Default for MessengerMessage {
fn default() -> Self {
Self::No
}
}
/// An object representing a single message in memory. /// An object representing a single message in memory.
/// The message object is not updated. /// The message object is not updated.
/// If you want an update, you have to recreate the object. /// If you want an update, you have to recreate the object.
@@ -172,8 +188,7 @@ pub struct Message {
pub(crate) in_reply_to: Option<String>, pub(crate) in_reply_to: Option<String>,
pub(crate) server_folder: Option<String>, pub(crate) server_folder: Option<String>,
pub(crate) server_uid: u32, pub(crate) server_uid: u32,
// TODO: enum pub(crate) is_dc_message: MessengerMessage,
pub(crate) is_dc_message: u32,
pub(crate) starred: bool, pub(crate) starred: bool,
pub(crate) chat_blocked: Blocked, pub(crate) chat_blocked: Blocked,
pub(crate) location_id: u32, pub(crate) location_id: u32,