matrix-js-sdk icon indicating copy to clipboard operation
matrix-js-sdk copied to clipboard

Automatically add to account_data "m.direct" direct rooms members

Open c10b10 opened this issue 2 years ago • 2 comments

To create a direct message room we need to call

client.createRoom({ 
   is_direct: true, 
   invite: [userId], 
   visibility: "private" 
})

This creates the room, but as per the matrix spec:

Both the inviting client and the invitee’s client should record the fact that the room is a direct chat by storing an m.direct event in the account data using /user/<user_id>/account_data/.

As far as I can tell, this isn't done automatically by matrix-js-sdk.

Manual management is impossible for servers that configure auto-joining on invites. Without m.direct update, it's impossible to tell which rooms are DM rooms. This might mean that this is a Bug report rather than a Feature request.

Describe the solution you'd like

When a user joins a DM room (one that was created with the above options), matrix-js-sdk should make sure the m.direct account data is correctly set as per the matrix docs.

c10b10 avatar Sep 15 '22 13:09 c10b10

Any updates on this?

ejke avatar Dec 12 '22 14:12 ejke

If anyone's stuck on this, you can do it yourself after creating the room:

const room = await client.createRoom({
    invite: [userId],
    is_direct: true,
})

const directMap: Record<string, string[]> = client.getAccountData('m.direct')?.getContent() || {}
directMap[userId] = [...(directMap[userId] || []), room.room_id]
await client.setAccountData('m.direct', directMap)

However I agree that this is very unintuitive, and it should probably do this automatically.

wbobeirne avatar Feb 07 '24 22:02 wbobeirne