mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 21:06:31 +03:00
name special contact-ids where easily possible
the point of this pr is to get an overview how and where DC_CONTACT_ID_DEVICE is used, to prepare introducing a device-"chat". i did not change the sql statements for now as this would require some more refactoring and has the potential to introduce bugs.
This commit is contained in:
committed by
holger krekel
parent
87abc6e4a2
commit
8c2efa707a
22
src/chat.rs
22
src/chat.rs
@@ -258,7 +258,7 @@ impl Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self.typ == Chattype::Group || self.typ == Chattype::VerifiedGroup)
|
if (self.typ == Chattype::Group || self.typ == Chattype::VerifiedGroup)
|
||||||
&& !is_contact_in_chat(context, self.id, 1 as u32)
|
&& !is_contact_in_chat(context, self.id, DC_CONTACT_ID_SELF)
|
||||||
{
|
{
|
||||||
emit_event!(
|
emit_event!(
|
||||||
context,
|
context,
|
||||||
@@ -414,7 +414,7 @@ impl Chat {
|
|||||||
&context.sql,
|
&context.sql,
|
||||||
"INSERT INTO locations \
|
"INSERT INTO locations \
|
||||||
(timestamp,from_id,chat_id, latitude,longitude,independent)\
|
(timestamp,from_id,chat_id, latitude,longitude,independent)\
|
||||||
VALUES (?,?,?, ?,?,1);",
|
VALUES (?,?,?, ?,?,1);", // 1=DC_CONTACT_ID_SELF
|
||||||
params![
|
params![
|
||||||
timestamp,
|
timestamp,
|
||||||
DC_CONTACT_ID_SELF,
|
DC_CONTACT_ID_SELF,
|
||||||
@@ -446,7 +446,7 @@ impl Chat {
|
|||||||
params![
|
params![
|
||||||
new_rfc724_mid,
|
new_rfc724_mid,
|
||||||
self.id as i32,
|
self.id as i32,
|
||||||
1i32,
|
DC_CONTACT_ID_SELF,
|
||||||
to_id as i32,
|
to_id as i32,
|
||||||
timestamp,
|
timestamp,
|
||||||
msg.type_0,
|
msg.type_0,
|
||||||
@@ -914,7 +914,7 @@ fn do_set_draft(context: &Context, chat_id: u32, msg: &mut Message) -> Result<()
|
|||||||
VALUES (?,?,?, ?,?,?,?,?);",
|
VALUES (?,?,?, ?,?,?,?,?);",
|
||||||
params![
|
params![
|
||||||
chat_id as i32,
|
chat_id as i32,
|
||||||
1,
|
DC_CONTACT_ID_SELF,
|
||||||
time(),
|
time(),
|
||||||
msg.type_0,
|
msg.type_0,
|
||||||
MessageState::OutDraft,
|
MessageState::OutDraft,
|
||||||
@@ -993,8 +993,8 @@ pub fn get_chat_msgs(
|
|||||||
" ON m.chat_id=chats.id",
|
" ON m.chat_id=chats.id",
|
||||||
" LEFT JOIN contacts",
|
" LEFT JOIN contacts",
|
||||||
" ON m.from_id=contacts.id",
|
" ON m.from_id=contacts.id",
|
||||||
" WHERE m.from_id!=1",
|
" WHERE m.from_id!=1", // 1=DC_CONTACT_ID_SELF
|
||||||
" AND m.from_id!=2",
|
" AND m.from_id!=2", // 2=DC_CONTACT_ID_DEVICE
|
||||||
" AND m.hidden=0",
|
" AND m.hidden=0",
|
||||||
" AND chats.blocked=2",
|
" AND chats.blocked=2",
|
||||||
" AND contacts.blocked=0",
|
" AND contacts.blocked=0",
|
||||||
@@ -1350,7 +1350,7 @@ pub fn create_group_chat(
|
|||||||
let chat_id = sql::get_rowid(context, &context.sql, "chats", "grpid", grpid);
|
let chat_id = sql::get_rowid(context, &context.sql, "chats", "grpid", grpid);
|
||||||
|
|
||||||
if chat_id != 0 {
|
if chat_id != 0 {
|
||||||
if add_to_chat_contacts_table(context, chat_id, 1) {
|
if add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF) {
|
||||||
let mut draft_msg = Message::new(Viewtype::Text);
|
let mut draft_msg = Message::new(Viewtype::Text);
|
||||||
draft_msg.set_text(Some(draft_txt));
|
draft_msg.set_text(Some(draft_txt));
|
||||||
set_draft_raw(context, chat_id, &mut draft_msg);
|
set_draft_raw(context, chat_id, &mut draft_msg);
|
||||||
@@ -1557,7 +1557,7 @@ pub fn remove_contact_from_chat(
|
|||||||
/* this allows to delete pending references to deleted contacts. Of course, this should _not_ happen. */
|
/* this allows to delete pending references to deleted contacts. Of course, this should _not_ happen. */
|
||||||
if let Ok(chat) = Chat::load_from_db(context, chat_id) {
|
if let Ok(chat) = Chat::load_from_db(context, chat_id) {
|
||||||
if real_group_exists(context, chat_id) {
|
if real_group_exists(context, chat_id) {
|
||||||
if !is_contact_in_chat(context, chat_id, 1 as u32) {
|
if !is_contact_in_chat(context, chat_id, DC_CONTACT_ID_SELF) {
|
||||||
emit_event!(
|
emit_event!(
|
||||||
context,
|
context,
|
||||||
Event::ErrorSelfNotInGroup(
|
Event::ErrorSelfNotInGroup(
|
||||||
@@ -1653,7 +1653,7 @@ pub fn set_chat_name(
|
|||||||
if real_group_exists(context, chat_id) {
|
if real_group_exists(context, chat_id) {
|
||||||
if chat.name == new_name.as_ref() {
|
if chat.name == new_name.as_ref() {
|
||||||
success = true;
|
success = true;
|
||||||
} else if !is_contact_in_chat(context, chat_id, 1) {
|
} else if !is_contact_in_chat(context, chat_id, DC_CONTACT_ID_SELF) {
|
||||||
emit_event!(
|
emit_event!(
|
||||||
context,
|
context,
|
||||||
Event::ErrorSelfNotInGroup("Cannot set chat name; self not in group".into())
|
Event::ErrorSelfNotInGroup("Cannot set chat name; self not in group".into())
|
||||||
@@ -1905,8 +1905,8 @@ pub fn add_device_msg(context: &Context, chat_id: u32, text: impl AsRef<str>) {
|
|||||||
"INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,rfc724_mid) VALUES (?,?,?, ?,?,?, ?,?);",
|
"INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,rfc724_mid) VALUES (?,?,?, ?,?,?, ?,?);",
|
||||||
params![
|
params![
|
||||||
chat_id as i32,
|
chat_id as i32,
|
||||||
2,
|
DC_CONTACT_ID_DEVICE,
|
||||||
2,
|
DC_CONTACT_ID_DEVICE,
|
||||||
dc_create_smeared_timestamp(context),
|
dc_create_smeared_timestamp(context),
|
||||||
Viewtype::Text,
|
Viewtype::Text,
|
||||||
MessageState::InNoticed,
|
MessageState::InNoticed,
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ impl Chatlist {
|
|||||||
let mut lastcontact = None;
|
let mut lastcontact = None;
|
||||||
|
|
||||||
let lastmsg = if let Ok(lastmsg) = Message::load_from_db(context, lastmsg_id) {
|
let lastmsg = if let Ok(lastmsg) = Message::load_from_db(context, lastmsg_id) {
|
||||||
if lastmsg.from_id != 1
|
if lastmsg.from_id != DC_CONTACT_ID_SELF
|
||||||
&& (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup)
|
&& (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup)
|
||||||
{
|
{
|
||||||
lastcontact = Contact::load_from_db(context, lastmsg.from_id).ok();
|
lastcontact = Contact::load_from_db(context, lastmsg.from_id).ok();
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ impl Contact {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if addr_normalized == addr_self {
|
if addr_normalized == addr_self {
|
||||||
return 1;
|
return DC_CONTACT_ID_SELF;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.sql.query_get_value(
|
context.sql.query_get_value(
|
||||||
@@ -301,7 +301,7 @@ impl Contact {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if addr == addr_self {
|
if addr == addr_self {
|
||||||
return Ok((1, sth_modified));
|
return Ok((DC_CONTACT_ID_SELF, sth_modified));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !may_be_valid_addr(&addr) {
|
if !may_be_valid_addr(&addr) {
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ unsafe fn add_parts(
|
|||||||
} else {
|
} else {
|
||||||
MessageState::InFresh
|
MessageState::InFresh
|
||||||
};
|
};
|
||||||
*to_id = 1;
|
*to_id = DC_CONTACT_ID_SELF;
|
||||||
// handshake messages must be processed _before_ chats are created
|
// handshake messages must be processed _before_ chats are created
|
||||||
// (eg. contacs may be marked as verified)
|
// (eg. contacs may be marked as verified)
|
||||||
if mime_parser.lookup_field("Secure-Join").is_some() {
|
if mime_parser.lookup_field("Secure-Join").is_some() {
|
||||||
@@ -551,7 +551,8 @@ unsafe fn add_parts(
|
|||||||
if to_ids.is_empty() && 0 != to_self {
|
if to_ids.is_empty() && 0 != to_self {
|
||||||
// from_id==to_id==DC_CONTACT_ID_SELF - this is a self-sent messages,
|
// from_id==to_id==DC_CONTACT_ID_SELF - this is a self-sent messages,
|
||||||
// maybe an Autocrypt Setup Messag
|
// maybe an Autocrypt Setup Messag
|
||||||
let (id, bl) = chat::create_or_lookup_by_contact_id(context, 1, Blocked::Not)
|
let (id, bl) =
|
||||||
|
chat::create_or_lookup_by_contact_id(context, DC_CONTACT_ID_SELF, Blocked::Not)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
*chat_id = id;
|
*chat_id = id;
|
||||||
chat_id_blocked = bl;
|
chat_id_blocked = bl;
|
||||||
@@ -1350,8 +1351,8 @@ unsafe fn create_or_lookup_adhoc_group(
|
|||||||
if !member_ids.contains(&from_id) {
|
if !member_ids.contains(&from_id) {
|
||||||
member_ids.push(from_id);
|
member_ids.push(from_id);
|
||||||
}
|
}
|
||||||
if !member_ids.contains(&1) {
|
if !member_ids.contains(&DC_CONTACT_ID_SELF) {
|
||||||
member_ids.push(1);
|
member_ids.push(DC_CONTACT_ID_SELF);
|
||||||
}
|
}
|
||||||
if member_ids.len() < 3 {
|
if member_ids.len() < 3 {
|
||||||
// too few contacts given
|
// too few contacts given
|
||||||
@@ -1471,7 +1472,7 @@ fn create_adhoc_grp_id(context: &Context, member_ids: &[u32]) -> String {
|
|||||||
.sql
|
.sql
|
||||||
.query_map(
|
.query_map(
|
||||||
format!(
|
format!(
|
||||||
"SELECT addr FROM contacts WHERE id IN({}) AND id!=1",
|
"SELECT addr FROM contacts WHERE id IN({}) AND id!=1", // 1=DC_CONTACT_ID_SELF
|
||||||
member_ids_str
|
member_ids_str
|
||||||
),
|
),
|
||||||
params![],
|
params![],
|
||||||
@@ -1525,7 +1526,7 @@ fn search_chat_ids_by_contact_ids(
|
|||||||
WHERE cc.chat_id IN(SELECT chat_id FROM chats_contacts WHERE contact_id IN({})) \
|
WHERE cc.chat_id IN(SELECT chat_id FROM chats_contacts WHERE contact_id IN({})) \
|
||||||
AND c.type=120 \
|
AND c.type=120 \
|
||||||
AND cc.contact_id!=1 \
|
AND cc.contact_id!=1 \
|
||||||
ORDER BY cc.chat_id, cc.contact_id;",
|
ORDER BY cc.chat_id, cc.contact_id;", // 1=DC_CONTACT_ID_GROUP
|
||||||
contact_ids_str
|
contact_ids_str
|
||||||
),
|
),
|
||||||
params![],
|
params![],
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ pub fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64) -> b
|
|||||||
accuracy,
|
accuracy,
|
||||||
time(),
|
time(),
|
||||||
chat_id,
|
chat_id,
|
||||||
1,
|
DC_CONTACT_ID_SELF,
|
||||||
]
|
]
|
||||||
) {
|
) {
|
||||||
warn!(context, "failed to store location {:?}", err);
|
warn!(context, "failed to store location {:?}", err);
|
||||||
|
|||||||
@@ -714,7 +714,7 @@ pub fn get_msg_info(context: &Context, msg_id: MsgId) -> String {
|
|||||||
ret += "\n";
|
ret += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.from_id == 2 || msg.to_id == 2 {
|
if msg.from_id == DC_CONTACT_ID_DEVICE || msg.to_id == DC_CONTACT_ID_DEVICE {
|
||||||
// device-internal message, no further details needed
|
// device-internal message, no further details needed
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user