Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily fix GuildChannel::message_count in a non-breaking way #2058

Merged
merged 3 commits into from
Jul 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/model/channel/guild_channel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::convert::TryFrom;
use std::fmt;
#[cfg(feature = "model")]
use std::sync::Arc;
Expand Down Expand Up @@ -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<Option<u8>, D::Error> {
let real_count = Option::<u32>::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
Expand Down Expand Up @@ -117,9 +126,12 @@ pub struct GuildChannel {
pub rtc_region: Option<String>,
/// The video quality mode for a voice channel.
pub video_quality_mode: Option<VideoQualityMode>,
/// 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<u8>,
/// An approximate count of users in a thread, stops counting at 50.
///
Expand Down