-
-
Notifications
You must be signed in to change notification settings - Fork 125
Add EventType::CallMissed and emit it for missed calls (#7840) #7955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,10 +218,11 @@ impl Context { | |
|
|
||
| let wait = RINGING_SECONDS; | ||
| let context = self.get_weak_context(); | ||
| task::spawn(Context::emit_end_call_if_unaccepted( | ||
| task::spawn(Context::finalize_call_if_unaccepted( | ||
| context, | ||
| wait.try_into()?, | ||
| call.id, | ||
| true, // Doesn't matter for outgoing calls | ||
| )); | ||
|
|
||
| Ok(call.id) | ||
|
|
@@ -314,39 +315,67 @@ impl Context { | |
| Ok(()) | ||
| } | ||
|
|
||
| async fn emit_end_call_if_unaccepted( | ||
| async fn finalize_call_if_unaccepted( | ||
| context: WeakContext, | ||
| wait: u64, | ||
| call_id: MsgId, | ||
| can_call_me: bool, | ||
| ) -> Result<()> { | ||
| sleep(Duration::from_secs(wait)).await; | ||
| let context = context.upgrade()?; | ||
| let Some(mut call) = context.load_call_by_id(call_id).await? else { | ||
| warn!( | ||
| context, | ||
| "emit_end_call_if_unaccepted is called with {call_id} which does not refer to a call." | ||
| "finalize_call_if_unaccepted is called with {call_id} which does not refer to a call." | ||
| ); | ||
| return Ok(()); | ||
| }; | ||
| if !call.is_accepted() && !call.is_ended() { | ||
| let (msg_id, chat_id) = (call_id, call.msg.chat_id); | ||
| if call.is_incoming() { | ||
| call.mark_as_canceled(&context).await?; | ||
| let missed_call_str = stock_str::missed_call(&context); | ||
| call.update_text(&context, &missed_call_str).await?; | ||
| if can_call_me { | ||
| context.emit_event(EventType::CallMissed { msg_id, chat_id }); | ||
| } | ||
| } else { | ||
| call.mark_as_ended(&context).await?; | ||
| let canceled_call_str = stock_str::canceled_call(&context); | ||
| call.update_text(&context, &canceled_call_str).await?; | ||
| } | ||
| if can_call_me { | ||
| context.emit_event(EventType::CallEnded { msg_id, chat_id }); | ||
| } | ||
| context.emit_msgs_changed(call.msg.chat_id, call_id); | ||
| context.emit_event(EventType::CallEnded { | ||
| msg_id: call.msg.id, | ||
| chat_id: call.msg.chat_id, | ||
| }); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| async fn can_call_me(&self, from_id: ContactId) -> Result<bool> { | ||
| Ok(match who_can_call_me(self).await? { | ||
| WhoCanCallMe::Contacts => ChatIdBlocked::lookup_by_contact(self, from_id) | ||
| .await? | ||
| .is_some_and(|chat_id_blocked| { | ||
| match chat_id_blocked.blocked { | ||
| Blocked::Not => true, | ||
| Blocked::Yes | Blocked::Request => { | ||
| // Do not notify about incoming calls | ||
| // from contact requests and blocked contacts. | ||
| // | ||
| // User can still access the call and accept it | ||
| // via the chat in case of contact requests. | ||
| false | ||
| } | ||
| } | ||
| }), | ||
| WhoCanCallMe::Everybody => ChatIdBlocked::lookup_by_contact(self, from_id) | ||
| .await? | ||
| .is_none_or(|chat_id_blocked| chat_id_blocked.blocked != Blocked::Yes), | ||
| WhoCanCallMe::Nobody => false, | ||
| }) | ||
| } | ||
|
|
||
| pub(crate) async fn handle_call_msg( | ||
| &self, | ||
| call_id: MsgId, | ||
|
|
@@ -360,50 +389,33 @@ impl Context { | |
| }; | ||
|
|
||
| if call.is_incoming() { | ||
| if call.is_stale() { | ||
| let missed_call_str = stock_str::missed_call(self); | ||
| call.update_text(self, &missed_call_str).await?; | ||
| self.emit_incoming_msg(call.msg.chat_id, call_id); // notify missed call | ||
| let call_str = match call.is_stale() { | ||
| true => stock_str::missed_call(self), | ||
| false => stock_str::incoming_call(self, call.has_video_initially()), | ||
| }; | ||
| call.update_text(self, &call_str).await?; | ||
| let (msg_id, chat_id) = (call_id, call.msg.chat_id); | ||
| let can_call_me = self.can_call_me(from_id).await?; | ||
| if !can_call_me { | ||
| } else if call.is_stale() { | ||
| self.emit_event(EventType::CallMissed { msg_id, chat_id }); | ||
|
Comment on lines
+400
to
+401
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, we notified about missed call even if the contact was not allowed to call. Now, we don't. Is this on purpose?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is also in the commit message:
I think this should be fine, e.g. we don't show notifications for messages from blocked contacts, so why show missed call notifications. Again, if it was on purpose, i'll revert this, but this looked to me like a bug.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idk if it was on purpose - @r10s? |
||
| } else { | ||
| let incoming_call_str = | ||
| stock_str::incoming_call(self, call.has_video_initially()); | ||
| call.update_text(self, &incoming_call_str).await?; | ||
| self.emit_msgs_changed(call.msg.chat_id, call_id); // ringing calls are not additionally notified | ||
| let can_call_me = match who_can_call_me(self).await? { | ||
| WhoCanCallMe::Contacts => ChatIdBlocked::lookup_by_contact(self, from_id) | ||
| .await? | ||
| .is_some_and(|chat_id_blocked| { | ||
| match chat_id_blocked.blocked { | ||
| Blocked::Not => true, | ||
| Blocked::Yes | Blocked::Request => { | ||
| // Do not notify about incoming calls | ||
| // from contact requests and blocked contacts. | ||
| // | ||
| // User can still access the call and accept it | ||
| // via the chat in case of contact requests. | ||
| false | ||
| } | ||
| } | ||
| }), | ||
| WhoCanCallMe::Everybody => ChatIdBlocked::lookup_by_contact(self, from_id) | ||
| .await? | ||
| .is_none_or(|chat_id_blocked| chat_id_blocked.blocked != Blocked::Yes), | ||
| WhoCanCallMe::Nobody => false, | ||
| }; | ||
| if can_call_me { | ||
| self.emit_event(EventType::IncomingCall { | ||
| msg_id: call.msg.id, | ||
| chat_id: call.msg.chat_id, | ||
| place_call_info: call.place_call_info.to_string(), | ||
| has_video: call.has_video_initially(), | ||
| }); | ||
| } | ||
| self.emit_event(EventType::IncomingCall { | ||
| msg_id, | ||
| chat_id, | ||
| place_call_info: call.place_call_info.to_string(), | ||
| has_video: call.has_video_initially(), | ||
| }); | ||
| } | ||
| self.emit_msgs_changed(chat_id, msg_id); | ||
| if !call.is_stale() { | ||
| let wait = call.remaining_ring_seconds(); | ||
| let context = self.get_weak_context(); | ||
| task::spawn(Context::emit_end_call_if_unaccepted( | ||
| task::spawn(Context::finalize_call_if_unaccepted( | ||
| context, | ||
| wait.try_into()?, | ||
| call.msg.id, | ||
| can_call_me, | ||
| )); | ||
| } | ||
| } else { | ||
|
|
@@ -455,6 +467,7 @@ impl Context { | |
| return Ok(()); | ||
| } | ||
|
|
||
| let (msg_id, chat_id) = (call_id, call.msg.chat_id); | ||
| if !call.is_accepted() { | ||
| if call.is_incoming() { | ||
| if from_id == ContactId::SELF { | ||
|
|
@@ -465,6 +478,9 @@ impl Context { | |
| call.mark_as_canceled(self).await?; | ||
| let missed_call_str = stock_str::missed_call(self); | ||
| call.update_text(self, &missed_call_str).await?; | ||
| if self.can_call_me(from_id).await? { | ||
| self.emit_event(EventType::CallMissed { msg_id, chat_id }); | ||
| } | ||
| } | ||
| } else { | ||
| // outgoing | ||
|
|
@@ -482,12 +498,8 @@ impl Context { | |
| call.mark_as_ended(self).await?; | ||
| call.update_text_duration(self).await?; | ||
| } | ||
|
|
||
| self.emit_event(EventType::CallEnded { msg_id, chat_id }); | ||
| self.emit_msgs_changed(call.msg.chat_id, call_id); | ||
| self.emit_event(EventType::CallEnded { | ||
| msg_id: call.msg.id, | ||
| chat_id: call.msg.chat_id, | ||
| }); | ||
| } | ||
| _ => {} | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it on purpose that no IncomingMsg event is emitted anymore when missing a call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is in the commit message:
If this creates some incompatibility, i'll revert this.
IncomingMsgwas emitted before because there was no other suitable event.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know whether it creates any incompatibility, because I was not involved in calls development so far. But if we remove an event, then we need to check whether UIs were relying on this event, or ask the UI developers.
@r10s said
so, @r10s - what do you think, is it fine to remove the IncomingMsg event? @Amzd just said that he thinks it's fine to remove it, but @r10s might have the best overview over this