From 0a53345aa185e39b13d9db0f6e088f4fd03a0eea Mon Sep 17 00:00:00 2001 From: Gnome! <45660393+GnomedDev@users.noreply.github.com> Date: Tue, 19 Jul 2022 18:11:50 +0100 Subject: [PATCH] Temporarily fix `GuildChannel::message_count` in a non-breaking way (#2058) --- src/model/channel/guild_channel.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 1622bfc2ce4..efdc019347f 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -1,3 +1,4 @@ +use std::convert::TryFrom; use std::fmt; #[cfg(feature = "model")] use std::sync::Arc; @@ -41,6 +42,14 @@ use crate::model::channel::AttachmentType; use crate::model::prelude::*; use crate::model::Timestamp; +// HACK(Gnome!): Prevent having to change the type of message_count on serenity@current +fn message_count_patch<'de, D: serde::Deserializer<'de>>( + deserializer: D, +) -> StdResult, D::Error> { + let real_count = Option::::deserialize(deserializer)?; + Ok(real_count.map(u8::try_from).transpose().unwrap_or(Some(u8::MAX))) +} + /// Represents a guild's text, news, or voice channel. Some methods are available /// only for voice channels and some are only available for text channels. /// News channels are a subset of text channels and lack slow mode hence @@ -117,9 +126,12 @@ pub struct GuildChannel { pub rtc_region: Option, /// The video quality mode for a voice channel. pub video_quality_mode: Option, - /// An approximate count of messages in the thread, stops counting at 50. + /// An approximate count of messages in the thread. + /// + /// This is currently saturated at 255 to prevent breaking. /// /// **Note**: This is only available on thread channels. + #[serde(deserialize_with = "message_count_patch")] pub message_count: Option, /// An approximate count of users in a thread, stops counting at 50. ///