mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 23:18:27 +02:00
Feature/2611 Notifications on mentions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user