-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: When reactions are seen, remove notification from second device (…
…#6480) Instead of being trashed, the message containing a reaction remains in the chat, hidden and InFresh. When the chat is opened, it will be marked as Seen on the server, so that a second device removes the notifications for the reaction. Close #6210. Also, this adds a benchmark.
- Loading branch information
Showing
7 changed files
with
226 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#![recursion_limit = "256"] | ||
use std::path::Path; | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion}; | ||
use deltachat::chat::{self, ChatId}; | ||
use deltachat::chatlist::Chatlist; | ||
use deltachat::context::Context; | ||
use deltachat::stock_str::StockStrings; | ||
use deltachat::Events; | ||
use futures_lite::future::block_on; | ||
use tempfile::tempdir; | ||
|
||
async fn marknoticed_chat_benchmark(context: &Context, chats: &[ChatId]) { | ||
for c in chats.iter().take(20) { | ||
chat::marknoticed_chat(context, *c).await.unwrap(); | ||
} | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
// To enable this benchmark, set `DELTACHAT_BENCHMARK_DATABASE` to some large database with many | ||
// messages, such as your primary account. | ||
if let Ok(path) = std::env::var("DELTACHAT_BENCHMARK_DATABASE") { | ||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
|
||
let chats: Vec<_> = rt.block_on(async { | ||
let context = Context::new(Path::new(&path), 100, Events::new(), StockStrings::new()) | ||
.await | ||
.unwrap(); | ||
let chatlist = Chatlist::try_load(&context, 0, None, None).await.unwrap(); | ||
let len = chatlist.len(); | ||
(1..len).map(|i| chatlist.get_chat_id(i).unwrap()).collect() | ||
}); | ||
|
||
// This mainly tests the performance of marknoticed_chat() | ||
// when nothing has to be done | ||
c.bench_function( | ||
"chat::marknoticed_chat (mark 20 chats as noticed repeatedly)", | ||
|b| { | ||
let dir = tempdir().unwrap(); | ||
let dir = dir.path(); | ||
let new_db = dir.join("dc.db"); | ||
std::fs::copy(&path, &new_db).unwrap(); | ||
|
||
let context = block_on(async { | ||
Context::new(Path::new(&new_db), 100, Events::new(), StockStrings::new()) | ||
.await | ||
.unwrap() | ||
}); | ||
|
||
b.to_async(&rt) | ||
.iter(|| marknoticed_chat_benchmark(&context, black_box(&chats))) | ||
}, | ||
); | ||
|
||
// If the first 20 chats contain fresh messages or reactions, | ||
// this tests the performance of marking them as noticed. | ||
c.bench_function( | ||
"chat::marknoticed_chat (mark 20 chats as noticed, resetting after every iteration)", | ||
|b| { | ||
b.to_async(&rt).iter_batched( | ||
|| { | ||
let dir = tempdir().unwrap(); | ||
let new_db = dir.path().join("dc.db"); | ||
std::fs::copy(&path, &new_db).unwrap(); | ||
|
||
let context = block_on(async { | ||
Context::new( | ||
Path::new(&new_db), | ||
100, | ||
Events::new(), | ||
StockStrings::new(), | ||
) | ||
.await | ||
.unwrap() | ||
}); | ||
(dir, context) | ||
}, | ||
|(_dir, context)| { | ||
let chats = &chats; | ||
async move { | ||
marknoticed_chat_benchmark(black_box(&context), black_box(chats)).await | ||
} | ||
}, | ||
BatchSize::PerIteration, | ||
); | ||
}, | ||
); | ||
} else { | ||
println!("env var not set: DELTACHAT_BENCHMARK_DATABASE"); | ||
} | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,7 +398,7 @@ mod tests { | |
use deltachat_contact_tools::ContactAddress; | ||
|
||
use super::*; | ||
use crate::chat::{forward_msgs, get_chat_msgs, send_text_msg}; | ||
use crate::chat::{forward_msgs, get_chat_msgs, marknoticed_chat, send_text_msg}; | ||
use crate::chatlist::Chatlist; | ||
use crate::config::Config; | ||
use crate::contact::{Contact, Origin}; | ||
|
@@ -623,7 +623,9 @@ Here's my footer -- [email protected]" | |
.get_matching_opt(t, |evt| { | ||
matches!( | ||
evt, | ||
EventType::IncomingReaction { .. } | EventType::IncomingMsg { .. } | ||
EventType::IncomingReaction { .. } | ||
| EventType::IncomingMsg { .. } | ||
| EventType::MsgsChanged { .. } | ||
) | ||
}) | ||
.await; | ||
|
@@ -667,7 +669,8 @@ Here's my footer -- [email protected]" | |
assert_eq!(get_chat_msgs(&bob, bob_msg.chat_id).await?.len(), 2); | ||
|
||
let bob_reaction_msg = bob.pop_sent_msg().await; | ||
alice.recv_msg_trash(&bob_reaction_msg).await; | ||
let alice_reaction_msg = alice.recv_msg_hidden(&bob_reaction_msg).await; | ||
assert_eq!(alice_reaction_msg.state, MessageState::InFresh); | ||
assert_eq!(get_chat_msgs(&alice, chat_alice.id).await?.len(), 2); | ||
|
||
let reactions = get_msg_reactions(&alice, alice_msg.sender_msg_id).await?; | ||
|
@@ -691,6 +694,20 @@ Here's my footer -- [email protected]" | |
.await?; | ||
expect_no_unwanted_events(&alice).await; | ||
|
||
marknoticed_chat(&alice, chat_alice.id).await?; | ||
assert_eq!( | ||
alice_reaction_msg.id.get_state(&alice).await?, | ||
MessageState::InSeen | ||
); | ||
// Reactions don't request MDNs. | ||
assert_eq!( | ||
alice | ||
.sql | ||
.count("SELECT COUNT(*) FROM smtp_mdns", ()) | ||
.await?, | ||
0 | ||
); | ||
|
||
// Alice reacts to own message. | ||
send_reaction(&alice, alice_msg.sender_msg_id, "👍 😀") | ||
.await | ||
|
@@ -730,7 +747,7 @@ Here's my footer -- [email protected]" | |
bob_msg1.chat_id.accept(&bob).await?; | ||
send_reaction(&bob, bob_msg1.id, "👍").await?; | ||
let bob_send_reaction = bob.pop_sent_msg().await; | ||
alice.recv_msg_trash(&bob_send_reaction).await; | ||
alice.recv_msg_hidden(&bob_send_reaction).await; | ||
expect_incoming_reactions_event( | ||
&alice, | ||
alice_chat.id, | ||
|
@@ -899,7 +916,7 @@ Here's my footer -- [email protected]" | |
let bob_reaction_msg = bob.pop_sent_msg().await; | ||
|
||
// Alice receives a reaction. | ||
alice.recv_msg_trash(&bob_reaction_msg).await; | ||
alice.recv_msg_hidden(&bob_reaction_msg).await; | ||
|
||
let reactions = get_msg_reactions(&alice, alice_msg_id).await?; | ||
assert_eq!(reactions.to_string(), "👍1"); | ||
|
@@ -951,7 +968,7 @@ Here's my footer -- [email protected]" | |
{ | ||
send_reaction(&alice2, alice2_msg.id, "👍").await?; | ||
let msg = alice2.pop_sent_msg().await; | ||
alice1.recv_msg_trash(&msg).await; | ||
alice1.recv_msg_hidden(&msg).await; | ||
} | ||
|
||
// Check that the status is still the same. | ||
|
@@ -973,7 +990,7 @@ Here's my footer -- [email protected]" | |
let alice1_msg = alice1.recv_msg(&alice0.pop_sent_msg().await).await; | ||
|
||
send_reaction(&alice0, alice0_msg_id, "👀").await?; | ||
alice1.recv_msg_trash(&alice0.pop_sent_msg().await).await; | ||
alice1.recv_msg_hidden(&alice0.pop_sent_msg().await).await; | ||
|
||
expect_reactions_changed_event(&alice0, chat_id, alice0_msg_id, ContactId::SELF).await?; | ||
expect_reactions_changed_event(&alice1, alice1_msg.chat_id, alice1_msg.id, ContactId::SELF) | ||
|
Oops, something went wrong.