diff --git a/src/components/views/messages/RoomCreate.tsx b/src/components/views/messages/RoomCreate.tsx index 8bff5dfdcc..25cfb90a48 100644 --- a/src/components/views/messages/RoomCreate.tsx +++ b/src/components/views/messages/RoomCreate.tsx @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React from "react"; +import React, { useCallback } from "react"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import dis from "../../../dispatcher/dispatcher"; @@ -36,44 +36,44 @@ interface IProps { * A message tile showing that this room was created as an upgrade of a previous * room. */ -export default class RoomCreate extends React.Component { - private onLinkClicked = (e: React.MouseEvent): void => { - e.preventDefault(); +export const RoomCreate: React.FC = ({ mxEvent, timestamp }) => { + const onLinkClicked = useCallback( + (e: React.MouseEvent): void => { + e.preventDefault(); - const predecessor = this.props.mxEvent.getContent()["predecessor"]; + const predecessor = mxEvent.getContent()["predecessor"]; - dis.dispatch({ - action: Action.ViewRoom, - event_id: predecessor["event_id"], - highlighted: true, - room_id: predecessor["room_id"], - metricsTrigger: "Predecessor", - metricsViaKeyboard: e.type !== "click", - }); - }; - - public render(): JSX.Element { - const predecessor = this.props.mxEvent.getContent()["predecessor"]; - if (predecessor === undefined) { - return
; // We should never have been instantiated in this case - } - const prevRoom = MatrixClientPeg.get().getRoom(predecessor["room_id"]); - const permalinkCreator = new RoomPermalinkCreator(prevRoom, predecessor["room_id"]); - permalinkCreator.load(); - const predecessorPermalink = permalinkCreator.forEvent(predecessor["event_id"]); - const link = ( - - {_t("Click here to see older messages.")} - - ); - - return ( - - ); + dis.dispatch({ + action: Action.ViewRoom, + event_id: predecessor["event_id"], + highlighted: true, + room_id: predecessor["room_id"], + metricsTrigger: "Predecessor", + metricsViaKeyboard: e.type !== "click", + }); + }, + [mxEvent], + ); + const predecessor = mxEvent.getContent()["predecessor"]; + if (predecessor === undefined) { + return
; // We should never have been instantiated in this case } -} + const prevRoom = MatrixClientPeg.get().getRoom(predecessor["room_id"]); + const permalinkCreator = new RoomPermalinkCreator(prevRoom, predecessor["room_id"]); + permalinkCreator.load(); + const predecessorPermalink = permalinkCreator.forEvent(predecessor["event_id"]); + const link = ( + + {_t("Click here to see older messages.")} + + ); + + return ( + + ); +}; diff --git a/src/events/EventTileFactory.tsx b/src/events/EventTileFactory.tsx index 1d30416f0f..d6b5e18ad5 100644 --- a/src/events/EventTileFactory.tsx +++ b/src/events/EventTileFactory.tsx @@ -33,7 +33,7 @@ import LegacyCallEvent from "../components/views/messages/LegacyCallEvent"; import { CallEvent } from "../components/views/messages/CallEvent"; import TextualEvent from "../components/views/messages/TextualEvent"; import EncryptionEvent from "../components/views/messages/EncryptionEvent"; -import RoomCreate from "../components/views/messages/RoomCreate"; +import { RoomCreate } from "../components/views/messages/RoomCreate"; import RoomAvatarEvent from "../components/views/messages/RoomAvatarEvent"; import { WIDGET_LAYOUT_EVENT_TYPE } from "../stores/widgets/WidgetLayoutStore"; import { ALL_RULE_TYPES } from "../mjolnir/BanList"; @@ -101,7 +101,7 @@ const EVENT_TILE_TYPES = new Map([ const STATE_EVENT_TILE_TYPES = new Map([ [EventType.RoomEncryption, (ref, props) => ], [EventType.RoomCanonicalAlias, TextualEventFactory], - [EventType.RoomCreate, (ref, props) => ], + [EventType.RoomCreate, (_ref, props) => ], [EventType.RoomMember, TextualEventFactory], [EventType.RoomName, TextualEventFactory], [EventType.RoomAvatar, (ref, props) => ], diff --git a/test/components/views/messages/RoomCreate-test.tsx b/test/components/views/messages/RoomCreate-test.tsx index 31763f9ae8..09f17e2ae4 100644 --- a/test/components/views/messages/RoomCreate-test.tsx +++ b/test/components/views/messages/RoomCreate-test.tsx @@ -22,7 +22,7 @@ import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix"; import dis from "../../../../src/dispatcher/dispatcher"; import SettingsStore from "../../../../src/settings/SettingsStore"; -import RoomCreate from "../../../../src/components/views/messages/RoomCreate"; +import { RoomCreate } from "../../../../src/components/views/messages/RoomCreate"; import { stubClient } from "../../../test-utils/test-utils"; import { Action } from "../../../../src/dispatcher/actions";