Merge pull request #3187 from deltachat/adb/issue-2557

Send setup-changed messages only in the chats we share with the peer
This commit is contained in:
Asiel Díaz Benítez
2022-04-09 19:43:51 -04:00
committed by GitHub
5 changed files with 49 additions and 12 deletions

View File

@@ -13,6 +13,8 @@
- Assign replies from a different email address to the correct chat #3119 - Assign replies from a different email address to the correct chat #3119
- Assing outgoing private replies to the correct chat #3177 - Assing outgoing private replies to the correct chat #3177
- start ephemeral timer when seen status is synchronized via IMAP #3122 - start ephemeral timer when seen status is synchronized via IMAP #3122
- Don't create empty contact requests with "setup changed" messages; instead, send a
"setup changed" message into all chats we share with the peer #3187
- do not delete duplicate messages on IMAP immediately to accidentally deleting - do not delete duplicate messages on IMAP immediately to accidentally deleting
the last copy #3138 the last copy #3138
- speed up loading of chat messages #3171 - speed up loading of chat messages #3171

View File

@@ -445,6 +445,7 @@ impl ChatId {
cmd, cmd,
dc_create_smeared_timestamp(context).await, dc_create_smeared_timestamp(context).await,
None, None,
None,
) )
.await?; .await?;
} }
@@ -3385,7 +3386,9 @@ pub(crate) async fn add_info_msg_with_cmd(
chat_id: ChatId, chat_id: ChatId,
text: &str, text: &str,
cmd: SystemMessage, cmd: SystemMessage,
timestamp: i64, timestamp_sort: i64,
// Timestamp to show to the user (if this is None, `timestamp_sort` will be shown to the user)
timestamp_sent_rcvd: Option<i64>,
parent: Option<&Message>, parent: Option<&Message>,
) -> Result<MsgId> { ) -> Result<MsgId> {
let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device"); let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device");
@@ -3398,12 +3401,15 @@ pub(crate) async fn add_info_msg_with_cmd(
let row_id = let row_id =
context.sql.insert( context.sql.insert(
"INSERT INTO msgs (chat_id,from_id,to_id,timestamp,type,state,txt,rfc724_mid,ephemeral_timer, param,mime_in_reply_to) VALUES (?,?,?, ?,?,?, ?,?,?, ?,?);", "INSERT INTO msgs (chat_id,from_id,to_id,timestamp,timestamp_sent,timestamp_rcvd,type,state,txt,rfc724_mid,ephemeral_timer, param,mime_in_reply_to)
VALUES (?,?,?, ?,?,?,?,?, ?,?,?, ?,?);",
paramsv![ paramsv![
chat_id, chat_id,
ContactId::INFO, ContactId::INFO,
ContactId::INFO, ContactId::INFO,
timestamp, timestamp_sort,
timestamp_sent_rcvd.unwrap_or(0),
timestamp_sent_rcvd.unwrap_or(0),
Viewtype::Text, Viewtype::Text,
MessageState::InNoticed, MessageState::InNoticed,
text, text,
@@ -3433,6 +3439,7 @@ pub(crate) async fn add_info_msg(
SystemMessage::Unknown, SystemMessage::Unknown,
timestamp, timestamp,
None, None,
None,
) )
.await .await
} }
@@ -4519,6 +4526,7 @@ mod tests {
SystemMessage::EphemeralTimerChanged, SystemMessage::EphemeralTimerChanged,
10000, 10000,
None, None,
None,
) )
.await?; .await?;

View File

@@ -355,6 +355,10 @@ impl Chatlist {
pub fn get_index_for_id(&self, id: ChatId) -> Option<usize> { pub fn get_index_for_id(&self, id: ChatId) -> Option<usize> {
self.ids.iter().position(|(chat_id, _)| chat_id == &id) self.ids.iter().position(|(chat_id, _)| chat_id == &id)
} }
pub fn iter(&self) -> impl Iterator<Item = &(ChatId, Option<MsgId>)> {
self.ids.iter()
}
} }
/// Returns the number of archived chats /// Returns the number of archived chats

View File

@@ -4,11 +4,13 @@ use std::collections::HashSet;
use std::fmt; use std::fmt;
use crate::aheader::{Aheader, EncryptPreference}; use crate::aheader::{Aheader, EncryptPreference};
use crate::chat::{self, ChatIdBlocked}; use crate::chat::{self};
use crate::constants::Blocked; use crate::chatlist::Chatlist;
use crate::context::Context; use crate::context::Context;
use crate::events::EventType; use crate::events::EventType;
use crate::key::{DcKey, Fingerprint, SignedPublicKey}; use crate::key::{DcKey, Fingerprint, SignedPublicKey};
use crate::message::Message;
use crate::mimeparser::SystemMessage;
use crate::sql::Sql; use crate::sql::Sql;
use crate::stock_str; use crate::stock_str;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
@@ -271,14 +273,34 @@ impl Peerstate {
.query_get_value("SELECT id FROM contacts WHERE addr=?;", paramsv![self.addr]) .query_get_value("SELECT id FROM contacts WHERE addr=?;", paramsv![self.addr])
.await? .await?
{ {
let chat_id = ChatIdBlocked::get_for_contact(context, contact_id, Blocked::Request) let chats = Chatlist::try_load(context, 0, None, contact_id).await?;
.await?
.id;
let msg = stock_str::contact_setup_changed(context, self.addr.clone()).await; let msg = stock_str::contact_setup_changed(context, self.addr.clone()).await;
for (chat_id, msg_id) in chats.iter() {
chat::add_info_msg(context, chat_id, &msg, timestamp).await?; let timestamp_sort = if let Some(msg_id) = msg_id {
context.emit_event(EventType::ChatModified(chat_id)); let lastmsg = Message::load_from_db(context, *msg_id).await?;
lastmsg.timestamp_sort
} else {
context
.sql
.query_get_value(
"SELECT created_timestamp FROM chats WHERE id=?;",
paramsv![chat_id],
)
.await?
.unwrap_or(0)
};
chat::add_info_msg_with_cmd(
context,
*chat_id,
&msg,
SystemMessage::Unknown,
timestamp_sort,
Some(timestamp),
None,
)
.await?;
context.emit_event(EventType::ChatModified(*chat_id));
}
} else { } else {
bail!("contact with peerstate.addr {:?} not found", &self.addr); bail!("contact with peerstate.addr {:?} not found", &self.addr);
} }

View File

@@ -219,6 +219,7 @@ impl Context {
info.as_str(), info.as_str(),
SystemMessage::Unknown, SystemMessage::Unknown,
timestamp, timestamp,
None,
Some(instance), Some(instance),
) )
.await?; .await?;