-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix outstanding UX issues with replies/mentions/keyword notifs #28270
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
Merged
t3chguy
merged 10 commits into
element-hq:develop
from
taffyko:mention-text-and-pills-ux
Jan 22, 2025
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3541391
Fix outstanding UX issues with replies/mentions/keyword notifs
taffyko 16ad814
Use createRoot instead of deprecated ReactDOM.render
taffyko 05bd8a2
Clean up react root on unmount
taffyko 6aa1b2e
Remove addition of left-edge highlight on message mentions
taffyko 3702cc0
Merge branch 'develop' into mention-text-and-pills-ux
taffyko 7ddfb54
Merge branch 'develop' into mention-text-and-pills-ux
t3chguy 0c24ba3
Merge branch 'develop' into mention-text-and-pills-ux
taffyko 8bdf0c0
Update call to ReactRootManager.render
taffyko 15aeec1
Merge branch 'develop' into mention-text-and-pills-ux
t3chguy 6f95f12
Merge branch 'develop' into mention-text-and-pills-ux
t3chguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,10 @@ Please see LICENSE files in the repository root for full details. | |
|
|
||
| import React, { createRef, SyntheticEvent, MouseEvent } from "react"; | ||
| import ReactDOM from "react-dom"; | ||
| import { MsgType } from "matrix-js-sdk/src/matrix"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import { MsgType, PushRuleKind } from "matrix-js-sdk/src/matrix"; | ||
| import { TooltipProvider } from "@vector-im/compound-web"; | ||
| import { globToRegexp } from "matrix-js-sdk/src/utils"; | ||
|
|
||
| import * as HtmlUtils from "../../../HtmlUtils"; | ||
| import { formatDate } from "../../../DateUtils"; | ||
|
|
@@ -36,6 +38,7 @@ import { EditWysiwygComposer } from "../rooms/wysiwyg_composer"; | |
| import { IEventTileOps } from "../rooms/EventTile"; | ||
| import { MatrixClientPeg } from "../../../MatrixClientPeg"; | ||
| import CodeBlock from "./CodeBlock"; | ||
| import { Pill, PillType } from "../elements/Pill"; | ||
|
|
||
| interface IState { | ||
| // the URLs (if any) to be previewed with a LinkPreviewWidget inside this TextualBody. | ||
|
|
@@ -102,6 +105,16 @@ export default class TextualBody extends React.Component<IBodyProps, IState> { | |
| } | ||
| } | ||
| } | ||
|
|
||
| // Highlight notification keywords using pills | ||
| const pushDetails = this.props.mxEvent.getPushDetails(); | ||
| if ( | ||
| pushDetails.rule?.enabled && | ||
| pushDetails.rule.kind === PushRuleKind.ContentSpecific && | ||
| pushDetails.rule.pattern | ||
| ) { | ||
| this.pillifyNotificationKeywords([content], this.regExpForKeywordPattern(pushDetails.rule.pattern)); | ||
| } | ||
| } | ||
|
|
||
| private addCodeElement(pre: HTMLPreElement): void { | ||
|
|
@@ -211,6 +224,55 @@ export default class TextualBody extends React.Component<IBodyProps, IState> { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Marks the text that activated a push-notification keyword pattern. | ||
| */ | ||
| private pillifyNotificationKeywords(nodes: ArrayLike<Element>, exp: RegExp): void { | ||
| let node: Node | null = nodes[0]; | ||
| while (node) { | ||
| if (node.nodeType === Node.TEXT_NODE) { | ||
| const text = node.nodeValue; | ||
| if (!text) { | ||
| node = node.nextSibling; | ||
| continue; | ||
| } | ||
| const match = text.match(exp); | ||
| if (!match || match.length < 3) { | ||
| node = node.nextSibling; | ||
| continue; | ||
| } | ||
| const keywordText = match[2]; | ||
| const idx = match.index! + match[1].length; | ||
| const before = text.substring(0, idx); | ||
| const after = text.substring(idx + keywordText.length); | ||
|
|
||
| const container = document.createElement("span"); | ||
| const newContent = ( | ||
| <> | ||
| {before} | ||
| <TooltipProvider> | ||
| <Pill text={keywordText} type={PillType.Keyword} /> | ||
| </TooltipProvider> | ||
| {after} | ||
| </> | ||
| ); | ||
| createRoot(container).render(newContent); | ||
taffyko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| node.parentNode?.replaceChild(container, node); | ||
| } else if (node.childNodes && node.childNodes.length) { | ||
| this.pillifyNotificationKeywords(node.childNodes as NodeListOf<Element>, exp); | ||
| } | ||
|
|
||
| node = node.nextSibling; | ||
| } | ||
| } | ||
|
|
||
| private regExpForKeywordPattern(pattern: string): RegExp { | ||
| // Reflects the push notification pattern-matching implementation at | ||
| // https://github.com/matrix-org/matrix-js-sdk/blob/dbd7d26968b94700827bac525c39afff2c198e61/src/pushprocessor.ts#L570 | ||
| return new RegExp("(^|\\W)(" + globToRegexp(pattern) + ")(\\W|$)", "i"); | ||
| } | ||
|
Comment on lines
+268
to
+272
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice to reuse the cache in the js-sdk for these regexes but not going to block this change on that |
||
|
|
||
| private findLinks(nodes: ArrayLike<Element>): string[] { | ||
| let links: string[] = []; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.