From aa7be1ac8f958fd6d17834aaedd2eefbf1d60968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dybiec?= Date: Tue, 27 Dec 2022 16:01:09 +0000 Subject: Treat missing mentions as empty list --- src/mattermost/model.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mattermost/model.rs b/src/mattermost/model.rs index 9d4d78e..d928359 100644 --- a/src/mattermost/model.rs +++ b/src/mattermost/model.rs @@ -56,7 +56,7 @@ pub struct Posted { pub channel_display_name: String, pub channel_name: String, pub channel_type: String, - #[serde(deserialize_with = "deserialize_json_field")] + #[serde(deserialize_with = "deserialize_json_field", default)] pub mentions: Vec, #[serde(deserialize_with = "deserialize_json_field")] pub post: Post, @@ -296,4 +296,10 @@ mod tests { } ); } + #[test] + fn parse_realexamples() { + let data = r#"{"event":"posted","data":{"channel_display_name":"a","channel_name":"a","channel_type":"O","post":"{\"id\":\"b\",\"create_at\":1,\"update_at\":2,\"edit_at\":0,\"delete_at\":0,\"is_pinned\":false,\"user_id\":\"b\",\"channel_id\":\"c\",\"root_id\":\"\",\"original_id\":\"\",\"message\":\"blah\",\"type\":\"\",\"props\":{\"disable_group_highlight\":true},\"hashtags\":\"\",\"pending_post_id\":\"d\",\"reply_count\":0,\"last_reply_at\":0,\"participants\":null,\"metadata\":{}}","sender_name":"@blah","set_online":true,"team_id":"e"},"broadcast":{"omit_users":null,"user_id":"","channel_id":"f","team_id":"","connection_id":"","omit_connection_id":""},"seq":3}"#; + + serde_json::from_str::(data).unwrap(); + } } -- cgit v1.2.3