Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSC3765: Rich text in room topics #3765

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
104 changes: 104 additions & 0 deletions proposals/3765-rich-room-topics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# MSC3765: Rich text in room topics
Copy link
Member

Choose a reason for hiding this comment

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

@alphapapa says:

On one hand, I can see some elegance in repurposing room topics for general-purpose, long-term room reference information. OTOH, it seems like overloading the purpose of topics with what, in other systems, would go in "pinned" topics or messages, or a wiki, etc.

So IMHO I would consider implementing support for pinned messages/events before overloading topics like this. It would seem relatively straightforward for a room's state to have a list of pinned events, which could be sent in initial sync by the server or be retrieved manually by clients. Clients could then display these pinned events in a room's timeline view, optionally hiding them, compressing them, etc. And the pinned events could be edited by room moderators using existing event-editing tools. (Forgive me if there's already a proposal for something like that.)

Copy link
Member

Choose a reason for hiding this comment

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

@Johennes replies:

Interesting idea. Pinned events seem to already exist. However, in their current form, these are not fit to be used for what you describe because, depending on room settings, users joining the room after the events were sent could be unable to see them.


## Problem
Johennes marked this conversation as resolved.
Show resolved Hide resolved

Topics are a central piece of room meta data and usually made easily
accessible to room members in clients. As a result, room administrators
often extend the use of topics to collect helpful peripheral information
that is related to the room’s purpose. Most commonly these are links to
external resources. At the moment, topics are limited to [plain text]
which, depending on the number and length of URLs and other content,
easily gets inconvenient to consume and calls for richer text formatting
options.

## Proposal

Drawing from extensible events as described in [MSC1767], `m.room.topic`
is prohibited in room versions that support extensible events and replaced
with a new `m.topic` event type. The latter contains a new content block
`m.topic` which wraps an `m.text` content block that allows representing
the room topic in different mime types.

``` json5
{
"type": "m.topic",
"state_key": "",
"content": {
"m.topic": {
"m.text": [{
"body": "All about **pizza** | [Recipes](https://recipes.pizza.net)"
}, {
"mimetype": "text/html",
"body": "All about <b>pizza</b> | <a href=\"https://recipes.pizza.net\">Recipes</a>"
}]
}
},
...
}
```

Details of how `m.text` works may be found in [MSC1767] and are not
repeated here.

The wrapping `m.topic` content block is similar to `m.caption` for file
uploads as defined in [MSC3551]. It avoids clients accidentally rendering
the topic state event as a room message.

In order to prevent formatting abuse in room topics, clients are
encouraged to limit the length of topics to at most two lines. Additionally,
clients should ignore things like headings and enumerations (or format them
as regular text). A future MSC may introduce a mechanism to capture extended
multiline details that are not suitable for room topics in a separate field
or event type.

A change to `/_matrix/client/v3/createRoom` is not necessary. The
endpoint has a plain text `topic` parameter but also allows to specify a
full `m.topic` event in `initial_state`.
Johennes marked this conversation as resolved.
Show resolved Hide resolved

Room topics also occur as part of the `PublicRoomsChunk` object in the
responses of `/_matrix/client/v3/publicRooms` and
`/_matrix/client/v1/rooms/{roomId}/hierarchy`. The topic can be kept
plain text here because this data should commonly only be displayed to
users that are *not* a member of the room yet. These users will not have
the same need for rich room topics as users who are inside the room. If
no plain text topic exists, home servers should return an empty topic
string from these end points. Since this will inevitably lead to bad UX,
client implementations are encouraged to always include a plain text
variant when sending `m.topic` events.
Johennes marked this conversation as resolved.
Show resolved Hide resolved

## Transition
Johennes marked this conversation as resolved.
Show resolved Hide resolved

As this MSC replaces `m.room.topic` for an extensible alternative,
clients and servers are expected to treat `m.room.topic` as invalid in
extensible event-supporting room versions.
Johennes marked this conversation as resolved.
Show resolved Hide resolved

## Potential issues

None.

## Alternatives
Johennes marked this conversation as resolved.
Show resolved Hide resolved

The combination of `format` and `formatted_body` currently utilised to
enable HTML in `m.room.message` events could be generalised to
`m.topic` events. However, this would only allow for a single
format in addition to plain text and is a weaker form of reuse than
described in the introductory section of [MSC1767].

## Security considerations

Allowing HTML in room topics is subject to the same security
considerations that apply to HTML in room messages.

## Unstable prefix

While this MSC is not considered stable, `m.topic` should be referred to
as `org.matrix.msc3765.topic`.
Comment on lines +92 to +95
Copy link
Member

@turt2live turt2live Sep 6, 2023

Choose a reason for hiding this comment

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

@jplatte says:

The current implementation in the JS SDK adds "org.matrix.msc3765.topic" as a content field to the existing m.room.topic event, but this MSC documents a new m.topic event type. Is the JS SDK implementation just outdated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The JS SDK implements an earlier version of this MSC, yes.

Comment on lines +92 to +95
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
## Unstable prefix
While this MSC is not considered stable, `m.topic` should be referred to
as `org.matrix.msc3765.topic`.
## Other notes
Normally extensible events would only be permitted in a specific room version.
However, this proposal's event is permitted in any room version. The stable
event type should only be sent in a room version which supports extensible
events, however.
## Unstable prefix
While this MSC is not considered stable, `m.topic` should be referred to as
`org.matrix.msc3765.topic`. Note that extensible events and content blocks
might have their own prefixing requirements.
### Implementation considerations
Implementation authors should note that as a feature using the Extensible Events
system, usage of the *stable* event type `m.topic` in regular room versions is not
permitted. As of writing (August 2024), Extensible Events does not have a *stable*
room version which supports such events. Therefore, implementations will have to
use the *unstable* event type if they intend to support rich text in room topics in
existing room versions.
When Extensible Events as a system is released in a dedicated room version, clients
will be able to use the stable event type there. The unstable event type should
not be used in that dedicated room version.

Copy link
Member

Choose a reason for hiding this comment

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

Normally extensible events would only be permitted in a specific room version. However, this proposal's event is permitted in any room version. The stable event type should only be sent in a room version which supports extensible events, however.

So in this case you'd expect both the unstable version and m.room.topic? I'm not quite sure what this means.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, good question. Forbidding m.room.topic in existing room versions feels wrong. Maybe this situation calls for the coexistence of both org.matrix.msc3765.topic and m.room.topic with rules for reading and writing the topic in a room:

  • If org.matrix.msc3765.topic exists, use that. Otherwise fall back to m.room.topic.
  • When writing org.matrix.msc3765.topic, also write m.room.topic with just the plain text topic.

Does that sound sensible?

Copy link
Member

Choose a reason for hiding this comment

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

I think it sounds sensible, but it is just a bit finicky / complicated. E.g.:

  1. You have both m.topic and m.room.topic set from a "modern" client, nominally the values are the same.
  2. Someone using an "old" client updates the topic, but only m.room.topic is updated.
  3. Users now see two different topics depending on what client they're using.

(This is also a potential security issue of presenting different information to different users, although it wouldn't be hidden per-say, just a display issue.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, true. 😕

The current implementation in Element Web actually has that problem even though it embedded the rich topic into m.room.topic (which was the first version of this proposal).

I don't think we can really avoid that unless we restrict m.topic to a new room version that forbids m.room.topic. Maybe pointing out the risk for early implementers in the proposal would suffice?

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a better idea. Would be interested to hear from others though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In reconsidering this, I think it may be better to revert to not allowing the use of m.topic in current room versions. This was originally proposed in an attempt to mimic the approach taken for polls in MSC3381. However, polls introduce entirely new events and, hence, are not subject to the same compatibility and security problems that replacing m.room.topic causes. Instead of this, I think we should take the approach from MSC1767 and require a new room version for m.topic.

Therefore, I propose not to apply the suggestion at the start of this thread. I don't believe this should prevent this proposal from going through FCP and, if successful, be merged without being added to the spec yet (which is how MSC1767 itself was treated, too).

Copy link
Member

Choose a reason for hiding this comment

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

What's wrong with embedding the rich topic into m.room.topic for old room versions? That seems like the best option, since presumably old clients updating the topic would then clear the rich topic rather than leaving an old rich topic laying around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, that's an interesting idea.

So new clients would write m.room.topic with both m.topic and topic (being the copy of the plain text body in m.topic) in content while old clients would only write topic (effectively deleting m.topic). If both behave correctly, we'd never have a situation where the old and new topic mismatch.

In places where the server needs the topic, it could read it from the plain text body in m.topic, falling back to topic if the former doesn't exist. On room upgrades, the server would also have to read the other mimetypes in m.topic.

Feels like relatively small risk and overhead that could enable using rich topics before extensible events land?


## Dependencies

- [MSC1767]

[plain text]: https://spec.matrix.org/v1.2/client-server-api/#mroomtopic
[MSC1767]: https://github.com/matrix-org/matrix-spec-proposals/pull/1767
[MSC3551]: https://github.com/matrix-org/matrix-spec-proposals/pull/3551
[`/rooms/{roomId}/upgrade`]: https://spec.matrix.org/v1.5/client-server-api/#post_matrixclientv3roomsroomidupgrade