From cdab08d912f5ec77596e3e06ccda360f2de23fff Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 7 Jan 2025 20:59:27 +0100 Subject: [PATCH] apply logic for reply mentions --- .../NotificationService.swift | 30 ++++++++++--------- deltachat-ios/DC/DcMsg.swift | 8 +++++ .../Helper/NotificationManager.swift | 5 ++-- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/DcNotificationService/NotificationService.swift b/DcNotificationService/NotificationService.swift index a1335a2b1..1079dbd11 100644 --- a/DcNotificationService/NotificationService.swift +++ b/DcNotificationService/NotificationService.swift @@ -54,22 +54,24 @@ class NotificationService: UNNotificationServiceExtension { if event.id == DC_EVENT_INCOMING_MSG { let dcContext = dcAccounts.get(id: event.accountId) let chat = dcContext.getChat(chatId: event.data1Int) - if !dcContext.isMuted() && !chat.isMuted { + if !dcContext.isMuted() { let msg = dcContext.getMessage(id: event.data2Int) - let sender = msg.getSenderName(dcContext.getContact(id: msg.fromContactId)) - if chat.isGroup { - bestAttemptContent.title = chat.name - bestAttemptContent.body = "\(sender): " + (msg.summary(chars: 80) ?? "") - } else { - bestAttemptContent.title = sender - bestAttemptContent.body = msg.summary(chars: 80) ?? "" - } - bestAttemptContent.userInfo["account_id"] = dcContext.id - bestAttemptContent.userInfo["chat_id"] = chat.id - bestAttemptContent.userInfo["message_id"] = msg.id + if !chat.isMuted || (chat.isGroup && msg.isReplyToSelf && dcContext.isMentionsEnabled()) { + let sender = msg.getSenderName(dcContext.getContact(id: msg.fromContactId)) + if chat.isGroup { + bestAttemptContent.title = chat.name + bestAttemptContent.body = "\(sender): " + (msg.summary(chars: 80) ?? "") + } else { + bestAttemptContent.title = sender + bestAttemptContent.body = msg.summary(chars: 80) ?? "" + } + bestAttemptContent.userInfo["account_id"] = dcContext.id + bestAttemptContent.userInfo["chat_id"] = chat.id + bestAttemptContent.userInfo["message_id"] = msg.id - uniqueChats["\(dcContext.id)-\(chat.id)"] = bestAttemptContent.title - messageCount += 1 + uniqueChats["\(dcContext.id)-\(chat.id)"] = bestAttemptContent.title + messageCount += 1 + } } } else if event.id == DC_EVENT_INCOMING_REACTION { let dcContext = dcAccounts.get(id: event.accountId) diff --git a/deltachat-ios/DC/DcMsg.swift b/deltachat-ios/DC/DcMsg.swift index 1ab0bc125..99460180e 100644 --- a/deltachat-ios/DC/DcMsg.swift +++ b/deltachat-ios/DC/DcMsg.swift @@ -111,6 +111,14 @@ public class DcMsg { } } + public var isReplyToSelf: Bool { + if let quoteMessage { + return quoteMessage.isFromCurrentSender + } else { + return false + } + } + public var parent: DcMsg? { guard let msgpointer = dc_msg_get_parent(messagePointer) else { return nil } return DcMsg(pointer: msgpointer) diff --git a/deltachat-ios/Helper/NotificationManager.swift b/deltachat-ios/Helper/NotificationManager.swift index fe292460b..724a8bfed 100644 --- a/deltachat-ios/Helper/NotificationManager.swift +++ b/deltachat-ios/Helper/NotificationManager.swift @@ -100,9 +100,10 @@ public class NotificationManager { !eventContext.isMuted() { let chat = eventContext.getChat(chatId: chatId) + let msg = eventContext.getMessage(id: messageId) + + if !chat.isMuted || (chat.isGroup && msg.isReplyToSelf && eventContext.isMentionsEnabled()) { - if !chat.isMuted { - let msg = eventContext.getMessage(id: messageId) let fromContact = eventContext.getContact(id: msg.fromContactId) let sender = msg.getSenderName(fromContact) let content = UNMutableNotificationContent()