matrix-org / matrix-rust-sdk

Matrix Client-Server SDK for Rust
Apache License 2.0
1.26k stars 246 forks source link

Rejecting an invite reports a MembershipChange of None instead of InvitationRejected #3960

Closed frebib closed 2 months ago

frebib commented 2 months ago

I experienced this using Element X (Android) although tracing through the code it looks like the logic for the MembershipChange event lies either here in rust-sdk https://github.com/matrix-org/matrix-rust-sdk/blob/1eecb2d603edfae43b842010ac13d021411d0332/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs#L300, or somewhere here in Ruma: https://github.com/matrix-org/ruma/blob/9d8c9c477f15c07b0f2fe4ff4a01aa2ea36eae66/crates/ruma-common/src/events/room/member/change.rs#L125

To reproduce:

  1. Get invited to a room
  2. Reject the invite
  3. Get reinvited to the same room
  4. Accept the invite
  5. Observe that the MembershipChange is None ("You made no changes" in Element X)

If it's helpful, these are the two state events in the room that shows this on my device

{
  "type": "m.room.member",
  "sender": "@steve:nerdhouse.io",
  "content": {
    "is_direct": true,
    "displayname": "frebib ⚡️",
    "avatar_url": "mxc://spritsail.io/CT5Q8KSagUCI32Sk8P98fN64WoOZjPke",
    "membership": "invite"
  },
  "state_key": "@frebib:spritsail.io",
  "origin_server_ts": 1725572457950,
  "event_id": "$WzSyO403lheriGNFjEb7Oy0oOieqAYvmNKuwADPZ3c4",
  "room_id": "!nSrXPEfFEflVtWQEFx:nerdhouse.io"
}
{
  "content": {
    "membership": "leave",
    "avatar_url": "mxc://spritsail.io/CT5Q8KSagUCI32Sk8P98fN64WoOZjPke",
    "displayname": "frebib ⚡️"
  },
  "origin_server_ts": 1725572594185,
  "sender": "@frebib:spritsail.io",
  "state_key": "@frebib:spritsail.io",
  "type": "m.room.member",
  "event_id": "$h1cZB-4x0TiNSK7kdYqUN0aGO5S8AfekbyWQvgbjtR0",
  "room_id": "!nSrXPEfFEflVtWQEFx:nerdhouse.io"
}
frebib commented 2 months ago

I just remembered that EleX shows the Rust model for the state event:

EventTimelineItem {
    sender: "@frebib:spritsail.io",
    sender_profile: Ready(
        Profile {
            display_name: Some(
                "frebib ⚡\u{fe0f}",
            ),
            display_name_ambiguous: false,
            avatar_url: Some(
                "mxc://spritsail.io/CT5Q8KSagUCI32Sk8P98fN64WoOZjPke",
            ),
        },
    ),
    reactions: ReactionsByKeyBySender(
        {},
    ),
    timestamp: 2024-09-05T21:43:14.185,
    content: MembershipChange(
        RoomMembershipChange {
            user_id: "@frebib:spritsail.io",
            content: Original {
                content: RoomMemberEventContent {
                    avatar_url: None,
                    displayname: None,
                    is_direct: None,
                    membership: "leave",
                    third_party_invite: None,
                    blurhash: None,
                    reason: None,
                    join_authorized_via_users_server: None,
                },
                prev_content: None, 👈🏼
            },
            change: Some(
                None,
            ),
        },
    ),
    kind: Remote(
        RemoteEventTimelineItem {
            event_id: "$h1cZB-4x0TiNSK7kdYqUN0aGO5S8AfekbyWQvgbjtR0",
            transaction_id: None,
            read_receipts: {},
            is_own: true,
            is_highlighted: false,
            encryption_info: None,
            origin: Pagination,
            ..
        },
    ),
    is_room_encrypted: Some(
        true,
    ),
}

With prev_content being None, we're hitting this codepath here then here which explains the "made no changes" message. The question is why there is no prev_content

frebib commented 2 months ago

Is this a sync issue? Is prev_content missing from unsigned in sync? https://github.com/matrix-org/matrix-rust-sdk/blob/1eecb2d603edfae43b842010ac13d021411d0332/crates/matrix-sdk-ui/src/timeline/event_handler.rs#L179

This a conduwuit server (latest version, whatever that is) using the native sliding sync implementation.

frebib commented 2 months ago

After discussing in the conduwuit room, it seems this might be a server-side bug causing prev_events to be missing -> https://matrix.to/#/!n8DKU1BeeJilOJXDPr:seirdy.one/$xlbC1d33vb3gvhJ4Hickk6vCv-OIQ5oL-ge63d-g1LA?via=awawawawawawawawawawawawawawawawawawawawawawawawawawawawawawaw.gay&via=transfem.dev&via=matrix.org