Feature/2611 Notifications on mentions

This commit is contained in:
Arnfried Griesert
2022-09-22 06:18:25 +00:00
parent 61ba9448c7
commit 92f4cdc8cc
6 changed files with 91 additions and 2 deletions

View File

@@ -229,7 +229,27 @@ class NotificationService: UNNotificationServiceExtension {
return false
}
}
/// BWI - Update the sharedUserDefault dictionary for room mentions
/// - Parameter roomID: room for which the number of mentions should be increased
private func increaseMentions(for roomID: String) {
// Read dictionary of count mentions in room from the sharedUserDefaults
guard let sharedUserDefaults = MXKAppSettings.standard().sharedUserDefaults else {
return
}
guard let data = sharedUserDefaults.data(forKey: Mentions.sharedUserDefaultsKey), let mentions = try? JSONDecoder().decode(Mentions.self, from: data) else {
return
}
// Update dictionary
let newCountMentions = (mentions.mentionsInRoom[roomID] ?? 0) + 1
mentions.mentionsInRoom[roomID] = newCountMentions
if let data = try? JSONEncoder().encode(mentions) {
sharedUserDefaults.set(data, forKey: Mentions.sharedUserDefaultsKey)
}
}
private func setupAnalytics(){
// Configure our analytics. It will start if the option is enabled
let analytics = Analytics.shared
@@ -498,6 +518,13 @@ class NotificationService: UNNotificationServiceExtension {
notificationTitle = self.messageTitle(for: eventSenderName, in: roomDisplayName)
}
// bwi: update counter if someone mentioned the account user
if let formattedBody = event.content["formatted_body"] as? String {
if let accountMatrixID = self.userAccount?.mxCredentials.userId, formattedBody.contains(accountMatrixID) {
self.increaseMentions(for: roomId)
}
}
// bwi: hide content in message notifications
if BwiBuildSettings.bwiHideNotificationMessageBody {
// Hide the content

View File

@@ -40,6 +40,7 @@ targets:
- path: ../bwi/AppConfig
- path: ../bwi/ServerURLs
- path: ../bwi/SecureStorage
- path: ../bwi/Mentions/Mentions.swift
- path: ../bwi/NotificationTimes/NotificationTimes.swift
- path: ../bwi/NotificationTimes/NotificationTimesRoomSettings.swift
- path: ../bwi/NotificationTimes/NotificationTimesWeekday.swift