Skip to content

Commit

Permalink
apply logic for reply mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Jan 7, 2025
1 parent 44e9e9b commit e3243eb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
30 changes: 16 additions & 14 deletions DcNotificationService/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions deltachat-ios/DC/DcMsg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions deltachat-ios/Helper/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e3243eb

Please sign in to comment.