Skip to content

Commit a1ea774

Browse files
committed
update call info message for missed calls
1 parent aa36f76 commit a1ea774

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/calls.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::chat::{send_msg, Chat, ChatId};
88
use crate::constants::Chattype;
99
use crate::context::Context;
1010
use crate::events::EventType;
11-
use crate::message::{rfc724_mid_exists, Message, MsgId, Viewtype};
11+
use crate::message::{self, rfc724_mid_exists, Message, MsgId, Viewtype};
1212
use crate::mimeparser::{MimeMessage, SystemMessage};
1313
use crate::param::Param;
1414
use crate::sync::SyncData;
@@ -52,6 +52,17 @@ impl CallInfo {
5252
let remaining_seconds = self.msg.timestamp_sent + RINGING_SECONDS - time();
5353
remaining_seconds.clamp(0, RINGING_SECONDS)
5454
}
55+
56+
async fn update_text(&self, context: &Context, text: &str) -> Result<()> {
57+
context
58+
.sql
59+
.execute(
60+
"UPDATE msgs SET txt=?, txt_normalized=? WHERE id=?;",
61+
(text, message::normalize_text(text), self.msg.id),
62+
)
63+
.await?;
64+
Ok(())
65+
}
5566
}
5667

5768
impl Context {
@@ -158,6 +169,7 @@ impl Context {
158169
let call = self.load_call_by_root_id(call_or_child_id).await?;
159170
if call.incoming {
160171
if call.is_stale_call() {
172+
call.update_text(self, "Missed call").await?;
161173
self.emit_incoming_msg(call.msg.chat_id, call_or_child_id);
162174
} else {
163175
self.emit_msgs_changed(call.msg.chat_id, call_or_child_id);
@@ -531,4 +543,17 @@ mod tests {
531543

532544
Ok(())
533545
}
546+
547+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
548+
async fn test_udpate_call_text() -> Result<()> {
549+
let (alice, _alice2, alice_call, _bob, _bob2, _bob_call, _bob2_call) = setup_call().await?;
550+
551+
let call_info = alice.load_call_by_root_id(alice_call.id).await?;
552+
call_info.update_text(&alice, "foo bar").await?;
553+
554+
let alice_call = Message::load_from_db(&alice, alice_call.id).await?;
555+
assert_eq!(alice_call.get_text(), "foo bar");
556+
557+
Ok(())
558+
}
534559
}

0 commit comments

Comments
 (0)