From dc4bb237d40be4b5c83eea883031b0d6504e2a91 Mon Sep 17 00:00:00 2001 From: kenwuuu Date: Mon, 17 Apr 2023 02:37:29 -0700 Subject: [PATCH] Replace hardcoded strings with MsgType constants (#10604) * replace hardcoded strings with MsgType constants * fix import and revert comments Signed-off-by: Ken Wu kenqiwu@gmail.com * fix import Signed-off-by: Ken Wu kenqiwu@gmail.com --------- Signed-off-by: Ken Wu kenqiwu@gmail.com --- src/components/structures/FilePanel.tsx | 7 ++----- src/components/views/elements/EventTilePreview.tsx | 5 +++-- src/components/views/messages/EditHistoryMessage.tsx | 3 ++- src/components/views/rooms/SendMessageComposer.tsx | 4 ++-- src/utils/exportUtils/HtmlExport.tsx | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/structures/FilePanel.tsx b/src/components/structures/FilePanel.tsx index 9d92892d3b..a6cce06c35 100644 --- a/src/components/structures/FilePanel.tsx +++ b/src/components/structures/FilePanel.tsx @@ -154,11 +154,8 @@ class FilePanel extends React.Component { }, }); - const filterId = await client.getOrCreateFilter("FILTER_FILES_" + client.credentials.userId, filter); - filter.filterId = filterId; - const timelineSet = room.getOrCreateFilteredTimelineSet(filter); - - return timelineSet; + filter.filterId = await client.getOrCreateFilter("FILTER_FILES_" + client.credentials.userId, filter); + return room.getOrCreateFilteredTimelineSet(filter); } private onPaginationRequest = ( diff --git a/src/components/views/elements/EventTilePreview.tsx b/src/components/views/elements/EventTilePreview.tsx index 10d7b458cc..eaa41903f7 100644 --- a/src/components/views/elements/EventTilePreview.tsx +++ b/src/components/views/elements/EventTilePreview.tsx @@ -18,6 +18,7 @@ import React from "react"; import classnames from "classnames"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { RoomMember } from "matrix-js-sdk/src/models/room-member"; +import { MsgType } from "matrix-js-sdk/src/@types/event"; import * as Avatar from "../../../Avatar"; import EventTile from "../rooms/EventTile"; @@ -78,12 +79,12 @@ export default class EventTilePreview extends React.Component { sender: this.props.userId, content: { "m.new_content": { - msgtype: "m.text", + msgtype: MsgType.Text, body: message, displayname: this.props.displayName, avatar_url: this.props.avatarUrl, }, - "msgtype": "m.text", + "msgtype": MsgType.Text, "body": message, "displayname": this.props.displayName, "avatar_url": this.props.avatarUrl, diff --git a/src/components/views/messages/EditHistoryMessage.tsx b/src/components/views/messages/EditHistoryMessage.tsx index 421673d771..930c6d7b9d 100644 --- a/src/components/views/messages/EditHistoryMessage.tsx +++ b/src/components/views/messages/EditHistoryMessage.tsx @@ -17,6 +17,7 @@ limitations under the License. import React, { createRef } from "react"; import { EventStatus, IContent, MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event"; import classNames from "classnames"; +import { MsgType } from "matrix-js-sdk/src/@types/event"; import * as HtmlUtils from "../../../HtmlUtils"; import { editBodyDiffToHtml } from "../../../utils/MessageDiffUtils"; @@ -166,7 +167,7 @@ export default class EditHistoryMessage extends React.PureComponent diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index 745b2c3ab6..24fbf5ccad 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -18,7 +18,7 @@ import React, { ClipboardEvent, createRef, KeyboardEvent } from "react"; import EMOJI_REGEX from "emojibase-regex"; import { IContent, MatrixEvent, IEventRelation, IMentions } from "matrix-js-sdk/src/models/event"; import { DebouncedFunc, throttle } from "lodash"; -import { EventType, RelationType } from "matrix-js-sdk/src/@types/event"; +import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event"; import { logger } from "matrix-js-sdk/src/logger"; import { Room } from "matrix-js-sdk/src/models/room"; import { Composer as ComposerEvent } from "@matrix-org/analytics-events/types/typescript/Composer"; @@ -187,7 +187,7 @@ export function createMessageContent( const body = textSerialize(model); const content: IContent = { - msgtype: isEmote ? "m.emote" : "m.text", + msgtype: isEmote ? MsgType.Emote : MsgType.Text, body: body, }; const formattedBody = htmlSerializeIfNeeded(model, { diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx index 3ec04a460b..d18a380625 100644 --- a/src/utils/exportUtils/HtmlExport.tsx +++ b/src/utils/exportUtils/HtmlExport.tsx @@ -344,7 +344,7 @@ export default class HTMLExporter extends Exporter { protected createModifiedEvent(text: string, mxEv: MatrixEvent, italic = true): MatrixEvent { const modifiedContent = { - msgtype: "m.text", + msgtype: MsgType.Text, body: `${text}`, format: "org.matrix.custom.html", formatted_body: `${text}`,