Merge pull request #7207 from element-hq/matthew/knock-push-notifications-pr

Display push notifications for knocks
This commit is contained in:
Benoit Marty
2026-08-11 17:44:26 +02:00
committed by GitHub
3 changed files with 57 additions and 1 deletions
@@ -36,6 +36,7 @@ import io.element.android.libraries.matrix.api.media.isPreviewEnabled
import io.element.android.libraries.matrix.api.notification.NotificationContent
import io.element.android.libraries.matrix.api.notification.NotificationData
import io.element.android.libraries.matrix.api.permalink.PermalinkParser
import io.element.android.libraries.matrix.api.room.RoomMembershipState
import io.element.android.libraries.matrix.api.room.join.JoinRule
import io.element.android.libraries.matrix.api.timeline.item.event.AudioMessageType
import io.element.android.libraries.matrix.api.timeline.item.event.EmoteMessageType
@@ -319,6 +320,29 @@ class DefaultNotifiableEventResolver(
Timber.tag(loggerTag.value).d("Ignoring notification for sticker")
throw NotificationResolverException.EventFilteredOut
}
is NotificationContent.StateEvent.RoomMemberContent -> {
// MSC4506: the homeserver pushes knocks to users who can act on them.
if (content.membershipState == RoomMembershipState.KNOCK) {
val notifiableMessageEvent = buildNotifiableMessageEvent(
sessionId = userId,
senderId = content.userId,
roomId = roomId,
eventId = eventId,
noisy = isNoisy,
timestamp = this.timestamp,
senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.userId),
body = stringProvider.getString(R.string.notification_knock_request_body),
roomName = roomDisplayName,
roomIsDm = isDm,
roomAvatarPath = roomAvatarUrl,
senderAvatarPath = senderAvatarUrl,
)
ResolvedPushEvent.Event(notifiableMessageEvent)
} else {
Timber.tag(loggerTag.value).d("Ignoring notification for membership ${content.membershipState}")
throw NotificationResolverException.EventFilteredOut
}
}
NotificationContent.MessageLike.Beacon -> {
Timber.tag(loggerTag.value).d("Ignoring notification for beacon")
throw NotificationResolverException.EventFilteredOut
@@ -341,7 +365,6 @@ class DefaultNotifiableEventResolver(
)
ResolvedPushEvent.Event(notifiableEventMessage)
}
is NotificationContent.StateEvent.RoomMemberContent,
NotificationContent.StateEvent.PolicyRuleRoom,
NotificationContent.StateEvent.PolicyRuleServer,
NotificationContent.StateEvent.PolicyRuleUser,
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2026 Element Creations Ltd.
~
~ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
~ Please see LICENSE files in the repository root for full details.
-->
<resources>
<!-- Body of the notification shown to users who can act on a knock (MSC4506 knock push rule). -->
<string name="notification_knock_request_body">"Requested to join"</string>
</resources>
@@ -652,6 +652,28 @@ class DefaultNotifiableEventResolverTest : RobolectricTest() {
assertThat(result.getEvent(request)).isEqualTo(Result.success(expectedResult))
}
@Test
fun `resolve RoomMemberContent knock`() = runTest {
val sut = createDefaultNotifiableEventResolver(
notificationResult = Result.success(
mapOf(
AN_EVENT_ID to Result.success(aNotificationData(
content = NotificationContent.StateEvent.RoomMemberContent(
userId = A_USER_ID_2,
membershipState = RoomMembershipState.KNOCK
)
))
)
)
)
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 = "Requested to join")
)
assertThat(result.getEvent(request)).isEqualTo(Result.success(expectedResult))
}
@Test
fun `resolve RoomMemberContent other`() = runTest {
val sut = createDefaultNotifiableEventResolver(