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

@ -15,7 +15,7 @@ limitations under the License.
*/
import { MatrixEvent } from "matrix-js-sdk";
import { IPollAnswer } from "matrix-js-sdk/src/@types/polls";
import { POLL_ANSWER, M_TEXT, M_POLL_KIND_DISCLOSED, M_POLL_START } from "matrix-events-sdk";
import { PollStartEventPreview } from "../../../../src/stores/room-list/previews/PollStartEventPreview";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
@ -41,12 +41,12 @@ describe("PollStartEventPreview", () => {
function newPollStartEvent(
question: string,
sender: string,
answers?: IPollAnswer[],
answers?: POLL_ANSWER[],
): MatrixEvent {
if (!answers) {
answers = [
{ "id": "socks", "org.matrix.msc1767.text": "Socks" },
{ "id": "shoes", "org.matrix.msc1767.text": "Shoes" },
{ "id": "socks", [M_TEXT.name]: "Socks" },
{ "id": "shoes", [M_TEXT.name]: "Shoes" },
];
}
@ -55,15 +55,16 @@ function newPollStartEvent(
"event_id": "$mypoll",
"room_id": "#myroom:example.com",
"sender": sender,
"type": M_POLL_START.name,
"content": {
"org.matrix.msc3381.poll.start": {
[M_POLL_START.name]: {
"question": {
"org.matrix.msc1767.text": question,
[M_TEXT.name]: question,
},
"kind": "org.matrix.msc3381.poll.disclosed",
"kind": M_POLL_KIND_DISCLOSED.name,
"answers": answers,
},
"org.matrix.msc1767.text": `${question}: answers`,
[M_TEXT.name]: `${question}: answers`,
},
},
);