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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/model/channel/guild_channel.rs
@@ -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 @@ -120,6 +129,7 @@ pub struct GuildChannel {
/// An approximate count of messages in the thread, stops counting at 50.
GnomedDev marked this conversation as resolved.
Show resolved Hide resolved
///
/// **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