mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 08:15:02 +00:00
Merge pull request #7203 from element-hq/matthew/lls-push-notifications
Render push notifications for live location share starts (MSC4505)
This commit is contained in:
+1
-1
@@ -118,7 +118,7 @@ sealed interface NotificationContent {
|
||||
data class RoomTopic(val topic: String) : StateEvent
|
||||
data object SpaceChild : StateEvent
|
||||
data object SpaceParent : StateEvent
|
||||
data object BeaconInfo : StateEvent
|
||||
data class BeaconInfo(val senderId: UserId) : StateEvent
|
||||
}
|
||||
|
||||
data class Invite(
|
||||
|
||||
+3
-3
@@ -40,11 +40,11 @@ class TimelineEventToNotificationContentMapper {
|
||||
private fun TimelineEventContent.toContent(senderId: UserId): NotificationContent {
|
||||
return when (this) {
|
||||
is TimelineEventContent.MessageLike -> content.toContent(senderId)
|
||||
is TimelineEventContent.State -> content.toContent()
|
||||
is TimelineEventContent.State -> content.toContent(senderId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun StateEventContent.toContent(): NotificationContent.StateEvent {
|
||||
private fun StateEventContent.toContent(senderId: UserId): NotificationContent.StateEvent {
|
||||
return when (this) {
|
||||
StateEventContent.PolicyRuleRoom -> NotificationContent.StateEvent.PolicyRuleRoom
|
||||
StateEventContent.PolicyRuleServer -> NotificationContent.StateEvent.PolicyRuleServer
|
||||
@@ -71,7 +71,7 @@ private fun StateEventContent.toContent(): NotificationContent.StateEvent {
|
||||
is StateEventContent.RoomTopic -> NotificationContent.StateEvent.RoomTopic(topic)
|
||||
StateEventContent.SpaceChild -> NotificationContent.StateEvent.SpaceChild
|
||||
StateEventContent.SpaceParent -> NotificationContent.StateEvent.SpaceParent
|
||||
StateEventContent.BeaconInfo -> NotificationContent.StateEvent.BeaconInfo
|
||||
StateEventContent.BeaconInfo -> NotificationContent.StateEvent.BeaconInfo(senderId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-2
@@ -303,6 +303,24 @@ class DefaultNotifiableEventResolver(
|
||||
Timber.tag(loggerTag.value).d("Ignoring notification for beacon")
|
||||
throw NotificationResolverException.EventFilteredOut
|
||||
}
|
||||
is NotificationContent.StateEvent.BeaconInfo -> {
|
||||
val notifiableEventMessage = buildNotifiableMessageEvent(
|
||||
sessionId = userId,
|
||||
senderId = content.senderId,
|
||||
roomId = roomId,
|
||||
eventId = eventId,
|
||||
noisy = isNoisy,
|
||||
timestamp = this.timestamp,
|
||||
senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId),
|
||||
body = stringProvider.getString(R.string.notification_live_location_started_body),
|
||||
imageUriString = null,
|
||||
roomName = roomDisplayName,
|
||||
roomIsDm = isDm,
|
||||
roomAvatarPath = roomAvatarUrl,
|
||||
senderAvatarPath = senderAvatarUrl,
|
||||
)
|
||||
ResolvedPushEvent.Event(notifiableEventMessage)
|
||||
}
|
||||
is NotificationContent.StateEvent.RoomMemberContent,
|
||||
NotificationContent.StateEvent.PolicyRuleRoom,
|
||||
NotificationContent.StateEvent.PolicyRuleServer,
|
||||
@@ -322,8 +340,7 @@ class DefaultNotifiableEventResolver(
|
||||
NotificationContent.StateEvent.RoomTombstone,
|
||||
is NotificationContent.StateEvent.RoomTopic,
|
||||
NotificationContent.StateEvent.SpaceChild,
|
||||
NotificationContent.StateEvent.SpaceParent,
|
||||
NotificationContent.StateEvent.BeaconInfo -> {
|
||||
NotificationContent.StateEvent.SpaceParent -> {
|
||||
Timber.tag(loggerTag.value).d("Ignoring notification for state event ${content.javaClass.simpleName}")
|
||||
throw NotificationResolverException.EventFilteredOut
|
||||
}
|
||||
|
||||
+22
@@ -416,6 +416,27 @@ class DefaultNotifiableEventResolverTest : RobolectricTest() {
|
||||
assertThat(result.getEvent(request)).isEqualTo(Result.success(expectedResult))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `resolve live location share start`() = runTest {
|
||||
val sut = createDefaultNotifiableEventResolver(
|
||||
notificationResult = Result.success(
|
||||
mapOf(
|
||||
AN_EVENT_ID to Result.success(aNotificationData(
|
||||
content = NotificationContent.StateEvent.BeaconInfo(
|
||||
senderId = A_USER_ID_2,
|
||||
),
|
||||
))
|
||||
)
|
||||
)
|
||||
)
|
||||
val request = aPushRequest(A_SESSION_ID, A_ROOM_ID, AN_EVENT_ID, "firebase")
|
||||
val result = sut.resolveEvents(A_SESSION_ID, listOf(request))
|
||||
val expectedResult = ResolvedPushEvent.Event(
|
||||
aNotifiableMessageEvent(body = "Started sharing their live location")
|
||||
)
|
||||
assertThat(result.getEvent(request)).isEqualTo(Result.success(expectedResult))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `resolve RoomMemberContent invite room`() = runTest {
|
||||
val sut = createDefaultNotifiableEventResolver(
|
||||
@@ -829,6 +850,7 @@ class DefaultNotifiableEventResolverTest : RobolectricTest() {
|
||||
testNoResults(NotificationContent.MessageLike.KeyVerificationDone)
|
||||
testNoResults(NotificationContent.MessageLike.ReactionContent(relatedEventId = AN_EVENT_ID_2.value))
|
||||
testNoResults(NotificationContent.MessageLike.Sticker)
|
||||
testNoResults(NotificationContent.MessageLike.Beacon)
|
||||
testNoResults(NotificationContent.StateEvent.PolicyRuleRoom)
|
||||
testNoResults(NotificationContent.StateEvent.PolicyRuleServer)
|
||||
testNoResults(NotificationContent.StateEvent.PolicyRuleUser)
|
||||
|
||||
Reference in New Issue
Block a user