Render incoming Element Call in the notification (unsupported)

This commit is contained in:
Benoit Marty 2024-11-12 15:12:53 +01:00
parent 066545a4b3
commit 6e2a0cfa91
8 changed files with 28 additions and 3 deletions

View File

@ -2937,6 +2937,7 @@
<string name="call_slide_to_end_conference">Slide to end the call</string> <string name="call_slide_to_end_conference">Slide to end the call</string>
<string name="call_unsupported">Unsupported call</string>
<string name="call_unsupported_matrix_rtc_call">Unsupported call. The new Element X app is needed to join this call.</string> <string name="call_unsupported_matrix_rtc_call">Unsupported call. The new Element X app is needed to join this call.</string>
<string name="re_authentication_activity_title">Re-Authentication Needed</string> <string name="re_authentication_activity_title">Re-Authentication Needed</string>

View File

@ -499,7 +499,11 @@ fun Event.getPollContent(): MessagePollContent? {
} }
fun Event.supportsNotification() = fun Event.supportsNotification() =
this.getClearType() in EventType.MESSAGE + EventType.POLL_START.values + EventType.POLL_END.values + EventType.STATE_ROOM_BEACON_INFO.values this.getClearType() in EventType.MESSAGE +
EventType.POLL_START.values +
EventType.POLL_END.values +
EventType.STATE_ROOM_BEACON_INFO.values +
EventType.ELEMENT_CALL_NOTIFY.values
fun Event.isContentReportable() = fun Event.isContentReportable() =
this.getClearType() in EventType.MESSAGE + EventType.STATE_ROOM_BEACON_INFO.values this.getClearType() in EventType.MESSAGE + EventType.STATE_ROOM_BEACON_INFO.values

View File

@ -32,3 +32,8 @@ data class Mentions(
@Json(name = "room") val room: Boolean? = null, @Json(name = "room") val room: Boolean? = null,
@Json(name = "user_ids") val userIds: List<String>? = null, @Json(name = "user_ids") val userIds: List<String>? = null,
) )
fun ElementCallNotifyContent.isUserMentioned(userId: String): Boolean {
return mentions?.room == true ||
mentions?.userIds?.contains(userId) == true
}

View File

@ -61,6 +61,7 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
in EventType.POLL_START.values, in EventType.POLL_START.values,
in EventType.POLL_END.values, in EventType.POLL_END.values,
in EventType.STATE_ROOM_BEACON_INFO.values, in EventType.STATE_ROOM_BEACON_INFO.values,
in EventType.ELEMENT_CALL_NOTIFY.values,
EventType.MESSAGE, EventType.MESSAGE,
EventType.REDACTION, EventType.REDACTION,
EventType.ENCRYPTED, EventType.ENCRYPTED,

View File

@ -214,6 +214,9 @@ class MessageActionsViewModel @AssistedInject constructor(
in EventType.POLL_END.values -> { in EventType.POLL_END.values -> {
stringProvider.getString(CommonStrings.message_reply_to_ended_poll_preview) stringProvider.getString(CommonStrings.message_reply_to_ended_poll_preview)
} }
in EventType.ELEMENT_CALL_NOTIFY.values -> {
stringProvider.getString(CommonStrings.call_unsupported)
}
else -> null else -> null
} }
} }

View File

@ -142,6 +142,9 @@ class DisplayableEventFormatter @Inject constructor(
in EventType.STATE_ROOM_BEACON_INFO.values -> { in EventType.STATE_ROOM_BEACON_INFO.values -> {
simpleFormat(senderName, stringProvider.getString(CommonStrings.sent_live_location), appendAuthor) simpleFormat(senderName, stringProvider.getString(CommonStrings.sent_live_location), appendAuthor)
} }
in EventType.ELEMENT_CALL_NOTIFY.values -> {
simpleFormat(senderName, stringProvider.getString(CommonStrings.call_unsupported), appendAuthor)
}
VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO -> { VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO -> {
formatVoiceBroadcastEvent(timelineEvent.root, isDm, senderName) formatVoiceBroadcastEvent(timelineEvent.root, isDm, senderName)
} }
@ -243,6 +246,9 @@ class DisplayableEventFormatter @Inject constructor(
in EventType.STATE_ROOM_BEACON_INFO.values -> { in EventType.STATE_ROOM_BEACON_INFO.values -> {
stringProvider.getString(CommonStrings.sent_live_location) stringProvider.getString(CommonStrings.sent_live_location)
} }
in EventType.ELEMENT_CALL_NOTIFY.values -> {
stringProvider.getString(CommonStrings.call_unsupported)
}
else -> { else -> {
span { span {
} }

View File

@ -47,6 +47,7 @@ object TimelineDisplayableEvents {
) + ) +
EventType.POLL_START.values + EventType.POLL_START.values +
EventType.POLL_END.values + EventType.POLL_END.values +
EventType.ELEMENT_CALL_NOTIFY.values +
EventType.STATE_ROOM_BEACON_INFO.values + EventType.STATE_ROOM_BEACON_INFO.values +
EventType.BEACON_LOCATION_DATA.values EventType.BEACON_LOCATION_DATA.values
} }

View File

@ -34,7 +34,9 @@ import org.matrix.android.sdk.api.session.getUserOrDefault
import org.matrix.android.sdk.api.session.room.getTimelineEvent import org.matrix.android.sdk.api.session.room.getTimelineEvent
import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
import org.matrix.android.sdk.api.session.room.model.message.ElementCallNotifyContent
import org.matrix.android.sdk.api.session.room.model.message.MessageWithAttachmentContent import org.matrix.android.sdk.api.session.room.model.message.MessageWithAttachmentContent
import org.matrix.android.sdk.api.session.room.model.message.isUserMentioned
import org.matrix.android.sdk.api.session.room.sender.SenderInfo import org.matrix.android.sdk.api.session.room.sender.SenderInfo
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.api.session.room.timeline.getEditedEventId import org.matrix.android.sdk.api.session.room.timeline.getEditedEventId
@ -149,9 +151,11 @@ class NotifiableEventResolver @Inject constructor(
) )
} else { } else {
event.attemptToDecryptIfNeeded(session) event.attemptToDecryptIfNeeded(session)
// only convert encrypted messages to NotifiableMessageEvents // For incoming Element Call, check that the user is mentioned
val isIncomingElementCall = event.root.getClearType() in EventType.ELEMENT_CALL_NOTIFY.values &&
event.root.getClearContent()?.toModel<ElementCallNotifyContent>()?.isUserMentioned(session.myUserId) == true
when { when {
event.root.supportsNotification() -> { isIncomingElementCall || event.root.supportsNotification() -> {
val body = displayableEventFormatter.format(event, isDm = room.roomSummary()?.isDirect.orFalse(), appendAuthor = false).toString() val body = displayableEventFormatter.format(event, isDm = room.roomSummary()?.isDirect.orFalse(), appendAuthor = false).toString()
val roomName = room.roomSummary()?.displayName ?: "" val roomName = room.roomSummary()?.displayName ?: ""
val senderDisplayName = event.senderInfo.disambiguatedDisplayName val senderDisplayName = event.senderInfo.disambiguatedDisplayName