events: Make polls events use the stable prefixes

This commit is contained in:
Kévin Commaille 2023-07-05 16:27:02 +02:00 committed by Kévin Commaille
parent df11c6d46a
commit c0b8cd4d46
5 changed files with 101 additions and 104 deletions

View File

@ -68,14 +68,11 @@ event_enum! {
#[ruma_enum(alias = "m.message")] #[ruma_enum(alias = "m.message")]
"org.matrix.msc1767.message" => super::message, "org.matrix.msc1767.message" => super::message,
#[cfg(feature = "unstable-msc3381")] #[cfg(feature = "unstable-msc3381")]
#[ruma_enum(alias = "m.poll.start")] "m.poll.start" => super::poll::start,
"org.matrix.msc3381.v2.poll.start" => super::poll::start,
#[cfg(feature = "unstable-msc3381")] #[cfg(feature = "unstable-msc3381")]
#[ruma_enum(alias = "m.poll.response")] "m.poll.response" => super::poll::response,
"org.matrix.msc3381.v2.poll.response" => super::poll::response,
#[cfg(feature = "unstable-msc3381")] #[cfg(feature = "unstable-msc3381")]
#[ruma_enum(alias = "m.poll.end")] "m.poll.end" => super::poll::end,
"org.matrix.msc3381.v2.poll.end" => super::poll::end,
"m.reaction" => super::reaction, "m.reaction" => super::reaction,
"m.room.encrypted" => super::room::encrypted, "m.room.encrypted" => super::room::encrypted,
"m.room.message" => super::room::message, "m.room.message" => super::room::message,

View File

@ -1,4 +1,4 @@
//! Types for the [`m.poll.end`] event. //! Types for the `m.poll.end` event.
use std::{ use std::{
collections::{btree_map, BTreeMap}, collections::{btree_map, BTreeMap},
@ -22,17 +22,14 @@ use crate::{
/// [`OriginalSyncPollStartEvent::compile_results()`]: super::start::OriginalSyncPollStartEvent::compile_results /// [`OriginalSyncPollStartEvent::compile_results()`]: super::start::OriginalSyncPollStartEvent::compile_results
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)] #[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "org.matrix.msc3381.v2.poll.end", alias = "m.poll.end", kind = MessageLike)] #[ruma_event(type = "m.poll.end", kind = MessageLike)]
pub struct PollEndEventContent { pub struct PollEndEventContent {
/// The text representation of the results. /// The text representation of the results.
#[serde(rename = "org.matrix.msc1767.text")] #[serde(rename = "m.text")]
pub text: TextContentBlock, pub text: TextContentBlock,
/// The sender's perspective of the results. /// The sender's perspective of the results.
#[serde( #[serde(rename = "m.poll.results", skip_serializing_if = "Option::is_none")]
rename = "org.matrix.msc3381.v2.poll.results",
skip_serializing_if = "Option::is_none"
)]
pub poll_results: Option<PollResultsContentBlock>, pub poll_results: Option<PollResultsContentBlock>,
/// Whether this message is automated. /// Whether this message is automated.

View File

@ -1,4 +1,4 @@
//! Types for the [`m.poll.response`] event. //! Types for the `m.poll.response` event.
use std::{ops::Deref, vec}; use std::{ops::Deref, vec};
@ -12,10 +12,10 @@ use super::start::PollContentBlock;
/// The payload for a poll response event. /// The payload for a poll response event.
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)] #[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "org.matrix.msc3381.v2.poll.response", alias = "m.poll.response", kind = MessageLike)] #[ruma_event(type = "m.poll.response", kind = MessageLike)]
pub struct PollResponseEventContent { pub struct PollResponseEventContent {
/// The user's selection. /// The user's selection.
#[serde(rename = "org.matrix.msc3381.v2.selections")] #[serde(rename = "m.selections")]
pub selections: SelectionsContentBlock, pub selections: SelectionsContentBlock,
/// Whether this message is automated. /// Whether this message is automated.

View File

@ -1,4 +1,4 @@
//! Types for the [`m.poll.start`] event. //! Types for the `m.poll.start` event.
use std::ops::Deref; use std::ops::Deref;
@ -21,14 +21,14 @@ use super::{
/// The payload for a poll start event. /// The payload for a poll start event.
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)] #[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "org.matrix.msc3381.v2.poll.start", alias = "m.poll.start", kind = MessageLike)] #[ruma_event(type = "m.poll.start", kind = MessageLike)]
pub struct PollStartEventContent { pub struct PollStartEventContent {
/// The poll content of the message. /// The poll content of the message.
#[serde(rename = "org.matrix.msc3381.v2.poll")] #[serde(rename = "m.poll")]
pub poll: PollContentBlock, pub poll: PollContentBlock,
/// Text representation of the message, for clients that don't support polls. /// Text representation of the message, for clients that don't support polls.
#[serde(rename = "org.matrix.msc1767.text")] #[serde(rename = "m.text")]
pub text: TextContentBlock, pub text: TextContentBlock,
/// Whether this message is automated. /// Whether this message is automated.
@ -184,7 +184,7 @@ impl PollContentBlock {
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct PollQuestion { pub struct PollQuestion {
/// The text representation of the question. /// The text representation of the question.
#[serde(rename = "org.matrix.msc1767.text")] #[serde(rename = "m.text")]
pub text: TextContentBlock, pub text: TextContentBlock,
} }
@ -201,11 +201,11 @@ impl From<TextContentBlock> for PollQuestion {
pub enum PollKind { pub enum PollKind {
/// The results are revealed once the poll is closed. /// The results are revealed once the poll is closed.
#[default] #[default]
#[ruma_enum(rename = "org.matrix.msc3381.v2.undisclosed")] #[ruma_enum(rename = "m.undisclosed")]
Undisclosed, Undisclosed,
/// The votes are visible up until and including when the poll is closed. /// The votes are visible up until and including when the poll is closed.
#[ruma_enum(rename = "org.matrix.msc3381.v2.disclosed")] #[ruma_enum(rename = "m.disclosed")]
Disclosed, Disclosed,
#[doc(hidden)] #[doc(hidden)]
@ -278,11 +278,11 @@ pub struct PollAnswer {
/// The ID of the answer. /// The ID of the answer.
/// ///
/// This must be unique among the answers of a poll. /// This must be unique among the answers of a poll.
#[serde(rename = "org.matrix.msc3381.v2.id")] #[serde(rename = "m.id")]
pub id: String, pub id: String,
/// The text representation of the answer. /// The text representation of the answer.
#[serde(rename = "org.matrix.msc1767.text")] #[serde(rename = "m.text")]
pub text: TextContentBlock, pub text: TextContentBlock,
} }

View File

@ -26,8 +26,8 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
#[test] #[test]
fn poll_answers_deserialization_valid() { fn poll_answers_deserialization_valid() {
let json_data = json!([ let json_data = json!([
{ "org.matrix.msc3381.v2.id": "aaa", "org.matrix.msc1767.text": [{ "body": "First answer" }] }, { "m.id": "aaa", "m.text": [{ "body": "First answer" }] },
{ "org.matrix.msc3381.v2.id": "bbb", "org.matrix.msc1767.text": [{ "body": "Second answer" }] }, { "m.id": "bbb", "m.text": [{ "body": "Second answer" }] },
]); ]);
let answers = from_json_value::<PollAnswers>(json_data).unwrap(); let answers = from_json_value::<PollAnswers>(json_data).unwrap();
@ -37,28 +37,28 @@ fn poll_answers_deserialization_valid() {
#[test] #[test]
fn poll_answers_deserialization_truncate() { fn poll_answers_deserialization_truncate() {
let json_data = json!([ let json_data = json!([
{ "org.matrix.msc3381.v2.id": "aaa", "org.matrix.msc1767.text": [{ "body": "1st answer" }] }, { "m.id": "aaa", "m.text": [{ "body": "1st answer" }] },
{ "org.matrix.msc3381.v2.id": "bbb", "org.matrix.msc1767.text": [{ "body": "2nd answer" }] }, { "m.id": "bbb", "m.text": [{ "body": "2nd answer" }] },
{ "org.matrix.msc3381.v2.id": "ccc", "org.matrix.msc1767.text": [{ "body": "3rd answer" }] }, { "m.id": "ccc", "m.text": [{ "body": "3rd answer" }] },
{ "org.matrix.msc3381.v2.id": "ddd", "org.matrix.msc1767.text": [{ "body": "4th answer" }] }, { "m.id": "ddd", "m.text": [{ "body": "4th answer" }] },
{ "org.matrix.msc3381.v2.id": "eee", "org.matrix.msc1767.text": [{ "body": "5th answer" }] }, { "m.id": "eee", "m.text": [{ "body": "5th answer" }] },
{ "org.matrix.msc3381.v2.id": "fff", "org.matrix.msc1767.text": [{ "body": "6th answer" }] }, { "m.id": "fff", "m.text": [{ "body": "6th answer" }] },
{ "org.matrix.msc3381.v2.id": "ggg", "org.matrix.msc1767.text": [{ "body": "7th answer" }] }, { "m.id": "ggg", "m.text": [{ "body": "7th answer" }] },
{ "org.matrix.msc3381.v2.id": "hhh", "org.matrix.msc1767.text": [{ "body": "8th answer" }] }, { "m.id": "hhh", "m.text": [{ "body": "8th answer" }] },
{ "org.matrix.msc3381.v2.id": "iii", "org.matrix.msc1767.text": [{ "body": "9th answer" }] }, { "m.id": "iii", "m.text": [{ "body": "9th answer" }] },
{ "org.matrix.msc3381.v2.id": "jjj", "org.matrix.msc1767.text": [{ "body": "10th answer" }] }, { "m.id": "jjj", "m.text": [{ "body": "10th answer" }] },
{ "org.matrix.msc3381.v2.id": "kkk", "org.matrix.msc1767.text": [{ "body": "11th answer" }] }, { "m.id": "kkk", "m.text": [{ "body": "11th answer" }] },
{ "org.matrix.msc3381.v2.id": "lll", "org.matrix.msc1767.text": [{ "body": "12th answer" }] }, { "m.id": "lll", "m.text": [{ "body": "12th answer" }] },
{ "org.matrix.msc3381.v2.id": "mmm", "org.matrix.msc1767.text": [{ "body": "13th answer" }] }, { "m.id": "mmm", "m.text": [{ "body": "13th answer" }] },
{ "org.matrix.msc3381.v2.id": "nnn", "org.matrix.msc1767.text": [{ "body": "14th answer" }] }, { "m.id": "nnn", "m.text": [{ "body": "14th answer" }] },
{ "org.matrix.msc3381.v2.id": "ooo", "org.matrix.msc1767.text": [{ "body": "15th answer" }] }, { "m.id": "ooo", "m.text": [{ "body": "15th answer" }] },
{ "org.matrix.msc3381.v2.id": "ppp", "org.matrix.msc1767.text": [{ "body": "16th answer" }] }, { "m.id": "ppp", "m.text": [{ "body": "16th answer" }] },
{ "org.matrix.msc3381.v2.id": "qqq", "org.matrix.msc1767.text": [{ "body": "17th answer" }] }, { "m.id": "qqq", "m.text": [{ "body": "17th answer" }] },
{ "org.matrix.msc3381.v2.id": "rrr", "org.matrix.msc1767.text": [{ "body": "18th answer" }] }, { "m.id": "rrr", "m.text": [{ "body": "18th answer" }] },
{ "org.matrix.msc3381.v2.id": "sss", "org.matrix.msc1767.text": [{ "body": "19th answer" }] }, { "m.id": "sss", "m.text": [{ "body": "19th answer" }] },
{ "org.matrix.msc3381.v2.id": "ttt", "org.matrix.msc1767.text": [{ "body": "20th answer" }] }, { "m.id": "ttt", "m.text": [{ "body": "20th answer" }] },
{ "org.matrix.msc3381.v2.id": "uuu", "org.matrix.msc1767.text": [{ "body": "21th answer" }] }, { "m.id": "uuu", "m.text": [{ "body": "21th answer" }] },
{ "org.matrix.msc3381.v2.id": "vvv", "org.matrix.msc1767.text": [{ "body": "22th answer" }] }, { "m.id": "vvv", "m.text": [{ "body": "22th answer" }] },
]); ]);
let answers = from_json_value::<PollAnswers>(json_data).unwrap(); let answers = from_json_value::<PollAnswers>(json_data).unwrap();
@ -93,15 +93,13 @@ fn start_content_serialization() {
assert_eq!( assert_eq!(
to_json_value(&event_content).unwrap(), to_json_value(&event_content).unwrap(),
json!({ json!({
"org.matrix.msc1767.text": [ "m.text": [{ "body": "How's the weather?\n1. Not bad…\n2. Fine.\n3. Amazing!" }],
{ "body": "How's the weather?\n1. Not bad…\n2. Fine.\n3. Amazing!" } "m.poll": {
], "question": { "m.text": [{ "body": "How's the weather?" }] },
"org.matrix.msc3381.v2.poll": {
"question": { "org.matrix.msc1767.text": [{ "body": "How's the weather?" }] },
"answers": [ "answers": [
{ "org.matrix.msc3381.v2.id": "not-bad", "org.matrix.msc1767.text": [{ "body": "Not bad…" }] }, { "m.id": "not-bad", "m.text": [{ "body": "Not bad…" }] },
{ "org.matrix.msc3381.v2.id": "fine", "org.matrix.msc1767.text": [{ "body": "Fine." }] }, { "m.id": "fine", "m.text": [{ "body": "Fine." }] },
{ "org.matrix.msc3381.v2.id": "amazing", "org.matrix.msc1767.text": [{ "body": "Amazing!" }] }, { "m.id": "amazing", "m.text": [{ "body": "Amazing!" }] },
], ],
}, },
}) })
@ -109,7 +107,7 @@ fn start_content_serialization() {
} }
#[test] #[test]
fn start_event_serialization() { fn start_content_other_serialization() {
let mut poll = PollContentBlock::new( let mut poll = PollContentBlock::new(
TextContentBlock::plain("How's the weather?"), TextContentBlock::plain("How's the weather?"),
vec![ vec![
@ -130,17 +128,15 @@ fn start_event_serialization() {
assert_eq!( assert_eq!(
to_json_value(&content).unwrap(), to_json_value(&content).unwrap(),
json!({ json!({
"org.matrix.msc1767.text": [ "m.text": [{ "body": "How's the weather?\n1. Not bad…\n2. Fine.\n3. Amazing!" }],
{ "body": "How's the weather?\n1. Not bad…\n2. Fine.\n3. Amazing!" } "m.poll": {
], "question": { "m.text": [{ "body": "How's the weather?" }] },
"org.matrix.msc3381.v2.poll": { "kind": "m.disclosed",
"question": { "org.matrix.msc1767.text": [{ "body": "How's the weather?" }] },
"kind": "org.matrix.msc3381.v2.disclosed",
"max_selections": 2, "max_selections": 2,
"answers": [ "answers": [
{ "org.matrix.msc3381.v2.id": "not-bad", "org.matrix.msc1767.text": [{ "body": "Not bad…" }] }, { "m.id": "not-bad", "m.text": [{ "body": "Not bad…" }] },
{ "org.matrix.msc3381.v2.id": "fine", "org.matrix.msc1767.text": [{ "body": "Fine." }] }, { "m.id": "fine", "m.text": [{ "body": "Fine." }] },
{ "org.matrix.msc3381.v2.id": "amazing", "org.matrix.msc1767.text": [{ "body": "Amazing!" }] }, { "m.id": "amazing", "m.text": [{ "body": "Amazing!" }] },
] ]
}, },
}) })
@ -151,16 +147,25 @@ fn start_event_serialization() {
fn start_event_deserialization() { fn start_event_deserialization() {
let json_data = json!({ let json_data = json!({
"content": { "content": {
"org.matrix.msc1767.text": [ "m.text": [
{ "body": "How's the weather?\n1. Not bad…\n2. Fine.\n3. Amazing!" } { "body": "How's the weather?\n1. Not bad…\n2. Fine.\n3. Amazing!" }
], ],
"org.matrix.msc3381.v2.poll": { "m.poll": {
"question": { "org.matrix.msc1767.text": [{ "body": "How's the weather?" }] }, "question": { "m.text": [{ "body": "How's the weather?" }] },
"max_selections": 2, "max_selections": 2,
"answers": [ "answers": [
{ "org.matrix.msc3381.v2.id": "not-bad", "org.matrix.msc1767.text": [{ "body": "Not bad…" }] }, {
{ "org.matrix.msc3381.v2.id": "fine", "org.matrix.msc1767.text": [{ "body": "Fine." }] }, "m.id": "not-bad",
{ "org.matrix.msc3381.v2.id": "amazing", "org.matrix.msc1767.text": [{ "body": "Amazing!" }] }, "m.text": [{ "body": "Not bad…" }],
},
{
"m.id": "fine",
"m.text": [{ "body": "Fine." }],
},
{
"m.id": "amazing",
"m.text": [{ "body": "Amazing!" }],
},
] ]
}, },
}, },
@ -168,7 +173,7 @@ fn start_event_deserialization() {
"origin_server_ts": 134_829_848, "origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs", "room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs", "sender": "@user:notareal.hs",
"type": "org.matrix.msc3381.v2.poll.start", "type": "m.poll.start",
}); });
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(); let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
@ -204,7 +209,7 @@ fn response_content_serialization() {
assert_eq!( assert_eq!(
to_json_value(&event_content).unwrap(), to_json_value(&event_content).unwrap(),
json!({ json!({
"org.matrix.msc3381.v2.selections": ["my-answer"], "m.selections": ["my-answer"],
"m.relates_to": { "m.relates_to": {
"rel_type": "m.reference", "rel_type": "m.reference",
"event_id": "$related_event:notareal.hs", "event_id": "$related_event:notareal.hs",
@ -214,7 +219,7 @@ fn response_content_serialization() {
} }
#[test] #[test]
fn response_event_serialization() { fn response_content_other_serialization() {
let content = PollResponseEventContent::new( let content = PollResponseEventContent::new(
vec!["first-answer".to_owned(), "second-answer".to_owned()].into(), vec!["first-answer".to_owned(), "second-answer".to_owned()].into(),
owned_event_id!("$related_event:notareal.hs"), owned_event_id!("$related_event:notareal.hs"),
@ -223,7 +228,7 @@ fn response_event_serialization() {
assert_eq!( assert_eq!(
to_json_value(&content).unwrap(), to_json_value(&content).unwrap(),
json!({ json!({
"org.matrix.msc3381.v2.selections": ["first-answer", "second-answer"], "m.selections": ["first-answer", "second-answer"],
"m.relates_to": { "m.relates_to": {
"rel_type": "m.reference", "rel_type": "m.reference",
"event_id": "$related_event:notareal.hs", "event_id": "$related_event:notareal.hs",
@ -236,7 +241,7 @@ fn response_event_serialization() {
fn response_event_deserialization() { fn response_event_deserialization() {
let json_data = json!({ let json_data = json!({
"content": { "content": {
"org.matrix.msc3381.v2.selections": ["my-answer"], "m.selections": ["my-answer"],
"m.relates_to": { "m.relates_to": {
"rel_type": "m.reference", "rel_type": "m.reference",
"event_id": "$related_event:notareal.hs", "event_id": "$related_event:notareal.hs",
@ -246,7 +251,7 @@ fn response_event_deserialization() {
"origin_server_ts": 134_829_848, "origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs", "room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs", "sender": "@user:notareal.hs",
"type": "org.matrix.msc3381.v2.poll.response", "type": "m.poll.response",
}); });
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(); let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
@ -271,9 +276,7 @@ fn end_content_serialization() {
assert_eq!( assert_eq!(
to_json_value(&event_content).unwrap(), to_json_value(&event_content).unwrap(),
json!({ json!({
"org.matrix.msc1767.text": [ "m.text": [{ "body": "The poll has closed. Top answer: Amazing!" }],
{ "body": "The poll has closed. Top answer: Amazing!" }
],
"m.relates_to": { "m.relates_to": {
"rel_type": "m.reference", "rel_type": "m.reference",
"event_id": "$related_event:notareal.hs", "event_id": "$related_event:notareal.hs",
@ -283,7 +286,7 @@ fn end_content_serialization() {
} }
#[test] #[test]
fn end_event_serialization() { fn end_content_with_results_serialization() {
let mut content = PollEndEventContent::with_plain_text( let mut content = PollEndEventContent::with_plain_text(
"The poll has closed. Top answer: Amazing!", "The poll has closed. Top answer: Amazing!",
owned_event_id!("$related_event:notareal.hs"), owned_event_id!("$related_event:notareal.hs"),
@ -300,10 +303,8 @@ fn end_event_serialization() {
assert_eq!( assert_eq!(
to_json_value(&content).unwrap(), to_json_value(&content).unwrap(),
json!({ json!({
"org.matrix.msc1767.text": [ "m.text": [{ "body": "The poll has closed. Top answer: Amazing!" }],
{ "body": "The poll has closed. Top answer: Amazing!" }, "m.poll.results": {
],
"org.matrix.msc3381.v2.poll.results": {
"not-bad": 1, "not-bad": 1,
"fine": 5, "fine": 5,
"amazing": 14, "amazing": 14,
@ -320,9 +321,14 @@ fn end_event_serialization() {
fn end_event_deserialization() { fn end_event_deserialization() {
let json_data = json!({ let json_data = json!({
"content": { "content": {
"org.matrix.msc1767.text": [ "m.text": [
{ "body": "The poll has closed. Top answer: Amazing!" }, { "body": "The poll has closed. Top answer: Amazing!" },
], ],
"m.poll.results": {
"not-bad": 1,
"fine": 5,
"amazing": 14,
},
"m.relates_to": { "m.relates_to": {
"rel_type": "m.reference", "rel_type": "m.reference",
"event_id": "$related_event:notareal.hs", "event_id": "$related_event:notareal.hs",
@ -332,7 +338,7 @@ fn end_event_deserialization() {
"origin_server_ts": 134_829_848, "origin_server_ts": 134_829_848,
"room_id": "!roomid:notareal.hs", "room_id": "!roomid:notareal.hs",
"sender": "@user:notareal.hs", "sender": "@user:notareal.hs",
"type": "org.matrix.msc3381.v2.poll.end", "type": "m.poll.end",
}); });
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(); let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
@ -349,7 +355,7 @@ fn new_poll_response(
selections: &[&str], selections: &[&str],
) -> OriginalSyncPollResponseEvent { ) -> OriginalSyncPollResponseEvent {
from_json_value(json!({ from_json_value(json!({
"type": "org.matrix.msc3381.v2.poll.response", "type": "m.poll.response",
"sender": user_id, "sender": user_id,
"origin_server_ts": ts, "origin_server_ts": ts,
"event_id": event_id, "event_id": event_id,
@ -358,7 +364,7 @@ fn new_poll_response(
"rel_type": "m.reference", "rel_type": "m.reference",
"event_id": "$poll_start_event_id" "event_id": "$poll_start_event_id"
}, },
"org.matrix.msc3381.v2.selections": selections, "m.selections": selections,
} }
})) }))
.unwrap() .unwrap()
@ -384,30 +390,27 @@ fn generate_poll_responses(
#[test] #[test]
fn compute_results() { fn compute_results() {
let poll: OriginalSyncPollStartEvent = from_json_value(json!({ let poll: OriginalSyncPollStartEvent = from_json_value(json!({
"type": "org.matrix.msc3381.v2.poll.start", "type": "m.poll.start",
"sender": "@alice:localhost", "sender": "@alice:localhost",
"event_id": "$poll_start_event_id", "event_id": "$poll_start_event_id",
"origin_server_ts": 1, "origin_server_ts": 1,
"content": { "content": {
"org.matrix.msc1767.text": [ "m.text": [
{ { "body": "What should we order for the party?\n1. Pizza 🍕\n2. Poutine 🍟\n3. Italian 🍝\n4. Wings 🔥" },
"mimetype": "text/plain",
"body": "What should we order for the party?\n1. Pizza 🍕\n2. Poutine 🍟\n3. Italian 🍝\n4. Wings 🔥"
}
], ],
"org.matrix.msc3381.v2.poll": { "m.poll": {
"kind": "m.disclosed", "kind": "m.disclosed",
"max_selections": 2, "max_selections": 2,
"question": { "question": {
"org.matrix.msc1767.text": [{"body": "What should we order for the party?"}] "m.text": [{ "body": "What should we order for the party?" }],
}, },
"answers": [ "answers": [
{"org.matrix.msc3381.v2.id": "pizza", "org.matrix.msc1767.text": [{"body": "Pizza 🍕"}]}, { "m.id": "pizza", "m.text": [{ "body": "Pizza 🍕" }] },
{"org.matrix.msc3381.v2.id": "poutine", "org.matrix.msc1767.text": [{"body": "Poutine 🍟"}]}, { "m.id": "poutine", "m.text": [{ "body": "Poutine 🍟" }] },
{"org.matrix.msc3381.v2.id": "italian", "org.matrix.msc1767.text": [{"body": "Italian 🍝"}]}, { "m.id": "italian", "m.text": [{ "body": "Italian 🍝" }] },
{"org.matrix.msc3381.v2.id": "wings", "org.matrix.msc1767.text": [{"body": "Wings 🔥"}]}, { "m.id": "wings", "m.text": [{ "body": "Wings 🔥" }] },
] ]
} },
} }
})).unwrap(); })).unwrap();