← Back to PRs

#19736: fix(matrix): remove memberCount heuristic from DM detection

by derbronko open 2026-02-18 04:08 View on GitHub →
channel: matrix size: XS
## What Removes the `memberCount === 2` early-return in `isDirectMessage()` that misclassifies 2-person group rooms as DMs. Moves `resolveMemberCount()` to after the DM checks (diagnostic logging only). ## Why Matrix already distinguishes DMs from groups at the protocol level: - [`m.direct` account data](https://spec.matrix.org/v1.12/client-server-api/#mdirect) — set when creating a DM - [`is_direct` on `m.room.member`](https://spec.matrix.org/v1.12/client-server-api/#mroommember) — set on the invite event Both are already checked by `client.dms.isDm()` and `hasDirectFlag()`. The `memberCount === 2` heuristic fires between these proper checks and short-circuits with false positives for any 2-person group room (admin channels, monitoring rooms, etc.). ## Change **File:** `extensions/matrix/src/matrix/monitor/direct.ts` 1. Remove the `memberCount === 2` block (lines 86-90) 2. Move `resolveMemberCount()` to after the DM checks — now only runs for confirmed group rooms (diagnostic logging), avoiding an unnecessary API call for every DM ## Edge Cases | Scenario | m.direct | is_direct | Caught by | Still works? | |----------|----------|-----------|-----------|:---:| | Normal DM | ✅ | ✅ | `client.dms.isDm()` | ✅ | | DM without m.direct | ❌ | ✅ | `hasDirectFlag()` | ✅ | | DM without is_direct | ✅ | ❌ | `client.dms.isDm()` | ✅ | | **2-person group** | **❌** | **❌** | **None (correct!)** | **✅ fixed** | No DM detection is lost. Only false positives are removed. Fixes #7718

Most Similar PRs