Merge pull request #6297 from matrix-org/gsouquet/fix-17852
commit
77968032ea
|
@ -403,9 +403,14 @@ export function bodyToHtml(content: IContent, highlights: string[], opts: IOpts
|
||||||
try {
|
try {
|
||||||
if (highlights && highlights.length > 0) {
|
if (highlights && highlights.length > 0) {
|
||||||
const highlighter = new HtmlHighlighter("mx_EventTile_searchHighlight", opts.highlightLink);
|
const highlighter = new HtmlHighlighter("mx_EventTile_searchHighlight", opts.highlightLink);
|
||||||
const safeHighlights = highlights.map(function(highlight) {
|
const safeHighlights = highlights
|
||||||
return sanitizeHtml(highlight, sanitizeParams);
|
// sanitizeHtml can hang if an unclosed HTML tag is thrown at it
|
||||||
});
|
// A search for `<foo` will make the browser crash
|
||||||
|
// an alternative would be to escape HTML special characters
|
||||||
|
// but that would bring no additional benefit as the highlighter
|
||||||
|
// does not work with those special chars
|
||||||
|
.filter((highlight: string): boolean => !highlight.includes("<"))
|
||||||
|
.map((highlight: string): string => sanitizeHtml(highlight, sanitizeParams));
|
||||||
// XXX: hacky bodge to temporarily apply a textFilter to the sanitizeParams structure.
|
// XXX: hacky bodge to temporarily apply a textFilter to the sanitizeParams structure.
|
||||||
sanitizeParams.textFilter = function(safeText) {
|
sanitizeParams.textFilter = function(safeText) {
|
||||||
return highlighter.applyHighlights(safeText, safeHighlights).join('');
|
return highlighter.applyHighlights(safeText, safeHighlights).join('');
|
||||||
|
|
|
@ -267,7 +267,7 @@ interface IProps {
|
||||||
showReactions?: boolean;
|
showReactions?: boolean;
|
||||||
|
|
||||||
// which layout to use
|
// which layout to use
|
||||||
layout: Layout;
|
layout?: Layout;
|
||||||
|
|
||||||
// whether or not to show flair at all
|
// whether or not to show flair at all
|
||||||
enableFlair?: boolean;
|
enableFlair?: boolean;
|
||||||
|
@ -321,6 +321,7 @@ export default class EventTile extends React.Component<IProps, IState> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
// no-op function because onHeightChanged is optional yet some sub-components assume its existence
|
// no-op function because onHeightChanged is optional yet some sub-components assume its existence
|
||||||
onHeightChanged: function() {},
|
onHeightChanged: function() {},
|
||||||
|
layout: Layout.Group,
|
||||||
};
|
};
|
||||||
|
|
||||||
static contextType = MatrixClientContext;
|
static contextType = MatrixClientContext;
|
||||||
|
|
|
@ -16,31 +16,28 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import { SearchResult } from "matrix-js-sdk/src/models/search-result";
|
||||||
import * as sdk from '../../../index';
|
import EventTile, { haveTileForEvent } from "./EventTile";
|
||||||
import { haveTileForEvent } from "./EventTile";
|
import DateSeparator from '../messages/DateSeparator';
|
||||||
import SettingsStore from "../../../settings/SettingsStore";
|
import SettingsStore from "../../../settings/SettingsStore";
|
||||||
import { UIFeature } from "../../../settings/UIFeature";
|
import { UIFeature } from "../../../settings/UIFeature";
|
||||||
|
import { RoomPermalinkCreator } from '../../../utils/permalinks/Permalinks';
|
||||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
// a matrix-js-sdk SearchResult containing the details of this result
|
||||||
|
searchResult: SearchResult;
|
||||||
|
// a list of strings to be highlighted in the results
|
||||||
|
searchHighlights?: string[];
|
||||||
|
// href for the highlights in this result
|
||||||
|
resultLink?: string;
|
||||||
|
onHeightChanged?: () => void;
|
||||||
|
permalinkCreator?: RoomPermalinkCreator;
|
||||||
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.rooms.SearchResultTile")
|
@replaceableComponent("views.rooms.SearchResultTile")
|
||||||
export default class SearchResultTile extends React.Component {
|
export default class SearchResultTile extends React.Component<IProps> {
|
||||||
static propTypes = {
|
public render() {
|
||||||
// a matrix-js-sdk SearchResult containing the details of this result
|
|
||||||
searchResult: PropTypes.object.isRequired,
|
|
||||||
|
|
||||||
// a list of strings to be highlighted in the results
|
|
||||||
searchHighlights: PropTypes.array,
|
|
||||||
|
|
||||||
// href for the highlights in this result
|
|
||||||
resultLink: PropTypes.string,
|
|
||||||
|
|
||||||
onHeightChanged: PropTypes.func,
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const DateSeparator = sdk.getComponent('messages.DateSeparator');
|
|
||||||
const EventTile = sdk.getComponent('rooms.EventTile');
|
|
||||||
const result = this.props.searchResult;
|
const result = this.props.searchResult;
|
||||||
const mxEv = result.context.getEvent();
|
const mxEv = result.context.getEvent();
|
||||||
const eventId = mxEv.getId();
|
const eventId = mxEv.getId();
|
Loading…
Reference in New Issue