Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion DcCore/DcCore/DC/events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
public static let incomingCallAccepted = Notification.Name(rawValue: "incomingCallAccepted")
public static let outgoingCallAccepted = Notification.Name(rawValue: "outgoingCallAccepted")
public static let callEnded = Notification.Name(rawValue: "callEnded")

public static let callMissed = Notification.Name(rawValue: "callMissed")

public static let relayHelperDidChange = Notification.Name(rawValue: "relayHelperDidChange")
}

Expand Down Expand Up @@ -241,6 +242,14 @@
"message_id": Int(data1),
])

case DC_EVENT_CALL_MISSED:

Check failure on line 245 in DcCore/DcCore/DC/events.swift

View workflow job for this annotation

GitHub Actions / build

cannot find 'DC_EVENT_CALL_MISSED' in scope
logger.info("☎️ DC_EVENT_CALL_MISSED(\(accountId),\(data1))")
NotificationCenter.default.post(name: Event.callMissed, object: nil, userInfo: [
"account_id": Int(accountId),
"message_id": Int(data1),
"chat_id": Int(data2),
])

default:
break
}
Expand Down
5 changes: 3 additions & 2 deletions DcCore/DcCore/Helper/UNMutableNotificationContent+init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ public extension UNMutableNotificationContent {
}

convenience init?(forMissedCallMsg msg: DcMsg, chat: DcChat, context: DcContext) {
guard !context.isMuted(), !chat.isMuted, !canUseCallKit else { return nil }
guard msg.id != 0 else { return nil } // invalid message
guard !context.isMuted(), !chat.isMuted else { return nil }
self.init()
let sender = msg.getSenderName(context.getContact(id: msg.fromContactId))
title = chat.isMultiUser ? chat.name : sender
body = .localized("missed_call")
userInfo["account_id"] = context.id
userInfo["chat_id"] = chat.id
userInfo["message_id"] = msg.id
threadIdentifier = "calls"
threadIdentifier = "\(context.id)-\(chat.id)"
sound = .default
setRelevanceScore(for: msg, in: chat, context: context)
}
Expand Down
7 changes: 7 additions & 0 deletions DcNotificationService/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ class NotificationService: UNNotificationServiceExtension {
if let content = UNMutableNotificationContent(forWebxdcNotification: event.data2String, msg: msg, chat: chat, context: dcContext) {
notifications.append(content)
}
} else if event.id == DC_EVENT_CALL_MISSED {
let dcContext = dcAccounts.get(id: event.accountId)
let chat = dcContext.getChat(chatId: event.data2Int)
let msg = dcContext.getMessage(id: event.data1Int)
if let content = UNMutableNotificationContent(forMissedCallMsg: msg, chat: chat, context: dcContext) {
notifications.append(content)
}
} else if event.id == DC_EVENT_INCOMING_CALL {
UserDefaults.pushToDebugArray("☎️")
let payload: [String: Any] = [
Expand Down
15 changes: 0 additions & 15 deletions deltachat-ios/Calls/CallManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,6 @@ class CallManager: NSObject {
if let currentCall, currentCall.contextId == accountId, currentCall.messageId == msgId {
logger.info("☎️ call to end (\(accountId),\(msgId)) is the current call :)")
endCallController(uuid: currentCall.uuid)

// call is missed if
// - not accepted elsewhere (currentCall would have been set to nil in handleIncomingCallAcceptedEvent)
// - and not accepted here (check currentCall.callAcceptedHere)
if !currentCall.callAcceptedHere, !canUseCallKit {
let dcContext = DcAccounts.shared.get(id: accountId)
let dcMsg = dcContext.getMessage(id: msgId)
let dcChat = dcContext.getChat(chatId: dcMsg.chatId)
let content = UNMutableNotificationContent(forMissedCallMsg: dcMsg, chat: dcChat, context: dcContext)
if let content {
let id = "missed-call-" + currentCall.uuid.uuidString
let request = UNNotificationRequest(identifier: id, content: content, trigger: nil)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
}
} else {
logger.info("☎️ call (\(accountId),\(msgId)) already ended")
}
Expand Down
1 change: 0 additions & 1 deletion deltachat-ios/Calls/CallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import WebRTC

// TODO: "Connecting..." and "Ringing..." status messages
// TODO: Minimize call to PiP when app is opened from a deeplink (or from a notification)
// TODO: Fix missed call logic: if the missed call was from me dont send notification
// TODO: Actually stop capturing mic when muted
// FIXME: Still doesn't always work when in background

Expand Down
18 changes: 18 additions & 0 deletions deltachat-ios/Helper/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class NotificationManager {
NotificationCenter.default.addObserver(self, selector: #selector(NotificationManager.handleIncomingReaction(_:)), name: Event.incomingReaction, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(NotificationManager.handleIncomingWebxdcNotify(_:)), name: Event.incomingWebxdcNotify, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(NotificationManager.handleMessagesNoticed(_:)), name: Event.messagesNoticed, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleCallMissedEvent), name: Event.callMissed, object: nil)
}

deinit {
Expand Down Expand Up @@ -162,4 +163,21 @@ public class NotificationManager {
UIApplication.shared.endBackgroundTask(backgroundTask) // this line must be reached to balance call to `beginBackgroundTask` above
}
}

@objc private func handleCallMissedEvent(_ notification: Notification) {
DispatchQueue.global().async { [weak self] in
guard let self,
let ui = notification.userInfo,
let accountId = ui["account_id"] as? Int,
let msgId = ui["message_id"] as? Int
else { return }
let eventContext = dcAccounts.get(id: accountId)
let dcMsg = eventContext.getMessage(id: msgId)
let dcChat = eventContext.getChat(chatId: dcMsg.chatId)
if let content = UNMutableNotificationContent(forMissedCallMsg: dcMsg, chat: dcChat, context: eventContext) {
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
}
}
}
Loading