Include room display name in fallback content

This commit is contained in:
ismailgulek 2020-06-25 14:18:53 +03:00
parent 2dd4b7dcc2
commit b6fded100d
No known key found for this signature in database
GPG key ID: E96336D42D9470A9

View file

@ -69,6 +69,8 @@ class NotificationService: UNNotificationServiceExtension {
// setup user account // setup user account
setup(withRoomId: roomId, eventId: eventId) { setup(withRoomId: roomId, eventId: eventId) {
// preprocess the payload, will attempt to fetch room display name
self.preprocessPayload(forEventId: eventId, roomId: roomId)
// fetch the event first // fetch the event first
self.fetchEvent(withEventId: eventId, roomId: roomId) self.fetchEvent(withEventId: eventId, roomId: roomId)
} }
@ -124,6 +126,16 @@ class NotificationService: UNNotificationServiceExtension {
} }
} }
/// Attempts to preprocess payload and attach room display name to the best attempt content
/// - Parameters:
/// - eventId: Event identifier to mutate best attempt content
/// - roomId: Room identifier to fetch display name
func preprocessPayload(forEventId eventId: String, roomId: String) {
guard let session = NotificationService.mxSession else { return }
guard let roomDisplayName = session.store.summary?(ofRoom: roomId)?.displayname else { return }
originalContents[eventId]?.title = roomDisplayName
}
func fetchEvent(withEventId eventId: String, roomId: String) { func fetchEvent(withEventId eventId: String, roomId: String) {
guard let mxSession = NotificationService.mxSession else { guard let mxSession = NotificationService.mxSession else {
// there is something wrong, do not change the content // there is something wrong, do not change the content