Skip to content

MSC4144: Per-message profiles - #4144

Open
tulir wants to merge 17 commits into
matrix-org:mainfrom
beeper:per-message-profile
Open

MSC4144: Per-message profiles#4144
tulir wants to merge 17 commits into
matrix-org:mainfrom
beeper:per-message-profile

Conversation

@tulir

@tulir tulir commented May 10, 2024

Copy link
Copy Markdown
Member

Signed-off-by: Tulir Asokan <tulir@beeper.com>
@tulir tulir added proposal A matrix spec change proposal. Process state. A-Client Server Client-Server API kind:feature MSC for not-core and not-maintenance stuff needs-implementation This MSC does not have a qualifying implementation for the SCT to review. The MSC cannot enter FCP. labels May 10, 2024
@onestacked

This comment was marked as resolved.

Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md Outdated
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md Outdated
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md Outdated
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
@tulir tulir removed the needs-implementation This MSC does not have a qualifying implementation for the SCT to review. The MSC cannot enter FCP. label Jan 28, 2025
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
@disastercurl

This comment was marked as resolved.


To remove the HTML fallback, either use a HTML parser to drop the entire `strong`
tag with a `data-mx-profile-fallback` attribute, or replace matches of the
following regex with an empty string: `<strong\s+data-mx-profile-fallback(?:="")?\s*>([^<]+): </strong\s*>`

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Stealthii said outside of a thread:

To address one of the main criticisms I have with this MSC: the suggestion of matching specifically this tag: <strong\s+data-mx-profile-fallback(?:="")?\s*>([^<]+): </strong\s*>

If we are recommending regular expressions, I would suggest the following, which is safer, handling multi-line input, other tags, matching the same closing tag, etc.

input = input.replace(/<(\w+)[^>]*\bdata-mx-profile-fallback\b[^>]*>[\s\S]*?<\/\1>/g, "")

This however is not 100% safe, no regular expression is. Personally I would like to argue for non-fallback content to be explicitly stated in that MSC in a separate property field, because regex should be used for matching, not content manipulation in matrix client or bridge implementations.

Similarly, suggesting trimming the plaintext component by "PMP name length + 2" also assumes that clients implement the spec accurately as it stands today, and do not deviate. This also cannot be guaranteed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Personally I would like to argue for non-fallback content to be explicitly stated in that MSC in a separate property field

Duplicating the entire content is a really bad idea. Each fallback doubles the content, so if there are 3 different fallbacks (edits, formatting, per-message profiles), that'd result in 2*2*2 = 8 duplicates of the content. It might be "only" 6 duplicates if the non-fallback per-message profile is only inside m.new_content, but if anyone decided to invent a new thing needing a fallback copy, it'd jump to 12 or more

which is safer, handling multi-line input, other tags, matching the same closing tag, etc.

The regex is intentionally fairly strict, other tags are not meant to be allowed. It could maybe slightly be relaxed in terms of the trailing space inside the fallback to allow \n there (<br> is obviously not allowed), perhaps :\s* instead of :

Alternatively, I guess the fallback itself could be put in another field, such that clients can simply do formatted_body.replace(fallback, "") rather than using a regex 🤔

Similarly, suggesting trimming the plaintext component by "PMP name length + 2" also assumes that clients implement the spec accurately as it stands today, and do not deviate. This also cannot be guaranteed.

The only consequence of deviating from the spec is that the message will render incorrectly. If clients don't implement the spec correctly and their messages render differently than they intended, that's their problem, not the spec's.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Blackilykat posted outside of a thread:

I'm not active in matrix spec proposals but am developing a bot which benefits from this feature and I'd like to give my 2 cents.

I think the sender should have more freedom on how to format the HTML fallback. Currently, it is required to be in exactly a <strong> tag with the data-mx-profile-fallback attribute containing exactly the text <profile>: . I think it would be beneficial to allow any tag (i.e. span) with the same attribute and any contents, including HTML formatted contents. This would include the original fallback but allow bots to customize the fallback if needed.

My use case: I am bridging a Minecraft chat over matrix. Different players have different chat formats which I would like to include in the fallback so outdated clients will see chat exactly as shown in-game. Clients which support this feature would instead show the message as if it was sent by that user, ignoring the HTML content inside the fallback.

If a client supports HTML-formatted content it should already have the logic to correctly parse HTML tags and ignoring a first tag with the data-mx-profile-fallback attribute, regardless of which tag it is or its contents, should not be difficult to implement.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Clients may want to remove fallbacks at a different stage than HTML parsing, so requiring the use of a parser is probably a bad idea. Several clients had trouble with reply fallbacks too.

A separate field containing the exact fallback string to remove should be easy and safe to remove, but it also feels slightly weird and has never been done before. Maybe I should just do that anyway

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe you could include the length of the formatted fallback string instead of the whole thing to avoid sending/storing duplicate data.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That would require it to strictly be a prefix, which may not be the case if the message uses paragraph tags or other such things

@7w1 7w1 mentioned this pull request Mar 21, 2026
9 tasks
Comment thread proposals/4144-per-message-profile.md
Comment thread proposals/4144-per-message-profile.md
@Blackilykat

This comment was marked as resolved.

@q-TheDog

q-TheDog commented Sep 6, 2026

Copy link
Copy Markdown

Client Implementation (Haven Desktop): Haven-Organization/haven-desktop@15fd359

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Client Server Client-Server API kind:feature MSC for not-core and not-maintenance stuff proposal A matrix spec change proposal. Process state.

Projects

None yet

Development

Successfully merging this pull request may close these issues.