api: add chat_id to all call events (#7216)

This commit is contained in:
WofWca
2025-10-01 14:42:33 +04:00
committed by GitHub
parent d8950fb7d1
commit 1b1757ebf2
4 changed files with 32 additions and 2 deletions

View File

@@ -425,6 +425,8 @@ pub enum EventType {
IncomingCall { IncomingCall {
/// ID of the info message referring to the call. /// ID of the info message referring to the call.
msg_id: u32, msg_id: u32,
/// ID of the chat which the message belongs to.
chat_id: u32,
/// User-defined info as passed to place_outgoing_call() /// User-defined info as passed to place_outgoing_call()
place_call_info: String, place_call_info: String,
/// True if incoming call is a video call. /// True if incoming call is a video call.
@@ -436,12 +438,16 @@ pub enum EventType {
IncomingCallAccepted { IncomingCallAccepted {
/// ID of the info message referring to the call. /// ID of the info message referring to the call.
msg_id: u32, msg_id: u32,
/// ID of the chat which the message belongs to.
chat_id: u32,
}, },
/// Outgoing call accepted. /// Outgoing call accepted.
OutgoingCallAccepted { OutgoingCallAccepted {
/// ID of the info message referring to the call. /// ID of the info message referring to the call.
msg_id: u32, msg_id: u32,
/// ID of the chat which the message belongs to.
chat_id: u32,
/// User-defined info passed to dc_accept_incoming_call( /// User-defined info passed to dc_accept_incoming_call(
accept_call_info: String, accept_call_info: String,
}, },
@@ -450,6 +456,8 @@ pub enum EventType {
CallEnded { CallEnded {
/// ID of the info message referring to the call. /// ID of the info message referring to the call.
msg_id: u32, msg_id: u32,
/// ID of the chat which the message belongs to.
chat_id: u32,
}, },
} }
@@ -607,25 +615,31 @@ impl From<CoreEventType> for EventType {
CoreEventType::AccountsItemChanged => AccountsItemChanged, CoreEventType::AccountsItemChanged => AccountsItemChanged,
CoreEventType::IncomingCall { CoreEventType::IncomingCall {
msg_id, msg_id,
chat_id,
place_call_info, place_call_info,
has_video, has_video,
} => IncomingCall { } => IncomingCall {
msg_id: msg_id.to_u32(), msg_id: msg_id.to_u32(),
chat_id: chat_id.to_u32(),
place_call_info, place_call_info,
has_video, has_video,
}, },
CoreEventType::IncomingCallAccepted { msg_id } => IncomingCallAccepted { CoreEventType::IncomingCallAccepted { msg_id, chat_id } => IncomingCallAccepted {
msg_id: msg_id.to_u32(), msg_id: msg_id.to_u32(),
chat_id: chat_id.to_u32(),
}, },
CoreEventType::OutgoingCallAccepted { CoreEventType::OutgoingCallAccepted {
msg_id, msg_id,
chat_id,
accept_call_info, accept_call_info,
} => OutgoingCallAccepted { } => OutgoingCallAccepted {
msg_id: msg_id.to_u32(), msg_id: msg_id.to_u32(),
chat_id: chat_id.to_u32(),
accept_call_info, accept_call_info,
}, },
CoreEventType::CallEnded { msg_id } => CallEnded { CoreEventType::CallEnded { msg_id, chat_id } => CallEnded {
msg_id: msg_id.to_u32(), msg_id: msg_id.to_u32(),
chat_id: chat_id.to_u32(),
}, },
#[allow(unreachable_patterns)] #[allow(unreachable_patterns)]
#[cfg(test)] #[cfg(test)]

View File

@@ -236,6 +236,7 @@ impl Context {
msg.id = send_msg(self, call.msg.chat_id, &mut msg).await?; msg.id = send_msg(self, call.msg.chat_id, &mut msg).await?;
self.emit_event(EventType::IncomingCallAccepted { self.emit_event(EventType::IncomingCallAccepted {
msg_id: call.msg.id, msg_id: call.msg.id,
chat_id: call.msg.chat_id,
}); });
self.emit_msgs_changed(call.msg.chat_id, call_id); self.emit_msgs_changed(call.msg.chat_id, call_id);
Ok(()) Ok(())
@@ -274,6 +275,7 @@ impl Context {
self.emit_event(EventType::CallEnded { self.emit_event(EventType::CallEnded {
msg_id: call.msg.id, msg_id: call.msg.id,
chat_id: call.msg.chat_id,
}); });
self.emit_msgs_changed(call.msg.chat_id, call_id); self.emit_msgs_changed(call.msg.chat_id, call_id);
Ok(()) Ok(())
@@ -297,6 +299,7 @@ impl Context {
context.emit_msgs_changed(call.msg.chat_id, call_id); context.emit_msgs_changed(call.msg.chat_id, call_id);
context.emit_event(EventType::CallEnded { context.emit_event(EventType::CallEnded {
msg_id: call.msg.id, msg_id: call.msg.id,
chat_id: call.msg.chat_id,
}); });
} }
Ok(()) Ok(())
@@ -327,6 +330,7 @@ impl Context {
}; };
self.emit_event(EventType::IncomingCall { self.emit_event(EventType::IncomingCall {
msg_id: call.msg.id, msg_id: call.msg.id,
chat_id: call.msg.chat_id,
place_call_info: call.place_call_info.to_string(), place_call_info: call.place_call_info.to_string(),
has_video, has_video,
}); });
@@ -355,6 +359,7 @@ impl Context {
if call.is_incoming() { if call.is_incoming() {
self.emit_event(EventType::IncomingCallAccepted { self.emit_event(EventType::IncomingCallAccepted {
msg_id: call.msg.id, msg_id: call.msg.id,
chat_id: call.msg.chat_id,
}); });
} else { } else {
let accept_call_info = mime_message let accept_call_info = mime_message
@@ -362,6 +367,7 @@ impl Context {
.unwrap_or_default(); .unwrap_or_default();
self.emit_event(EventType::OutgoingCallAccepted { self.emit_event(EventType::OutgoingCallAccepted {
msg_id: call.msg.id, msg_id: call.msg.id,
chat_id: call.msg.chat_id,
accept_call_info: accept_call_info.to_string(), accept_call_info: accept_call_info.to_string(),
}); });
} }
@@ -401,6 +407,7 @@ impl Context {
self.emit_msgs_changed(call.msg.chat_id, call_id); self.emit_msgs_changed(call.msg.chat_id, call_id);
self.emit_event(EventType::CallEnded { self.emit_event(EventType::CallEnded {
msg_id: call.msg.id, msg_id: call.msg.id,
chat_id: call.msg.chat_id,
}); });
} }
_ => {} _ => {}

View File

@@ -135,6 +135,7 @@ async fn accept_call() -> Result<CallSetup> {
ev, ev,
EventType::OutgoingCallAccepted { EventType::OutgoingCallAccepted {
msg_id: alice_call.id, msg_id: alice_call.id,
chat_id: alice_call.chat_id,
accept_call_info: ACCEPT_INFO.to_string() accept_call_info: ACCEPT_INFO.to_string()
} }
); );

View File

@@ -383,6 +383,8 @@ pub enum EventType {
IncomingCall { IncomingCall {
/// ID of the message referring to the call. /// ID of the message referring to the call.
msg_id: MsgId, msg_id: MsgId,
/// ID of the chat which the message belongs to.
chat_id: ChatId,
/// User-defined info as passed to place_outgoing_call() /// User-defined info as passed to place_outgoing_call()
place_call_info: String, place_call_info: String,
/// True if incoming call is a video call. /// True if incoming call is a video call.
@@ -393,12 +395,16 @@ pub enum EventType {
IncomingCallAccepted { IncomingCallAccepted {
/// ID of the message referring to the call. /// ID of the message referring to the call.
msg_id: MsgId, msg_id: MsgId,
/// ID of the chat which the message belongs to.
chat_id: ChatId,
}, },
/// Outgoing call accepted. /// Outgoing call accepted.
OutgoingCallAccepted { OutgoingCallAccepted {
/// ID of the message referring to the call. /// ID of the message referring to the call.
msg_id: MsgId, msg_id: MsgId,
/// ID of the chat which the message belongs to.
chat_id: ChatId,
/// User-defined info as passed to accept_incoming_call() /// User-defined info as passed to accept_incoming_call()
accept_call_info: String, accept_call_info: String,
}, },
@@ -407,6 +413,8 @@ pub enum EventType {
CallEnded { CallEnded {
/// ID of the message referring to the call. /// ID of the message referring to the call.
msg_id: MsgId, msg_id: MsgId,
/// ID of the chat which the message belongs to.
chat_id: ChatId,
}, },
/// Event for using in tests, e.g. as a fence between normally generated events. /// Event for using in tests, e.g. as a fence between normally generated events.