Skip to content

Commit a09e91d

Browse files
author
Marco Romano
committed
Display poll notifications in the notification drawer
Display notifications for polls as if they were message events.
1 parent 53cf82f commit a09e91d

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/notification/NotificationData.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ sealed interface NotificationContent {
6161
) : MessageLike
6262
data object RoomRedaction : MessageLike
6363
data object Sticker : MessageLike
64-
data class Poll(val question: String) : MessageLike
64+
data class Poll(
65+
val senderId: UserId,
66+
val question: String,
67+
) : MessageLike
6568
}
6669

6770
sealed interface StateEvent : NotificationContent {

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/notification/TimelineEventToNotificationContentMapper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private fun MessageLikeEventContent.toContent(senderId: UserId): NotificationCon
9494
}
9595
MessageLikeEventContent.RoomRedaction -> NotificationContent.MessageLike.RoomRedaction
9696
MessageLikeEventContent.Sticker -> NotificationContent.MessageLike.Sticker
97-
is MessageLikeEventContent.Poll -> NotificationContent.MessageLike.Poll(question)
97+
is MessageLikeEventContent.Poll -> NotificationContent.MessageLike.Poll(senderId, question)
9898
}
9999
}
100100
}

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotifiableEventResolver.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,22 @@ class NotifiableEventResolver @Inject constructor(
133133
NotificationContent.MessageLike.KeyVerificationStart -> null.also {
134134
Timber.tag(loggerTag.value).d("Ignoring notification for verification ${content.javaClass.simpleName}")
135135
}
136-
is NotificationContent.MessageLike.Poll -> null.also {
137-
// TODO Polls: handle notification rendering
138-
Timber.tag(loggerTag.value).d("Ignoring notification for poll")
136+
is NotificationContent.MessageLike.Poll -> {
137+
buildNotifiableMessageEvent(
138+
sessionId = userId,
139+
senderId = content.senderId,
140+
roomId = roomId,
141+
eventId = eventId,
142+
noisy = isNoisy,
143+
timestamp = this.timestamp,
144+
senderName = senderDisplayName,
145+
body = stringProvider.getString(CommonStrings.common_poll_summary, content.question),
146+
imageUriString = this.contentUrl,
147+
roomName = roomDisplayName,
148+
roomIsDirect = isDirect,
149+
roomAvatarPath = roomAvatarUrl,
150+
senderAvatarPath = senderAvatarUrl,
151+
)
139152
}
140153
is NotificationContent.MessageLike.ReactionContent -> null.also {
141154
Timber.tag(loggerTag.value).d("Ignoring notification for reaction")

0 commit comments

Comments
 (0)