Add support for MSC-4144: Per-Message Profiles #82

Open
beanie wants to merge 2 commits from beanie/out-of-your-element:msc4144 into main
Contributor

This PR implements support for using per-message profile data if present in either com.beeper.per_message_profile (unstable), or m.per_message_profile (stable), updating the displayName and avatarURL as required.

If a message contains a fallback, we additionally strip the fallback identity from both the plaintext and formatted HTML components as per the specification.

Completes #59

This PR implements support for using per-message profile data if present in either `com.beeper.per_message_profile` (unstable), or `m.per_message_profile` (stable), updating the displayName and avatarURL as required. If a message contains a fallback, we additionally strip the fallback identity from both the plaintext and formatted HTML components as per the specification. Completes #59
beanie added 2 commits 2026-03-20 14:19:10 +00:00
Override webhook username and avatar_url from m.per_message_profile
(and unstable com.beeper.per_message_profile) when present.
The stable key takes priority over the unstable prefix.
Remove data-mx-profile-fallback elements from formatted_body and
displayname prefix from plain body when per-message profile is used.
Author
Contributor

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

I have instead implemented the following, which is safer, handling multi-line input, 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'm going to argue for the non-fallback content to be explicitly stated in that MSC, because regex should be used for matching, not content manipulation in matrix client or bridge implementations.

Similarly, trimming the plaintext component also assumes that clients implement the spec accurately as it stands today, and do not deviate. This also cannot be guaranteed.

To address one of the main criticisms I have with that MSC, they make the suggestion of matching specifically this tag: `<strong\s+data-mx-profile-fallback(?:="")?\s*>([^<]+): </strong\s*>` I have instead implemented the following, which is safer, handling multi-line input, matching the same closing tag, etc. ```js 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'm going to argue for the non-fallback content to be explicitly stated in that MSC, because regex should be used for matching, not content manipulation in matrix client or bridge implementations. Similarly, trimming the plaintext component also assumes that clients implement the spec accurately as it stands today, and do not deviate. This also cannot be guaranteed.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u msc4144:beanie-msc4144
git checkout beanie-msc4144

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout main
git merge --no-ff beanie-msc4144
git checkout beanie-msc4144
git rebase main
git checkout main
git merge --ff-only beanie-msc4144
git checkout beanie-msc4144
git rebase main
git checkout main
git merge --no-ff beanie-msc4144
git checkout main
git merge --squash beanie-msc4144
git checkout main
git merge --ff-only beanie-msc4144
git checkout main
git merge beanie-msc4144
git push origin main
Sign in to join this conversation.
No description provided.