Skip to content

Commit 01b2aa0

Browse files
committed
fix: Mark call message as seen when accepting/declining a call (#7842)
1 parent fb46c34 commit 01b2aa0

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

src/calls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::context::{Context, WeakContext};
1111
use crate::events::EventType;
1212
use crate::headerdef::HeaderDef;
1313
use crate::log::warn;
14-
use crate::message::{Message, MsgId, Viewtype};
14+
use crate::message::{Message, MsgId, Viewtype, markseen_msgs};
1515
use crate::mimeparser::{MimeMessage, SystemMessage};
1616
use crate::net::dns::lookup_host_with_cache;
1717
use crate::param::Param;
@@ -249,6 +249,7 @@ impl Context {
249249
if chat.is_contact_request() {
250250
chat.id.accept(self).await?;
251251
}
252+
markseen_msgs(self, vec![call_id]).await?;
252253

253254
// send an acceptance message around: to the caller as well as to the other devices of the callee
254255
let mut msg = Message {
@@ -283,6 +284,7 @@ impl Context {
283284
if !call.is_accepted() {
284285
if call.is_incoming() {
285286
call.mark_as_ended(self).await?;
287+
markseen_msgs(self, vec![call_id]).await?;
286288
let declined_call_str = stock_str::declined_call(self).await;
287289
call.update_text(self, &declined_call_str).await?;
288290
} else {

src/calls/calls_tests.rs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::*;
22
use crate::chat::forward_msgs;
33
use crate::config::Config;
44
use crate::constants::DC_CHAT_ID_TRASH;
5+
use crate::message::MessageState;
56
use crate::receive_imf::receive_imf;
67
use crate::test_utils::{TestContext, TestContextManager};
78

@@ -115,6 +116,17 @@ async fn accept_call() -> Result<CallSetup> {
115116
// Bob accepts the incoming call
116117
bob.accept_incoming_call(bob_call.id, ACCEPT_INFO.to_string())
117118
.await?;
119+
assert_eq!(bob_call.id.get_state(&bob).await?, MessageState::InSeen);
120+
// Bob sends an MDN to Alice.
121+
assert_eq!(
122+
bob.sql
123+
.count(
124+
"SELECT COUNT(*) FROM smtp_mdns WHERE msg_id=? AND from_id=?",
125+
(bob_call.id, bob_call.from_id)
126+
)
127+
.await?,
128+
1
129+
);
118130
assert_text(&bob, bob_call.id, "Incoming video call").await?;
119131
bob.evtracker
120132
.get_matching(|evt| matches!(evt, EventType::IncomingCallAccepted { .. }))
@@ -200,9 +212,20 @@ async fn test_accept_call_callee_ends() -> Result<()> {
200212
bob2_call,
201213
..
202214
} = accept_call().await?;
215+
assert_eq!(bob_call.id.get_state(&bob).await?, MessageState::InSeen);
203216

204217
// Bob has accepted the call and also ends it
205218
bob.end_call(bob_call.id).await?;
219+
// Bob sends an MDN to Alice.
220+
assert_eq!(
221+
bob.sql
222+
.count(
223+
"SELECT COUNT(*) FROM smtp_mdns WHERE msg_id=? AND from_id=?",
224+
(bob_call.id, bob_call.from_id)
225+
)
226+
.await?,
227+
1
228+
);
206229
assert_text(&bob, bob_call.id, "Incoming video call\n<1 minute").await?;
207230
bob.evtracker
208231
.get_matching(|evt| matches!(evt, EventType::CallEnded { .. }))
@@ -328,8 +351,18 @@ async fn test_callee_rejects_call() -> Result<()> {
328351
} = setup_call().await?;
329352

330353
// Bob has accepted Alice before, but does not want to talk with Alice
331-
bob_call.chat_id.accept(&bob).await?;
332354
bob.end_call(bob_call.id).await?;
355+
assert_eq!(bob_call.id.get_state(&bob).await?, MessageState::InSeen);
356+
// Bob sends an MDN to Alice.
357+
assert_eq!(
358+
bob.sql
359+
.count(
360+
"SELECT COUNT(*) FROM smtp_mdns WHERE msg_id=? AND from_id=?",
361+
(bob_call.id, bob_call.from_id)
362+
)
363+
.await?,
364+
1
365+
);
333366
assert_text(&bob, bob_call.id, "Declined call").await?;
334367
bob.evtracker
335368
.get_matching(|evt| matches!(evt, EventType::CallEnded { .. }))
@@ -370,6 +403,35 @@ async fn test_callee_rejects_call() -> Result<()> {
370403
Ok(())
371404
}
372405

406+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
407+
async fn test_callee_sees_contact_request_call() -> Result<()> {
408+
let mut tcm = TestContextManager::new();
409+
let alice = &tcm.alice().await;
410+
let bob = &tcm.bob().await;
411+
412+
let alice_chat = alice.create_chat(bob).await;
413+
alice
414+
.place_outgoing_call(alice_chat.id, PLACE_INFO.to_string(), true)
415+
.await?;
416+
let sent1 = alice.pop_sent_msg().await;
417+
let bob_call = bob.recv_msg(&sent1).await;
418+
// Bob can't end_call() because the contact request isn't accepted, but he can mark the call as
419+
// seen.
420+
markseen_msgs(bob, vec![bob_call.id]).await?;
421+
assert_eq!(bob_call.id.get_state(bob).await?, MessageState::InSeen);
422+
// Bob sends an MDN only to self so that an unaccepted contact can't know anything.
423+
assert_eq!(
424+
bob.sql
425+
.count(
426+
"SELECT COUNT(*) FROM smtp_mdns WHERE msg_id=? AND from_id=?",
427+
(bob_call.id, ContactId::SELF)
428+
)
429+
.await?,
430+
1
431+
);
432+
Ok(())
433+
}
434+
373435
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
374436
async fn test_caller_cancels_call() -> Result<()> {
375437
// Alice calls Bob

0 commit comments

Comments
 (0)