diff --git a/src/components/views/context_menus/MessageContextMenu.tsx b/src/components/views/context_menus/MessageContextMenu.tsx index 84c61a716d..019691e4c7 100644 --- a/src/components/views/context_menus/MessageContextMenu.tsx +++ b/src/components/views/context_menus/MessageContextMenu.tsx @@ -19,6 +19,7 @@ import React from 'react'; import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event'; import { EventType, RelationType } from "matrix-js-sdk/src/@types/event"; import { Relations } from 'matrix-js-sdk/src/models/relations'; +import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; import { MatrixClientPeg } from '../../../MatrixClientPeg'; import dis from '../../../dispatcher/dispatcher'; @@ -42,7 +43,6 @@ import { IPosition, ChevronFace } from '../../structures/ContextMenu'; import RoomContext, { TimelineRenderingType } from '../../../contexts/RoomContext'; import { ComposerInsertPayload } from "../../../dispatcher/payloads/ComposerInsertPayload"; import { WidgetLayoutStore } from '../../../stores/widgets/WidgetLayoutStore'; -import { POLL_START_EVENT_TYPE } from '../../../polls/consts'; import EndPollDialog from '../dialogs/EndPollDialog'; import { isPollEnded } from '../messages/MPollBody'; diff --git a/src/components/views/dialogs/EndPollDialog.tsx b/src/components/views/dialogs/EndPollDialog.tsx index cf50193639..f3403839b9 100644 --- a/src/components/views/dialogs/EndPollDialog.tsx +++ b/src/components/views/dialogs/EndPollDialog.tsx @@ -18,11 +18,12 @@ import React from "react"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixClient } from "matrix-js-sdk/src/client"; import { Relations } from "matrix-js-sdk/src/models/relations"; +import { IPollEndContent, POLL_END_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; +import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events"; import { _t } from "../../../languageHandler"; import { IDialogProps } from "./IDialogProps"; import QuestionDialog from "./QuestionDialog"; -import { IPollEndContent, POLL_END_EVENT_TYPE, TEXT_NODE_TYPE } from "../../../polls/consts"; import { findTopAnswer } from "../messages/MPollBody"; import Modal from "../../../Modal"; import ErrorDialog from "./ErrorDialog"; diff --git a/src/components/views/elements/PollCreateDialog.tsx b/src/components/views/elements/PollCreateDialog.tsx index 4e1e76d23f..1f442c93d8 100644 --- a/src/components/views/elements/PollCreateDialog.tsx +++ b/src/components/views/elements/PollCreateDialog.tsx @@ -16,6 +16,7 @@ limitations under the License. import React, { ChangeEvent, createRef } from "react"; import { Room } from "matrix-js-sdk/src/models/room"; +import { makePollContent, POLL_KIND_DISCLOSED, POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; import ScrollableBaseModal, { IScrollableBaseState } from "../dialogs/ScrollableBaseModal"; import { IDialogProps } from "../dialogs/IDialogProps"; @@ -25,7 +26,6 @@ import { _t } from "../../../languageHandler"; import { arrayFastClone, arraySeed } from "../../../utils/arrays"; import Field from "./Field"; import AccessibleButton from "./AccessibleButton"; -import { makePollContent, POLL_KIND_DISCLOSED, POLL_START_EVENT_TYPE } from "../../../polls/consts"; import Spinner from "./Spinner"; interface IProps extends IDialogProps { diff --git a/src/components/views/messages/MPollBody.tsx b/src/components/views/messages/MPollBody.tsx index 10f43938ed..51c895414b 100644 --- a/src/components/views/messages/MPollBody.tsx +++ b/src/components/views/messages/MPollBody.tsx @@ -19,12 +19,7 @@ import classNames from 'classnames'; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Relations } from 'matrix-js-sdk/src/models/relations'; import { MatrixClient } from 'matrix-js-sdk/src/matrix'; - -import { _t } from '../../../languageHandler'; -import { replaceableComponent } from "../../../utils/replaceableComponent"; -import Modal from '../../../Modal'; -import { IBodyProps } from "./IBodyProps"; -import { formatCommaSeparatedList } from '../../../utils/FormattingUtils'; +import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events"; import { IPollAnswer, IPollContent, @@ -32,8 +27,13 @@ import { POLL_END_EVENT_TYPE, POLL_RESPONSE_EVENT_TYPE, POLL_START_EVENT_TYPE, - TEXT_NODE_TYPE, -} from '../../../polls/consts'; +} from "matrix-js-sdk/src/@types/polls"; + +import { _t } from '../../../languageHandler'; +import { replaceableComponent } from "../../../utils/replaceableComponent"; +import Modal from '../../../Modal'; +import { IBodyProps } from "./IBodyProps"; +import { formatCommaSeparatedList } from '../../../utils/FormattingUtils'; import StyledRadioButton from '../elements/StyledRadioButton'; import MatrixClientContext from "../../../contexts/MatrixClientContext"; import ErrorDialog from '../dialogs/ErrorDialog'; diff --git a/src/components/views/messages/MessageEvent.tsx b/src/components/views/messages/MessageEvent.tsx index 2cd23779d3..c40c9ff2a0 100644 --- a/src/components/views/messages/MessageEvent.tsx +++ b/src/components/views/messages/MessageEvent.tsx @@ -17,6 +17,7 @@ limitations under the License. import React, { createRef } from 'react'; import { EventType, MsgType } from "matrix-js-sdk/src/@types/event"; import { Relations } from 'matrix-js-sdk/src/models/relations'; +import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; import * as sdk from '../../../index'; import SettingsStore from "../../../settings/SettingsStore"; @@ -29,7 +30,6 @@ import { IOperableEventTile } from "../context_menus/MessageContextMenu"; import { MediaEventHelper } from "../../../utils/MediaEventHelper"; import { ReactAnyComponent } from "../../../@types/common"; import { IBodyProps } from "./IBodyProps"; -import { POLL_START_EVENT_TYPE } from '../../../polls/consts'; // onMessageAllowed is handled internally interface IProps extends Omit { diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index 88a2682c90..2db9b311ea 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -24,6 +24,7 @@ import { RoomMember } from "matrix-js-sdk/src/models/room-member"; import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread'; import { logger } from "matrix-js-sdk/src/logger"; import { NotificationCountType } from 'matrix-js-sdk/src/models/room'; +import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; import ReplyChain from "../elements/ReplyChain"; import { _t } from '../../../languageHandler'; @@ -65,7 +66,6 @@ import { MessagePreviewStore } from '../../../stores/room-list/MessagePreviewSto import { TimelineRenderingType } from "../../../contexts/RoomContext"; import { MediaEventHelper } from "../../../utils/MediaEventHelper"; import Toolbar from '../../../accessibility/Toolbar'; -import { POLL_START_EVENT_TYPE } from '../../../polls/consts'; import { RovingAccessibleTooltipButton } from '../../../accessibility/roving/RovingAccessibleTooltipButton'; import { RovingThreadListContextMenu } from '../context_menus/ThreadListContextMenu'; import { ThreadNotificationState } from '../../../stores/notifications/ThreadNotificationState'; diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 7af913763b..3698f87d2e 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -21,6 +21,7 @@ import { RoomMember } from "matrix-js-sdk/src/models/room-member"; import { RelationType } from 'matrix-js-sdk/src/@types/event'; import { MsgType } from "matrix-js-sdk/src/@types/event"; import { logger } from "matrix-js-sdk/src/logger"; +import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; import { _t } from '../../../languageHandler'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; @@ -56,7 +57,6 @@ import LocationPicker from '../location/LocationPicker'; import UIStore, { UI_EVENTS } from '../../../stores/UIStore'; import Modal from "../../../Modal"; import RoomContext from '../../../contexts/RoomContext'; -import { POLL_START_EVENT_TYPE } from "../../../polls/consts"; import ErrorDialog from "../dialogs/ErrorDialog"; import PollCreateDialog from "../elements/PollCreateDialog"; import LocationShareType from "../location/LocationShareType"; diff --git a/src/polls/consts.ts b/src/polls/consts.ts deleted file mode 100644 index dfb56c0fe8..0000000000 --- a/src/polls/consts.ts +++ /dev/null @@ -1,78 +0,0 @@ -/* -Copyright 2021 The Matrix.org Foundation C.I.C. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -import { UnstableValue } from "matrix-js-sdk/src/NamespacedValue"; -import { IContent } from "matrix-js-sdk/src/models/event"; - -export const POLL_START_EVENT_TYPE = new UnstableValue("m.poll.start", "org.matrix.msc3381.poll.start"); -export const POLL_RESPONSE_EVENT_TYPE = new UnstableValue("m.poll.response", "org.matrix.msc3381.poll.response"); -export const POLL_END_EVENT_TYPE = new UnstableValue("m.poll.end", "org.matrix.msc3381.poll.end"); -export const POLL_KIND_DISCLOSED = new UnstableValue("m.poll.disclosed", "org.matrix.msc3381.poll.disclosed"); -export const POLL_KIND_UNDISCLOSED = new UnstableValue("m.poll.undisclosed", "org.matrix.msc3381.poll.undisclosed"); - -// TODO: [TravisR] Use extensible events library when ready -export const TEXT_NODE_TYPE = new UnstableValue("m.text", "org.matrix.msc1767.text"); - -export interface IPollAnswer extends IContent { - id: string; - [TEXT_NODE_TYPE.name]: string; -} - -export interface IPollContent extends IContent { - [POLL_START_EVENT_TYPE.name]: { - kind: string; // disclosed or undisclosed (untypeable for now) - question: { - [TEXT_NODE_TYPE.name]: string; - }; - answers: IPollAnswer[]; - }; - [TEXT_NODE_TYPE.name]: string; -} - -export interface IPollResponseContent extends IContent { - [POLL_RESPONSE_EVENT_TYPE.name]: { - answers: string[]; - }; - "m.relates_to": { - "event_id": string; - "rel_type": string; - }; -} - -export interface IPollEndContent extends IContent { - [POLL_END_EVENT_TYPE.name]: {}; - "m.relates_to": { - "event_id": string; - "rel_type": string; - }; -} - -export function makePollContent(question: string, answers: string[], kind: string): IPollContent { - question = question.trim(); - answers = answers.map(a => a.trim()).filter(a => !!a); - return { - [TEXT_NODE_TYPE.name]: `${question}\n${answers.map((a, i) => `${i + 1}. ${a}`).join('\n')}`, - [POLL_START_EVENT_TYPE.name]: { - kind: kind, - question: { - [TEXT_NODE_TYPE.name]: question, - }, - answers: answers.map( - (a, i) => ({ id: `${i}-${a}`, [TEXT_NODE_TYPE.name]: a }), - ), - }, - }; -} diff --git a/src/stores/room-list/MessagePreviewStore.ts b/src/stores/room-list/MessagePreviewStore.ts index 45e98dc33f..edf7b3cc31 100644 --- a/src/stores/room-list/MessagePreviewStore.ts +++ b/src/stores/room-list/MessagePreviewStore.ts @@ -17,6 +17,7 @@ limitations under the License. import { Room } from "matrix-js-sdk/src/models/room"; import { isNullOrUndefined } from "matrix-js-sdk/src/utils"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; import { ActionPayload } from "../../dispatcher/payloads"; import { AsyncStoreWithClient } from "../AsyncStoreWithClient"; @@ -30,7 +31,6 @@ import { CallHangupEvent } from "./previews/CallHangupEvent"; import { StickerEventPreview } from "./previews/StickerEventPreview"; import { ReactionEventPreview } from "./previews/ReactionEventPreview"; import { UPDATE_EVENT } from "../AsyncStore"; -import { POLL_START_EVENT_TYPE } from "../../polls/consts"; import SettingsStore from "../../settings/SettingsStore"; // Emitted event for when a room's preview has changed. First argument will the room for which diff --git a/src/stores/room-list/previews/PollStartEventPreview.ts b/src/stores/room-list/previews/PollStartEventPreview.ts index ff78258d3b..b473916bf8 100644 --- a/src/stores/room-list/previews/PollStartEventPreview.ts +++ b/src/stores/room-list/previews/PollStartEventPreview.ts @@ -15,12 +15,13 @@ limitations under the License. */ import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; +import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events"; import { IPreview } from "./IPreview"; import { TagID } from "../models"; import { _t, sanitizeForTranslation } from "../../../languageHandler"; import { getSenderName, isSelf, shouldPrefixMessagesIn } from "./utils"; -import { POLL_START_EVENT_TYPE, TEXT_NODE_TYPE } from "../../../polls/consts"; import MatrixClientContext from "../../../contexts/MatrixClientContext"; export class PollStartEventPreview implements IPreview { diff --git a/src/utils/EventUtils.ts b/src/utils/EventUtils.ts index a2773ab044..5a7332301b 100644 --- a/src/utils/EventUtils.ts +++ b/src/utils/EventUtils.ts @@ -19,12 +19,12 @@ import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event import { MatrixClient } from 'matrix-js-sdk/src/client'; import { Thread } from 'matrix-js-sdk/src/models/thread'; import { logger } from 'matrix-js-sdk/src/logger'; +import { POLL_START_EVENT_TYPE } from "matrix-js-sdk/src/@types/polls"; import { MatrixClientPeg } from '../MatrixClientPeg'; import shouldHideEvent from "../shouldHideEvent"; import { getHandlerTile, haveTileForEvent } from "../components/views/rooms/EventTile"; import SettingsStore from "../settings/SettingsStore"; -import { POLL_START_EVENT_TYPE } from '../polls/consts'; /** * Returns whether an event should allow actions like reply, reactions, edit, etc. diff --git a/test/components/views/messages/MPollBody-test.tsx b/test/components/views/messages/MPollBody-test.tsx index ff62c26c71..fa8f123930 100644 --- a/test/components/views/messages/MPollBody-test.tsx +++ b/test/components/views/messages/MPollBody-test.tsx @@ -19,16 +19,16 @@ import { mount, ReactWrapper } from "enzyme"; import { Callback, IContent, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk"; import { ISendEventResponse } from "matrix-js-sdk/src/@types/requests"; import { Relations } from "matrix-js-sdk/src/models/relations"; - -import * as TestUtils from "../../../test-utils"; -import sdk from "../../../skinned-sdk"; import { IPollAnswer, IPollContent, POLL_END_EVENT_TYPE, POLL_RESPONSE_EVENT_TYPE, - TEXT_NODE_TYPE, -} from "../../../../src/polls/consts"; +} from "matrix-js-sdk/src/@types/polls"; +import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events"; + +import * as TestUtils from "../../../test-utils"; +import sdk from "../../../skinned-sdk"; import { UserVote, allVotes, diff --git a/test/stores/room-list/previews/PollStartEventPreview-test.ts b/test/stores/room-list/previews/PollStartEventPreview-test.ts index d1df55685a..ed4e8cb8f1 100644 --- a/test/stores/room-list/previews/PollStartEventPreview-test.ts +++ b/test/stores/room-list/previews/PollStartEventPreview-test.ts @@ -15,8 +15,8 @@ limitations under the License. */ import { MatrixEvent } from "matrix-js-sdk"; +import { IPollAnswer } from "matrix-js-sdk/src/@types/polls"; -import { IPollAnswer } from "../../../../src/polls/consts"; import { PollStartEventPreview } from "../../../../src/stores/room-list/previews/PollStartEventPreview"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";