matrix-org / matrix-org/matrix-rust-sdk

feat: Add Update Type/Diff to RoomInfoListener callback

Open
#5,982 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.3k
Forks
500
Avg merge
1d 16h
Merged PRs (30d)
106

Description

Hello, I'm writing on behalf of the Citadel product developed by ERCOM.

**Add an update type or diff field to the `RoomInfoListener` callback to enable efficient client-side updates and prevent unnecessary re-renders.**

## Description

Currently, the `RoomInfoListener` callback provides the full `RoomInfo` object whenever *any* property of the room changes.

```javascript
interface RoomInfoListener {
call(info: RoomInfo): Promise;
}
```

**The Problem:**
The client receives the entire `RoomInfo` object but has no way of knowing *what* specifically changed (e.g., did the name change? the avatar? the unread count? or just the power levels?).

To prevent unnecessary React re-renders, the client currently has to manually compare every single field against its local state:

```javascript
// Current inefficient client logic
if (newMetadata.name !== metadata.name ||
newMetadata.topic !== metadata.topic ||
newMetadata.avatar !== metadata.avatar ||
newMetadata.numUnreadMessages !== metadata.numUnreadMessages) {
// Update state...
}
```

This is inefficient because:

- **Performance:** Deep comparison of objects (especially large ones like `powerLevels` or member lists) is expensive on the main thread.
- **Complexity:** Client code becomes bloated with manual diffing logic.
- **Over subscription:** We might trigger heavy operations (like re-fetching the member list) when only a trivial field (like a typing notification or unread count) changed.

## Suggested Solution

Please enhance the `RoomInfoListener` to include an `updateType` or `changedFields` property.

### Option A: Update Type Enum

Provide a specific tag indicating the reason for the update.

```javascript
const RoomInfoUpdateType = {
Name: 'Name',
Topic: 'Topic',
Avatar: 'Avatar',
UnreadCount: 'UnreadCount',
Members: 'Members',
PowerLevels: 'PowerLevels',
...
} as const;

type RoomInfoUpdateType = typeof RoomInfoUpdateType[keyof typeof RoomInfoUpdateType];

interface RoomInfoUpdate {
info: RoomInfo;
type: RoomInfoUpdateType; // What changed?
}
```

### Option B: Changed Fields Mask

Provide a bitmask or list of fields that changed.

```javascript
interface RoomInfoUpdate {
info: RoomInfo;
changes: ["name", "numUnreadMessages"]; // Array of changed property names
}
```

## Acceptance Criteria

1. The `RoomInfoListener` callback provides context on what changed.
2. Clients can switch on the update type to selectively update only the relevant parts of their state (e.g., update unread badge without re-rendering the room header).

## Impact

- **Significant Performance Gain:** Clients can skip expensive checks (like member list diffing) when only simple metadata changes.
- **Cleaner Code:** Removes the need for manual field-by-field comparison in the UI layer.
- **Reduced Re-renders:** React components will only re-render when data they actually care about changes.
```# Add an update type or diff field to the `RoomInfoListener` callback to enable efficient client-side updates and prevent unnecessary re-renders.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the RoomInfoListener callback and tracing where RoomInfo updates are emitted. Review how each room property change is represented and whether existing tests cover listener notifications. The work is done when callbacks expose reliable change context and clients can selectively react without manually comparing the full RoomInfo.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.