Skip to content

Fix a crash on custom room membership and map missing SDK fields - #8252

Merged
bmarty merged 6 commits into
developfrom
bma/map-missing-sdk-fields
Dec 1, 2026
Merged

bmarty merged 6 commits into
developfrom
bma/map-missing-sdk-fields

Conversation

@bmarty

@bmarty bmarty commented Nov 24, 2026

Copy link
Copy Markdown
Member

Content

We audited the data classes of org.matrix.rustcomponents:sdk-android:26.11.18-nightly against the mappers in libraries/matrix/impl, looking for SDK fields we never map. This PR fixes the crash the audit found and maps the three fields with the clearest value for the app. Each change is a separate commit:

  1. Do not crash on custom room membership state. RoomMemberMapper.mapMembership mapped MembershipState.Custom to TODO(), so any member with a non-standard membership crashed the app. It is now mapped to LEAVE, so the member is not considered active, and the unknown value is logged.
  2. Show DM status and heroes when previewing an unknown room. RoomPreviewInfo now maps isDirect, heroes and numActiveMembers. JoinRoomPresenter hardcoded isDm = false for room previews and an empty hero list for space previews; it now uses the real values. isDm is derived as "direct room with at most 2 active members".
  3. Map the redaction reason of timeline items. New EventTimelineItem.redactionReason. Mapping only, no UI yet.
  4. Map whether a send failure is recoverable. New isRecoverable on every LocalEventSendState.Failed subtype and on SendQueueUpdate.SendError. It has no default value, so a mapper cannot silently drop it. SendingFromUnverifiedDevice and MissingMediaContent change from data object to data class. Mapping only, no UI yet.

Motivation and context

The SDK keeps adding fields that never reach our models, so the UI can't use data the SDK already provides, and one gap was a crash.

Status of the other unmapped SDK fields

Found by the audit, not handled in this PR:

Useful for the UI, candidates for follow-up PRs

SDK field Possible use Notes
EventTimelineItem.redactionReason (UI) Show why a message was removed Mapped here. Needs a new string and a TimelineItemRedactedContent that carries the reason
Failed.isRecoverable / SendError.isRecoverable (UI) Offer "Retry" only when it can work Mapped here. Needs product input
LocationContent.zoomLevel Open a received location at the sender's zoom level We already send it (Timeline.sendLocation) but drop it on receive
MessageLikeEventContent.RoomMessage.inReplyToEventId "Replied to you" in notifications
PasswordStrengthEstimate.feedback zxcvbn warning and suggestions on the recovery passphrase screen
EventTimelineItem.localCreatedAt Show when a queued local echo was created
ReactionSenderData.sendState Pending or failed state for our own reactions
VideoMessageContent.circle / VideoInfo.circle Round video messages Only if the product wants the feature
EventSendState.SendingFailed.error on SendQueueUpdate.SendError Error details in send queue updates Only used by analytics today

Low value, map when a feature needs them

  • RoomInfo / NotificationRoomInfo: activeServiceMembersCount, serviceMembers. Service members are already flagged per member (RoomMember.isServiceMember).
  • NotificationRoomInfo: canonicalAlias, topic, joinedMembersCount.
  • OtherState.RoomPowerLevels: events, previousEvents, previousUsers, thresholds, previousThresholds. Only needed for richer state event text.
  • OtherState.RoomCreate.federate, OtherState.RoomHistoryVisibility.historyVisibility. Same.
  • RoomPowerLevelsValues.usersDefault. RoomPowerLevelChanges.usersDefault is also always sent as null.
  • RecentEmoji.count. Only emoji is kept.
  • ComposerDraft.attachments. Always emptyList(), so drafts lose their attachments.

Debug or internal, no need to map

  • EventTimelineItem.eventTypeRaw, NotificationItem.rawEvent, NotificationItem.actions
  • EventEncryptionInfo: senderId, senderCurve25519Key, sessionId, shieldStateStrict
  • PasswordStrengthEstimate.guesses, StickyEvent.expiresAtMs

SDK parameters we never set (defaults are used): extraContentJson on upload and gallery parameters, seven options of VirtualElementCallWidgetConfig, expect on the Category and ReadReceipts room list filters.

Fields with very common names (name, topic, ...) can hide a gap from the audit, so these lists may be incomplete.

Screenshots / GIFs

No visual change in previews. Item 2 changes what the join room screen shows when it previews an unknown DM or space.

Tests

  • New and updated unit tests: RoomMemberMapperTest, RoomPreviewInfoMapperTest, RoomPreviewInfoTest, JoinRoomPresenterTest, EventTimelineItemMapperTest, SendQueueUpdatesExtTest
  • ./gradlew :libraries:matrix:impl:testDebugUnitTest :features:messages:impl:testDebugUnitTest passes
  • To test manually, open a link to a DM you are not part of and check that the join screen shows it as a DM

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

  • I am aware of the etiquette.
  • This PR was made with the help of AI:
    • Yes. In this case, please request a review by Copilot.
    • No.
  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly defines what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

🤖 Generated with Claude Code

bmarty and others added 4 commits November 24, 2026 15:34
RoomMemberMapper.mapMembership mapped MembershipState.Custom to TODO(),
which throws NotImplementedError when the SDK returns a member with a
non-standard membership value. Map it to LEAVE instead, so the member is
not considered active, and log the unknown value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RoomPreviewInfo from the SDK exposes isDirect, heroes and numActiveMembers
but we never mapped them, so JoinRoomPresenter hardcoded isDm = false for
room previews and an empty hero list for space previews.

Map the three fields into the api RoomPreviewInfo, derive isDm from them
(direct room with at most 2 active members, like the SDK does for
RoomInfo), and use isDm and heroes when building the join room content
state from a preview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EventTimelineItem from the SDK exposes redactionReason, the reason given
with the redaction of an event (from the server, or from our own pending
redaction), but it was dropped by EventTimelineItemMapper.

Expose it as EventTimelineItem.redactionReason in the matrix api so the
timeline can later show why a message was removed. No UI change yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK reports isRecoverable on EventSendState.SendingFailed and on
RoomSendQueueUpdate.SendError, but we dropped it, so the app could not
tell a failure that disabled the send queue from one parked until the
user retries or cancels it.

Expose it as LocalEventSendState.Failed.isRecoverable, set on every
failure subtype without a default so the mapper cannot drop it again,
and as SendQueueUpdate.SendError.isRecoverable. SendingFromUnverifiedDevice
and MissingMediaContent become data classes to carry the value, and the
verified user failure iterators keep it when splitting a failure.
No UI change yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bmarty bmarty added the PR-Bugfix For bug fix label Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/QoCEUy

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.28571% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.13%. Comparing base (896d280) to head (0b817af).
⚠️ Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
...mpl/timeline/item/event/EventTimelineItemMapper.kt 33.33% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8252      +/-   ##
===========================================
+ Coverage    81.11%   81.13%   +0.02%     
===========================================
  Files         2906     2906              
  Lines        87593    87614      +21     
  Branches     11906    11897       -9     
===========================================
+ Hits         71052    71088      +36     
+ Misses       11900    11889      -11     
+ Partials      4641     4637       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Document the transactionId parameter of SendQueueUpdate.SendError
(OutdatedDocumentation) and remove unnecessary parentheses in
RoomPreviewInfo.isDm (UnnecessaryParentheses).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@bmarty
bmarty marked this pull request as ready for review December 1, 2026 16:00
@bmarty
bmarty requested a review from a team as a code owner December 1, 2026 16:00
@bmarty
bmarty requested review from jmartinesp and removed request for a team December 1, 2026 16:00

@jmartinesp jmartinesp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I was a bit worried because I remember making some exceptions for isRecoverable in the send queue errors, but I don't think this affects it.

)
}
is QueueWedgeError.GenericApiError -> {
LocalEventSendState.Failed.Unknown(queueWedgeError.msg)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up. This PR is just adding the mapping, there is no behavior change.

@bmarty
bmarty merged commit b3f6920 into develop Dec 1, 2026
30 of 31 checks passed
@bmarty
bmarty deleted the bma/map-missing-sdk-fields branch December 1, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-Bugfix For bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants