Skip to content

Commit a65d986

Browse files
committed
emit end-call after timeout
1 parent 705be9a commit a65d986

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/calls.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,19 @@ impl Context {
135135
Ok(())
136136
}
137137

138-
async fn emit_end_call_if_unaccepted(wait: u64) {
138+
async fn emit_end_call_if_unaccepted(
139+
context: Context,
140+
wait: u64,
141+
call_id: MsgId,
142+
) -> Result<()> {
139143
sleep(Duration::from_secs(wait)).await;
144+
let call = context.load_call_by_root_id(call_id).await?;
145+
if !call.accepted {
146+
context.emit_event(EventType::CallEnded {
147+
msg_id: call.msg.id,
148+
});
149+
}
150+
Ok(())
140151
}
141152

142153
pub(crate) async fn handle_call_msg(
@@ -153,7 +164,11 @@ impl Context {
153164
msg_id: call.msg.id,
154165
});
155166
let wait = call.remaining_ring_seconds();
156-
task::spawn(Context::emit_end_call_if_unaccepted(wait.try_into()?));
167+
task::spawn(Context::emit_end_call_if_unaccepted(
168+
self.clone(),
169+
wait.try_into()?,
170+
call.msg.id,
171+
));
157172
}
158173
}
159174
SystemMessage::CallAccepted => {

0 commit comments

Comments
 (0)