Move all polls processing to events-sdk & prep for stable polls (#7517)

* Move all polls processing to events-sdk

This makes polls support the full range of extensible events (both parsing and generation).

* Appease the linter

* Fix & update tests

* Update events-sdk for polls bugfix

* Update events-sdk for typechecking

* Add missing type cast

* Update per review
This commit is contained in:
Travis Ralston 2022-01-17 10:06:30 -07:00 committed by GitHub
parent 12e967a97c
commit 65987e6b72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 727 additions and 299 deletions

View file

@ -18,8 +18,7 @@ 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 { PollEndEvent } from "matrix-events-sdk";
import { _t } from "../../../languageHandler";
import { IDialogProps } from "./IDialogProps";
@ -57,17 +56,10 @@ export default class EndPollDialog extends React.Component<IProps> {
);
if (endPoll) {
const endContent: IPollEndContent = {
[POLL_END_EVENT_TYPE.name]: {},
"m.relates_to": {
"event_id": this.props.event.getId(),
"rel_type": "m.reference",
},
[TEXT_NODE_TYPE.name]: message,
};
const endEvent = PollEndEvent.from(this.props.event.getId(), message).serialize();
this.props.matrixClient.sendEvent(
this.props.event.getRoomId(), POLL_END_EVENT_TYPE.name, endContent,
this.props.event.getRoomId(), endEvent.type, endEvent.content,
).catch((e: any) => {
console.error("Failed to submit poll response event:", e);
Modal.createTrackedDialog(