"Poll start" event push notification (#1819)

* Handle polls in NotificationContentBuilder

* Cleanup
This commit is contained in:
Alfonso Grillo 2023-09-28 11:21:17 +02:00 committed by GitHub
parent 7bde419e85
commit ee0539f260
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,15 +33,21 @@ struct NotificationContentBuilder {
case .invite:
return try await processInvited(notificationItem: notificationItem, mediaProvider: mediaProvider)
case .timeline(let event):
switch try? event.eventType() {
guard let eventType = try? event.eventType() else {
return processEmpty(notificationItem: notificationItem)
}
switch eventType {
case let .messageLike(content):
switch content {
case .roomMessage(let messageType, _):
return try await processRoomMessage(notificationItem: notificationItem, messageType: messageType, mediaProvider: mediaProvider)
case .poll(let question):
return try await processPollStartEvent(notificationItem: notificationItem, pollQuestion: question, mediaProvider: mediaProvider)
default:
return processEmpty(notificationItem: notificationItem)
}
default:
case .state:
return processEmpty(notificationItem: notificationItem)
}
}
@ -116,6 +122,12 @@ struct NotificationContentBuilder {
return notification
}
private func processPollStartEvent(notificationItem: NotificationItemProxyProtocol, pollQuestion: String, mediaProvider: MediaProviderProtocol?) async throws -> UNMutableNotificationContent {
let notification = try await processCommonRoomMessage(notificationItem: notificationItem, mediaProvider: mediaProvider)
notification.body = L10n.commonPollSummary(pollQuestion)
return notification
}
private func processCommonRoomMessage(notificationItem: NotificationItemProxyProtocol, mediaProvider: MediaProviderProtocol?) async throws -> UNMutableNotificationContent {
var notification = baseMutableContent(for: notificationItem)
notification.title = notificationItem.senderDisplayName ?? notificationItem.roomDisplayName