Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit e576347

Browse files
authored
Fix pinned messages not re-linkifying on edit (#9042)
* Fix pinned messages not re-linkifying on edit * Fix tests
1 parent 2587aa1 commit e576347

File tree

9 files changed

+30
-13
lines changed

9 files changed

+30
-13
lines changed

src/HtmlUtils.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { split } from 'lodash';
2626
import katex from 'katex';
2727
import { AllHtmlEntities } from 'html-entities';
2828
import { IContent } from 'matrix-js-sdk/src/models/event';
29+
import { Optional } from 'matrix-events-sdk';
2930

3031
import {
3132
_linkifyElement,
@@ -456,9 +457,9 @@ function formatEmojis(message: string, isHtmlMessage: boolean): (JSX.Element | s
456457
* opts.forComposerQuote: optional param to lessen the url rewriting done by sanitization, for quoting into composer
457458
* opts.ref: React ref to attach to any React components returned (not compatible with opts.returnString)
458459
*/
459-
export function bodyToHtml(content: IContent, highlights: string[], opts: IOptsReturnString): string;
460-
export function bodyToHtml(content: IContent, highlights: string[], opts: IOptsReturnNode): ReactNode;
461-
export function bodyToHtml(content: IContent, highlights: string[], opts: IOpts = {}) {
460+
export function bodyToHtml(content: IContent, highlights: Optional<string[]>, opts: IOptsReturnString): string;
461+
export function bodyToHtml(content: IContent, highlights: Optional<string[]>, opts: IOptsReturnNode): ReactNode;
462+
export function bodyToHtml(content: IContent, highlights: Optional<string[]>, opts: IOpts = {}) {
462463
const isFormattedBody = content.format === "org.matrix.custom.html" && content.formatted_body;
463464
let bodyHasEmoji = false;
464465
let isHtmlMessage = false;

src/components/structures/RightPanel.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ export default class RightPanel extends React.Component<IProps, IState> {
199199

200200
case RightPanelPhases.PinnedMessages:
201201
if (SettingsStore.getValue("feature_pinning")) {
202-
card = <PinnedMessagesCard room={this.props.room} onClose={this.onClose} />;
202+
card = <PinnedMessagesCard
203+
room={this.props.room}
204+
onClose={this.onClose}
205+
permalinkCreator={this.props.permalinkCreator}
206+
/>;
203207
}
204208
break;
205209
case RightPanelPhases.Timeline:

src/components/views/messages/IBodyProps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export interface IBodyProps {
2626
mxEvent: MatrixEvent;
2727

2828
/* a list of words to highlight */
29-
highlights: string[];
29+
highlights?: string[];
3030

3131
/* link URL for the highlights */
32-
highlightLink: string;
32+
highlightLink?: string;
3333

3434
/* callback called when dynamic content in events are loaded */
3535
onHeightChanged: () => void;

src/components/views/messages/MessageEvent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
6767
public context!: React.ContextType<typeof MatrixClientContext>;
6868

6969
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
70-
super(props);
70+
super(props, context);
7171

7272
if (MediaEventHelper.isEligible(this.props.mxEvent)) {
7373
this.mediaHelper = new MediaEventHelper(this.props.mxEvent);

src/components/views/messages/TextualBody.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { createRef, SyntheticEvent, MouseEvent } from 'react';
17+
import React, { createRef, SyntheticEvent, MouseEvent, ReactNode } from 'react';
1818
import ReactDOM from 'react-dom';
1919
import highlight from 'highlight.js';
2020
import { MsgType } from "matrix-js-sdk/src/@types/event";
@@ -565,7 +565,7 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
565565

566566
// only strip reply if this is the original replying event, edits thereafter do not have the fallback
567567
const stripReply = !mxEvent.replacingEvent() && !!getParentEventId(mxEvent);
568-
let body;
568+
let body: ReactNode;
569569
if (SettingsStore.isEnabled("feature_extensible_events")) {
570570
const extev = this.props.mxEvent.unstableExtensibleEvent as MessageEvent;
571571
if (extev?.isEquivalentTo(M_MESSAGE)) {

src/components/views/right_panel/PinnedMessagesCard.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ import { useRoomState } from "../../../hooks/useRoomState";
3333
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
3434
import { ReadPinsEventId } from "./types";
3535
import Heading from '../typography/Heading';
36+
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
3637

3738
interface IProps {
3839
room: Room;
40+
permalinkCreator: RoomPermalinkCreator;
3941
onClose(): void;
4042
}
4143

@@ -78,7 +80,7 @@ export const useReadPinnedEvents = (room: Room): Set<string> => {
7880
return readPinnedEvents;
7981
};
8082

81-
const PinnedMessagesCard = ({ room, onClose }: IProps) => {
83+
const PinnedMessagesCard = ({ room, onClose, permalinkCreator }: IProps) => {
8284
const cli = useContext(MatrixClientContext);
8385
const roomContext = useContext(RoomContext);
8486
const canUnpin = useRoomState(room, state => state.mayClientSendStateEvent(EventType.RoomPinnedEvents, cli));
@@ -152,6 +154,7 @@ const PinnedMessagesCard = ({ room, onClose }: IProps) => {
152154
key={ev.getId()}
153155
event={ev}
154156
onUnpinClicked={canUnpin ? () => onUnpinClicked(ev) : undefined}
157+
permalinkCreator={permalinkCreator}
155158
/>
156159
));
157160
} else {

src/components/views/rooms/PinnedEventTile.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
3333
import { getUserNameColorClass } from "../../../utils/FormattingUtils";
3434
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
3535
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
36+
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
3637

3738
interface IProps {
3839
event: MatrixEvent;
40+
permalinkCreator: RoomPermalinkCreator;
3941
onUnpinClicked?(): void;
4042
}
4143

@@ -140,6 +142,8 @@ export default class PinnedEventTile extends React.Component<IProps> {
140142
className="mx_PinnedEventTile_body"
141143
maxImageHeight={150}
142144
onHeightChanged={() => {}} // we need to give this, apparently
145+
permalinkCreator={this.props.permalinkCreator}
146+
replacingEventId={this.props.event.replacingEventId()}
143147
/>
144148
</div>
145149

src/events/EventTileFactory.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ import { shouldDisplayAsBeaconTile } from "../utils/beacon/timeline";
4848
export interface EventTileTypeProps {
4949
ref?: React.RefObject<any>; // `any` because it's effectively impossible to convince TS of a reasonable type
5050
mxEvent: MatrixEvent;
51-
highlights: string[];
52-
highlightLink: string;
51+
highlights?: string[];
52+
highlightLink?: string;
5353
showUrlPreview?: boolean;
5454
onHeightChanged: () => void;
5555
forExport?: boolean;

test/components/views/right_panel/PinnedMessagesCard-test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import PinnedMessagesCard from "../../../../src/components/views/right_panel/Pin
4242
import PinnedEventTile from "../../../../src/components/views/rooms/PinnedEventTile";
4343
import MPollBody from "../../../../src/components/views/messages/MPollBody";
4444
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
45+
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
4546

4647
describe("<PinnedMessagesCard />", () => {
4748
stubClient();
@@ -85,7 +86,11 @@ describe("<PinnedMessagesCard />", () => {
8586
const mountPins = async (room: Room): Promise<ReactWrapper<ComponentProps<typeof PinnedMessagesCard>>> => {
8687
let pins;
8788
await act(async () => {
88-
pins = mount(<PinnedMessagesCard room={room} onClose={jest.fn()} />, {
89+
pins = mount(<PinnedMessagesCard
90+
room={room}
91+
onClose={jest.fn()}
92+
permalinkCreator={new RoomPermalinkCreator(room, room.roomId)}
93+
/>, {
8994
wrappingComponent: MatrixClientContext.Provider,
9095
wrappingComponentProps: { value: cli },
9196
});

0 commit comments

Comments
 (0)