fix: add support for new channel about data model

This commit is contained in:
ThetaDev 2023-08-22 22:58:28 +02:00
parent 57628d1392
commit e2eda901b1
3 changed files with 66 additions and 10 deletions

View file

@ -200,8 +200,12 @@ impl<'de> Deserialize<'de> for TextComponent {
where
D: Deserializer<'de>,
{
let mut text = RichTextInternal::deserialize(deserializer)?;
Ok(text.runs.swap_remove(0).into())
let text = RichTextInternal::deserialize(deserializer)?;
text.runs
.into_iter()
.next()
.map(TextComponent::from)
.ok_or(serde::de::Error::invalid_length(0, &"at least 1"))
}
}
@ -289,6 +293,20 @@ impl<'de> DeserializeAs<'de, TextComponents> for AttributedText {
}
}
impl<'de> DeserializeAs<'de, TextComponent> for AttributedText {
fn deserialize_as<D>(deserializer: D) -> Result<TextComponent, D::Error>
where
D: Deserializer<'de>,
{
let components: TextComponents = AttributedText::deserialize_as(deserializer)?;
components
.0
.into_iter()
.next()
.ok_or(serde::de::Error::invalid_length(0, &"at least 1"))
}
}
impl TryFrom<TextComponent> for crate::model::ChannelId {
type Error = ();
@ -404,6 +422,17 @@ impl TextComponent {
}
}
impl From<TextComponent> for String {
fn from(value: TextComponent) -> Self {
match value {
TextComponent::Video { text, .. }
| TextComponent::Browse { text, .. }
| TextComponent::Web { text, .. }
| TextComponent::Text { text } => text,
}
}
}
impl TextComponents {
/// Return the string representation of the first text component
pub fn first_str(&self) -> &str {