From 391ef978418e8593c6adedfe7521ad51f081b436 Mon Sep 17 00:00:00 2001 From: "Carson M." Date: Tue, 4 Jun 2024 22:05:34 -0500 Subject: [PATCH] feat(yt): add fallback unknown chat item Failing the entire stream when we can't parse a single message seems like a bad idea. --- src/youtube/types/get_live_chat.rs | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/youtube/types/get_live_chat.rs b/src/youtube/types/get_live_chat.rs index 3b65987..2d46e3a 100644 --- a/src/youtube/types/get_live_chat.rs +++ b/src/youtube/types/get_live_chat.rs @@ -15,6 +15,7 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_aux::prelude::*; +use simd_json::{base::ValueAsContainer, derived::ValueObjectAccessAsScalar}; use url::Url; use super::{deserialize_datetime_utc_from_microseconds, Accessibility, CommandMetadata, Icon, ImageContainer, LocalizedText, UnlocalizedText}; @@ -136,31 +137,19 @@ pub struct InvalidationId { pub enum Action { #[serde(rename = "addChatItemAction")] #[serde(rename_all = "camelCase")] - AddChatItem { - item: ChatItem, - client_id: Option - }, + AddChatItem { item: ChatItem, client_id: Option }, #[serde(rename = "replaceChatItemAction")] #[serde(rename_all = "camelCase")] - ReplaceChatItem { - target_item_id: String, - replacement_item: ChatItem - }, + ReplaceChatItem { target_item_id: String, replacement_item: ChatItem }, #[serde(rename = "removeChatItemAction")] #[serde(rename_all = "camelCase")] - RemoveChatItem { - target_item_id: String - }, + RemoveChatItem { target_item_id: String }, #[serde(rename = "removeChatItemByAuthorAction")] #[serde(rename_all = "camelCase")] - RemoveChatItemByAuthor { - external_channel_id: String - }, + RemoveChatItemByAuthor { external_channel_id: String }, #[serde(rename = "addLiveChatTickerItemAction")] #[serde(rename_all = "camelCase")] - AddLiveChatTicker { - item: simd_json::OwnedValue - }, + AddLiveChatTicker { item: simd_json::OwnedValue }, #[serde(rename = "replayChatItemAction")] #[serde(rename_all = "camelCase")] ReplayChat { @@ -174,7 +163,8 @@ pub enum Action { #[serde(flatten)] data: simd_json::OwnedValue }, - LiveChatReportModerationStateCommand(simd_json::OwnedValue) + #[serde(rename = "liveChatReportModerationStateCommand")] + ReportModerationState(simd_json::OwnedValue) } #[derive(Deserialize, Debug, Clone)] @@ -285,7 +275,9 @@ pub enum ChatItem { timestamp_usec: DateTime }, #[serde(rename = "liveChatViewerEngagementMessageRenderer")] - ViewerEngagement { id: String } + ViewerEngagement { id: String }, + #[serde(untagged)] + Unknown(simd_json::OwnedValue) } impl ChatItem { @@ -298,7 +290,8 @@ impl ChatItem { ChatItem::MembershipGift { id, .. } => id, ChatItem::MembershipGiftRedemption { id, .. } => id, ChatItem::Placeholder { id, .. } => id, - ChatItem::ViewerEngagement { id } => id + ChatItem::ViewerEngagement { id } => id, + ChatItem::Unknown(_) => "" } } }