Use js-sdk imports for poll event types instead of events-sdk (#9904)

* Use js-sdk imports for poll event types instead of events-sdk

* Attempt to appease some tsc --strict errors

* Manually create poll response in cypress test
This commit is contained in:
Travis Ralston 2023-01-13 10:02:33 -07:00 committed by GitHub
parent 6052db1e8a
commit badb2c4b27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 69 additions and 71 deletions

View file

@ -16,8 +16,6 @@ limitations under the License.
/// <reference types="cypress" /> /// <reference types="cypress" />
import { PollResponseEvent } from "matrix-events-sdk";
import { HomeserverInstance } from "../../plugins/utils/homeserver"; import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { MatrixClient } from "../../global"; import { MatrixClient } from "../../global";
import Chainable = Cypress.Chainable; import Chainable = Cypress.Chainable;
@ -70,8 +68,16 @@ describe("Polls", () => {
cy.get('input[type="radio"]') cy.get('input[type="radio"]')
.invoke("attr", "value") .invoke("attr", "value")
.then((optionId) => { .then((optionId) => {
const pollVote = PollResponseEvent.from([optionId], pollId).serialize(); // We can't use the js-sdk types for this stuff directly, so manually construct the event.
bot.sendEvent(roomId, pollVote.type, pollVote.content); bot.sendEvent(roomId, "org.matrix.msc3381.poll.response", {
"m.relates_to": {
rel_type: "m.reference",
event_id: pollId,
},
"org.matrix.msc3381.poll.response": {
answers: [optionId],
},
});
}); });
}); });
}; };

View file

@ -20,7 +20,8 @@ import { logger } from "matrix-js-sdk/src/logger";
import { removeDirectionOverrideChars } from "matrix-js-sdk/src/utils"; import { removeDirectionOverrideChars } from "matrix-js-sdk/src/utils";
import { GuestAccess, HistoryVisibility, JoinRule } from "matrix-js-sdk/src/@types/partials"; import { GuestAccess, HistoryVisibility, JoinRule } from "matrix-js-sdk/src/@types/partials";
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event"; import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
import { M_POLL_START, M_POLL_END, PollStartEvent } from "matrix-events-sdk"; import { M_POLL_START, M_POLL_END } from "matrix-js-sdk/src/@types/polls";
import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
import { _t } from "./languageHandler"; import { _t } from "./languageHandler";
import * as Roles from "./Roles"; import * as Roles from "./Roles";

View file

@ -21,7 +21,7 @@ import { EventStatus, MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType, RelationType } from "matrix-js-sdk/src/@types/event"; import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
import { Relations } from "matrix-js-sdk/src/models/relations"; import { Relations } from "matrix-js-sdk/src/models/relations";
import { RoomMemberEvent } from "matrix-js-sdk/src/models/room-member"; import { RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
import { M_POLL_START } from "matrix-events-sdk"; import { M_POLL_START } from "matrix-js-sdk/src/@types/polls";
import { Thread } from "matrix-js-sdk/src/models/thread"; import { Thread } from "matrix-js-sdk/src/models/thread";
import { MatrixClientPeg } from "../../../MatrixClientPeg"; import { MatrixClientPeg } from "../../../MatrixClientPeg";

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from "react"; import React from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MatrixClient } from "matrix-js-sdk/src/client"; import { MatrixClient } from "matrix-js-sdk/src/client";
import { PollEndEvent } from "matrix-events-sdk"; import { PollEndEvent } from "matrix-js-sdk/src/extensible_events_v1/PollEndEvent";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
import { IDialogProps } from "./IDialogProps"; import { IDialogProps } from "./IDialogProps";

View file

@ -17,14 +17,14 @@ limitations under the License.
import React, { ChangeEvent, createRef } from "react"; import React, { ChangeEvent, createRef } from "react";
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { import {
IPartialEvent, KnownPollKind,
KNOWN_POLL_KIND,
M_POLL_KIND_DISCLOSED, M_POLL_KIND_DISCLOSED,
M_POLL_KIND_UNDISCLOSED, M_POLL_KIND_UNDISCLOSED,
M_POLL_START, M_POLL_START,
PollStartEvent, } from "matrix-js-sdk/src/@types/polls";
} from "matrix-events-sdk"; import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { IPartialEvent } from "matrix-js-sdk/src/@types/extensible_events";
import ScrollableBaseModal, { IScrollableBaseState } from "../dialogs/ScrollableBaseModal"; import ScrollableBaseModal, { IScrollableBaseState } from "../dialogs/ScrollableBaseModal";
import { IDialogProps } from "../dialogs/IDialogProps"; import { IDialogProps } from "../dialogs/IDialogProps";
@ -51,7 +51,7 @@ interface IState extends IScrollableBaseState {
question: string; question: string;
options: string[]; options: string[];
busy: boolean; busy: boolean;
kind: KNOWN_POLL_KIND; kind: KnownPollKind;
autoFocusTarget: FocusTarget; autoFocusTarget: FocusTarget;
} }
@ -263,7 +263,7 @@ export default class PollCreateDialog extends ScrollableBaseModal<IProps, IState
}; };
} }
function pollTypeNotes(kind: KNOWN_POLL_KIND): string { function pollTypeNotes(kind: KnownPollKind): string {
if (M_POLL_KIND_DISCLOSED.matches(kind.name)) { if (M_POLL_KIND_DISCLOSED.matches(kind.name)) {
return _t("Voters see results as soon as they have voted"); return _t("Voters see results as soon as they have voted");
} else { } else {

View file

@ -20,17 +20,11 @@ import { logger } from "matrix-js-sdk/src/logger";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { Relations, RelationsEvent } from "matrix-js-sdk/src/models/relations"; import { Relations, RelationsEvent } from "matrix-js-sdk/src/models/relations";
import { MatrixClient } from "matrix-js-sdk/src/matrix"; import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { import { M_POLL_END, M_POLL_KIND_DISCLOSED, M_POLL_RESPONSE, M_POLL_START } from "matrix-js-sdk/src/@types/polls";
M_POLL_END,
M_POLL_KIND_DISCLOSED,
M_POLL_RESPONSE,
M_POLL_START,
NamespacedValue,
PollAnswerSubevent,
PollResponseEvent,
PollStartEvent,
} from "matrix-events-sdk";
import { RelatedRelations } from "matrix-js-sdk/src/models/related-relations"; import { RelatedRelations } from "matrix-js-sdk/src/models/related-relations";
import { NamespacedValue } from "matrix-events-sdk";
import { PollStartEvent, PollAnswerSubevent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
import { PollResponseEvent } from "matrix-js-sdk/src/extensible_events_v1/PollResponseEvent";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
import Modal from "../../../Modal"; import Modal from "../../../Modal";

View file

@ -18,7 +18,7 @@ import React, { createRef } from "react";
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event"; import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon"; import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
import { M_LOCATION } from "matrix-js-sdk/src/@types/location"; import { M_LOCATION } from "matrix-js-sdk/src/@types/location";
import { M_POLL_START } from "matrix-events-sdk"; import { M_POLL_START } from "matrix-js-sdk/src/@types/polls";
import { MatrixEventEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import SettingsStore from "../../../settings/SettingsStore"; import SettingsStore from "../../../settings/SettingsStore";

View file

@ -16,7 +16,7 @@ limitations under the License.
import classNames from "classnames"; import classNames from "classnames";
import { IEventRelation } from "matrix-js-sdk/src/models/event"; import { IEventRelation } from "matrix-js-sdk/src/models/event";
import { M_POLL_START } from "matrix-events-sdk"; import { M_POLL_START } from "matrix-js-sdk/src/@types/polls";
import React, { createContext, MouseEventHandler, ReactElement, useContext, useRef } from "react"; import React, { createContext, MouseEventHandler, ReactElement, useContext, useRef } from "react";
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixClient } from "matrix-js-sdk/src/client"; import { MatrixClient } from "matrix-js-sdk/src/client";

View file

@ -20,7 +20,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Relations } from "matrix-js-sdk/src/models/relations"; import { Relations } from "matrix-js-sdk/src/models/relations";
import { EventType, RelationType } from "matrix-js-sdk/src/@types/event"; import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { M_POLL_START, M_POLL_RESPONSE, M_POLL_END } from "matrix-events-sdk"; import { M_POLL_START, M_POLL_RESPONSE, M_POLL_END } from "matrix-js-sdk/src/@types/polls";
import dis from "../../../dispatcher/dispatcher"; import dis from "../../../dispatcher/dispatcher";
import { Action } from "../../../dispatcher/actions"; import { Action } from "../../../dispatcher/actions";

View file

@ -17,7 +17,8 @@ limitations under the License.
import React from "react"; import React from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event"; import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
import { M_POLL_START, Optional } from "matrix-events-sdk"; import { Optional } from "matrix-events-sdk";
import { M_POLL_START } from "matrix-js-sdk/src/@types/polls";
import { MatrixClient } from "matrix-js-sdk/src/client"; import { MatrixClient } from "matrix-js-sdk/src/client";
import { GroupCallIntent } from "matrix-js-sdk/src/webrtc/groupCall"; import { GroupCallIntent } from "matrix-js-sdk/src/webrtc/groupCall";

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { M_POLL_START } from "matrix-events-sdk"; import { M_POLL_START } from "matrix-js-sdk/src/@types/polls";
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon"; import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
import { MatrixEvent, MatrixClient } from "matrix-js-sdk/src/matrix"; import { MatrixEvent, MatrixClient } from "matrix-js-sdk/src/matrix";

View file

@ -17,7 +17,7 @@ limitations under the License.
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { isNullOrUndefined } from "matrix-js-sdk/src/utils"; import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { M_POLL_START } from "matrix-events-sdk"; import { M_POLL_START } from "matrix-js-sdk/src/@types/polls";
import { ActionPayload } from "../../dispatcher/payloads"; import { ActionPayload } from "../../dispatcher/payloads";
import { AsyncStoreWithClient } from "../AsyncStoreWithClient"; import { AsyncStoreWithClient } from "../AsyncStoreWithClient";

View file

@ -15,7 +15,9 @@ limitations under the License.
*/ */
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { InvalidEventError, M_POLL_START_EVENT_CONTENT, PollStartEvent } from "matrix-events-sdk"; import { PollStartEventContent } from "matrix-js-sdk/src/@types/polls";
import { InvalidEventError } from "matrix-js-sdk/src/extensible_events_v1/InvalidEventError";
import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
import { IPreview } from "./IPreview"; import { IPreview } from "./IPreview";
import { TagID } from "../models"; import { TagID } from "../models";
@ -43,7 +45,7 @@ export class PollStartEventPreview implements IPreview {
try { try {
const poll = new PollStartEvent({ const poll = new PollStartEvent({
type: event.getType(), type: event.getType(),
content: eventContent as M_POLL_START_EVENT_CONTENT, content: eventContent as PollStartEventContent,
}); });
let question = poll.question.text.trim(); let question = poll.question.text.trim();

View file

@ -16,7 +16,7 @@ limitations under the License.
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event"; import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
import { M_POLL_START } from "matrix-events-sdk"; import { M_POLL_START } from "matrix-js-sdk/src/@types/polls";
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon"; import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
import { IContent } from "matrix-js-sdk/src/matrix"; import { IContent } from "matrix-js-sdk/src/matrix";

View file

@ -18,7 +18,7 @@ import { EventStatus, MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType, EVENT_VISIBILITY_CHANGE_TYPE, MsgType, RelationType } from "matrix-js-sdk/src/@types/event"; import { EventType, EVENT_VISIBILITY_CHANGE_TYPE, MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
import { MatrixClient } from "matrix-js-sdk/src/client"; import { MatrixClient } from "matrix-js-sdk/src/client";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { M_POLL_START } from "matrix-events-sdk"; import { M_POLL_START } from "matrix-js-sdk/src/@types/polls";
import { M_LOCATION } from "matrix-js-sdk/src/@types/location"; import { M_LOCATION } from "matrix-js-sdk/src/@types/location";
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon"; import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";

View file

@ -16,7 +16,7 @@ limitations under the License.
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType } from "matrix-js-sdk/src/@types/event"; import { EventType } from "matrix-js-sdk/src/@types/event";
import { M_POLL_START } from "matrix-events-sdk"; import { M_POLL_START } from "matrix-js-sdk/src/@types/polls";
export default class PinningUtils { export default class PinningUtils {
/** /**

View file

@ -26,7 +26,8 @@ import {
getBeaconInfoIdentifier, getBeaconInfoIdentifier,
EventType, EventType,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { M_POLL_KIND_DISCLOSED, PollStartEvent } from "matrix-events-sdk"; import { M_POLL_KIND_DISCLOSED } from "matrix-js-sdk/src/@types/polls";
import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
import { FeatureSupport, Thread } from "matrix-js-sdk/src/models/thread"; import { FeatureSupport, Thread } from "matrix-js-sdk/src/models/thread";
import { mocked } from "jest-mock"; import { mocked } from "jest-mock";
import { act } from "@testing-library/react"; import { act } from "@testing-library/react";

View file

@ -18,7 +18,7 @@ import React from "react";
import { act } from "react-dom/test-utils"; import { act } from "react-dom/test-utils";
import { MatrixEvent, EventType } from "matrix-js-sdk/src/matrix"; import { MatrixEvent, EventType } from "matrix-js-sdk/src/matrix";
import { LocationAssetType, M_ASSET, M_LOCATION, M_TIMESTAMP } from "matrix-js-sdk/src/@types/location"; import { LocationAssetType, M_ASSET, M_LOCATION, M_TIMESTAMP } from "matrix-js-sdk/src/@types/location";
import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events"; import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
import { fireEvent, getByTestId, render, RenderResult, screen } from "@testing-library/react"; import { fireEvent, getByTestId, render, RenderResult, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event"; import userEvent from "@testing-library/user-event";
@ -248,7 +248,7 @@ describe("ForwardDialog", () => {
const expectedStrippedContent = { const expectedStrippedContent = {
...modernLocationEvent.getContent(), ...modernLocationEvent.getContent(),
body: text, body: text,
[TEXT_NODE_TYPE.name]: text, [M_TEXT.name]: text,
[M_TIMESTAMP.name]: now, [M_TIMESTAMP.name]: now,
[M_ASSET.name]: { type: LocationAssetType.Pin }, [M_ASSET.name]: { type: LocationAssetType.Pin },
[M_LOCATION.name]: { [M_LOCATION.name]: {
@ -276,7 +276,7 @@ describe("ForwardDialog", () => {
const expectedStrippedContent = { const expectedStrippedContent = {
...modernLocationEvent.getContent(), ...modernLocationEvent.getContent(),
body: text, body: text,
[TEXT_NODE_TYPE.name]: text, [M_TEXT.name]: text,
[M_ASSET.name]: { type: LocationAssetType.Pin }, [M_ASSET.name]: { type: LocationAssetType.Pin },
[M_LOCATION.name]: { [M_LOCATION.name]: {
uri: geoUri, uri: geoUri,
@ -297,7 +297,7 @@ describe("ForwardDialog", () => {
const expectedContent = { const expectedContent = {
msgtype: "m.location", msgtype: "m.location",
body: text, body: text,
[TEXT_NODE_TYPE.name]: text, [M_TEXT.name]: text,
[M_ASSET.name]: { type: LocationAssetType.Pin }, [M_ASSET.name]: { type: LocationAssetType.Pin },
[M_LOCATION.name]: { [M_LOCATION.name]: {
uri: geoUri, uri: geoUri,

View file

@ -18,14 +18,10 @@ import React from "react";
// eslint-disable-next-line deprecate/import // eslint-disable-next-line deprecate/import
import { mount, ReactWrapper } from "enzyme"; import { mount, ReactWrapper } from "enzyme";
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { import { M_POLL_KIND_DISCLOSED, M_POLL_KIND_UNDISCLOSED, M_POLL_START } from "matrix-js-sdk/src/@types/polls";
M_POLL_KIND_DISCLOSED, import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
M_POLL_KIND_UNDISCLOSED,
M_POLL_START,
M_TEXT,
PollStartEvent,
} from "matrix-events-sdk";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
import { findById, getMockClientWithEventEmitter } from "../../../test-utils"; import { findById, getMockClientWithEventEmitter } from "../../../test-utils";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";

View file

@ -26,10 +26,10 @@ import {
M_POLL_KIND_UNDISCLOSED, M_POLL_KIND_UNDISCLOSED,
M_POLL_RESPONSE, M_POLL_RESPONSE,
M_POLL_START, M_POLL_START,
M_POLL_START_EVENT_CONTENT, PollStartEventContent,
M_TEXT, PollAnswer,
POLL_ANSWER, } from "matrix-js-sdk/src/@types/polls";
} from "matrix-events-sdk"; import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
import { MockedObject } from "jest-mock"; import { MockedObject } from "jest-mock";
import { import {
@ -440,7 +440,7 @@ describe("MPollBody", () => {
responseEvent("@catrd:example.com", "poutine"), responseEvent("@catrd:example.com", "poutine"),
responseEvent("@dune2:example.com", "wings"), responseEvent("@dune2:example.com", "wings"),
]; ];
const body = newMPollBody(votes, [], null, false); const body = newMPollBody(votes, [], undefined, false);
expect(votesCount(body, "pizza")).toBe(""); expect(votesCount(body, "pizza")).toBe("");
expect(votesCount(body, "poutine")).toBe(""); expect(votesCount(body, "poutine")).toBe("");
expect(votesCount(body, "italian")).toBe(""); expect(votesCount(body, "italian")).toBe("");
@ -456,7 +456,7 @@ describe("MPollBody", () => {
responseEvent("@catrd:example.com", "poutine"), responseEvent("@catrd:example.com", "poutine"),
responseEvent("@dune2:example.com", "wings"), responseEvent("@dune2:example.com", "wings"),
]; ];
const body = newMPollBody(votes, [], null, false); const body = newMPollBody(votes, [], undefined, false);
// My vote is marked // My vote is marked
expect(body.find('input[value="pizza"]').prop("checked")).toBeTruthy(); expect(body.find('input[value="pizza"]').prop("checked")).toBeTruthy();
@ -474,7 +474,7 @@ describe("MPollBody", () => {
responseEvent("@dune2:example.com", "wings"), responseEvent("@dune2:example.com", "wings"),
]; ];
const ends = [endEvent("@me:example.com", 12)]; const ends = [endEvent("@me:example.com", 12)];
const body = newMPollBody(votes, ends, null, false); const body = newMPollBody(votes, ends, undefined, false);
expect(endedVotesCount(body, "pizza")).toBe("3 votes"); expect(endedVotesCount(body, "pizza")).toBe("3 votes");
expect(endedVotesCount(body, "poutine")).toBe("1 vote"); expect(endedVotesCount(body, "poutine")).toBe("1 vote");
expect(endedVotesCount(body, "italian")).toBe("0 votes"); expect(endedVotesCount(body, "italian")).toBe("0 votes");
@ -913,7 +913,7 @@ describe("MPollBody", () => {
responseEvent("@yh:example.com", "poutine", 14), responseEvent("@yh:example.com", "poutine", 14),
]; ];
const ends = []; const ends = [];
const body = newMPollBody(votes, ends, null, false); const body = newMPollBody(votes, ends, undefined, false);
expect(body.html()).toMatchSnapshot(); expect(body.html()).toMatchSnapshot();
}); });
@ -927,7 +927,7 @@ describe("MPollBody", () => {
responseEvent("@yh:example.com", "poutine", 14), responseEvent("@yh:example.com", "poutine", 14),
]; ];
const ends = [endEvent("@me:example.com", 25)]; const ends = [endEvent("@me:example.com", 25)];
const body = newMPollBody(votes, ends, null, false); const body = newMPollBody(votes, ends, undefined, false);
expect(body.html()).toMatchSnapshot(); expect(body.html()).toMatchSnapshot();
}); });
}); });
@ -951,7 +951,7 @@ function newRelations(relationEvents: Array<MatrixEvent>, eventType: string): Re
function newMPollBody( function newMPollBody(
relationEvents: Array<MatrixEvent>, relationEvents: Array<MatrixEvent>,
endEvents: Array<MatrixEvent> = [], endEvents: Array<MatrixEvent> = [],
answers?: POLL_ANSWER[], answers?: PollAnswer[],
disclosed = true, disclosed = true,
): ReactWrapper { ): ReactWrapper {
const mxEvent = new MatrixEvent({ const mxEvent = new MatrixEvent({
@ -1033,7 +1033,7 @@ function endedVotesCount(wrapper: ReactWrapper, value: string): string {
return wrapper.find(`div[data-value="${value}"] .mx_MPollBody_optionVoteCount`).text(); return wrapper.find(`div[data-value="${value}"] .mx_MPollBody_optionVoteCount`).text();
} }
function newPollStart(answers?: POLL_ANSWER[], question?: string, disclosed = true): M_POLL_START_EVENT_CONTENT { function newPollStart(answers?: PollAnswer[], question?: string, disclosed = true): PollStartEventContent {
if (!answers) { if (!answers) {
answers = [ answers = [
{ id: "pizza", [M_TEXT.name]: "Pizza" }, { id: "pizza", [M_TEXT.name]: "Pizza" },
@ -1047,7 +1047,7 @@ function newPollStart(answers?: POLL_ANSWER[], question?: string, disclosed = tr
question = "What should we order for the party?"; question = "What should we order for the party?";
} }
const answersFallback = answers.map((a, i) => `${i + 1}. ${a[M_TEXT.name]}`).join("\n"); const answersFallback = answers.map((a, i) => `${i + 1}. ${M_TEXT.findIn<string>(a)}`).join("\n");
const fallback = `${question}\n${answersFallback}`; const fallback = `${question}\n${answersFallback}`;

View file

@ -23,14 +23,10 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType, RelationType, MsgType } from "matrix-js-sdk/src/@types/event"; import { EventType, RelationType, MsgType } from "matrix-js-sdk/src/@types/event";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state"; import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { IEvent, Room, EventTimelineSet, IMinimalEvent } from "matrix-js-sdk/src/matrix"; import { IEvent, Room, EventTimelineSet, IMinimalEvent } from "matrix-js-sdk/src/matrix";
import { import { M_POLL_RESPONSE, M_POLL_END, M_POLL_KIND_DISCLOSED } from "matrix-js-sdk/src/@types/polls";
M_POLL_RESPONSE, import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
M_POLL_END, import { PollResponseEvent } from "matrix-js-sdk/src/extensible_events_v1/PollResponseEvent";
M_POLL_KIND_DISCLOSED, import { PollEndEvent } from "matrix-js-sdk/src/extensible_events_v1/PollEndEvent";
PollStartEvent,
PollResponseEvent,
PollEndEvent,
} from "matrix-events-sdk";
import { stubClient, mkStubRoom, mkEvent, mkMessage } from "../../../test-utils"; import { stubClient, mkStubRoom, mkEvent, mkMessage } from "../../../test-utils";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";

View file

@ -15,9 +15,10 @@ limitations under the License.
*/ */
import { MatrixEvent } from "matrix-js-sdk/src/matrix"; import { MatrixEvent } from "matrix-js-sdk/src/matrix";
import { M_TEXT, M_POLL_START, POLL_ANSWER, M_POLL_KIND_DISCLOSED } from "matrix-events-sdk"; import { M_POLL_START, PollAnswer, M_POLL_KIND_DISCLOSED } from "matrix-js-sdk/src/@types/polls";
import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
export const makePollStartEvent = (question: string, sender: string, answers?: POLL_ANSWER[]): MatrixEvent => { export const makePollStartEvent = (question: string, sender: string, answers?: PollAnswer[]): MatrixEvent => {
if (!answers) { if (!answers) {
answers = [ answers = [
{ id: "socks", [M_TEXT.name]: "Socks" }, { id: "socks", [M_TEXT.name]: "Socks" },

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events"; import { M_TEXT } from "matrix-js-sdk/src/@types/extensible_events";
import { import {
ILocationContent, ILocationContent,
LocationAssetType, LocationAssetType,
@ -38,7 +38,7 @@ describe("isSelfLocation", () => {
msgtype: "m.location", msgtype: "m.location",
geo_uri: "", geo_uri: "",
[M_LOCATION.name]: { uri: "" }, [M_LOCATION.name]: { uri: "" },
[TEXT_NODE_TYPE.name]: "", [M_TEXT.name]: "",
[M_TIMESTAMP.name]: 0, [M_TIMESTAMP.name]: 0,
// Note: no m.asset! // Note: no m.asset!
}; };
@ -51,7 +51,7 @@ describe("isSelfLocation", () => {
msgtype: "m.location", msgtype: "m.location",
geo_uri: "", geo_uri: "",
[M_LOCATION.name]: { uri: "" }, [M_LOCATION.name]: { uri: "" },
[TEXT_NODE_TYPE.name]: "", [M_TEXT.name]: "",
[M_TIMESTAMP.name]: 0, [M_TIMESTAMP.name]: 0,
[M_ASSET.name]: { [M_ASSET.name]: {
// Note: no type! // Note: no type!