Skip to content

Commit

Permalink
fix(models): add "flags" field to MemberUpdate payload (#2265)
Browse files Browse the repository at this point in the history
Adds the `flags` field to the MemberUpdate gateway model. Discord sends
this field, but it is not captured by Twilight, and is incredibly useful
when working with servers that have onboarding enabled.

---------

Co-authored-by: itohatweb <[email protected]>
  • Loading branch information
Kelwing and itohatweb authored Nov 18, 2024
1 parent b2734c0 commit f773e51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions twilight-cache-inmemory/src/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ mod tests {
communication_disabled_until: None,
guild_id: GUILD_ID,
deaf: None,
flags: None,
joined_at,
mute: None,
nick: None,
Expand Down Expand Up @@ -1122,6 +1123,7 @@ mod tests {
communication_disabled_until: Some(in_past),
guild_id: GUILD_ID,
deaf: None,
flags: None,
joined_at: Some(Timestamp::from_secs(1).unwrap()),
mute: None,
nick: None,
Expand Down
11 changes: 9 additions & 2 deletions twilight-model/src/gateway/payload/incoming/member_update.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
guild::MemberFlags,
id::{
marker::{GuildMarker, RoleMarker},
Id,
Expand All @@ -14,6 +15,8 @@ pub struct MemberUpdate {
pub avatar: Option<ImageHash>,
pub communication_disabled_until: Option<Timestamp>,
pub guild_id: Id<GuildMarker>,
#[serde(skip_serializing_if = "Option::is_none")]
pub flags: Option<MemberFlags>,
pub deaf: Option<bool>,
pub joined_at: Option<Timestamp>,
pub mute: Option<bool>,
Expand All @@ -37,7 +40,7 @@ pub struct MemberUpdate {
#[cfg(test)]
mod tests {
use super::MemberUpdate;
use crate::{id::Id, test::image_hash, user::User, util::Timestamp};
use crate::{guild::MemberFlags, id::Id, test::image_hash, user::User, util::Timestamp};
use serde_test::Token;

#[test]
Expand All @@ -51,6 +54,7 @@ mod tests {
avatar: None,
communication_disabled_until: Some(communication_disabled_until),
guild_id: Id::new(1_234),
flags: Some(MemberFlags::empty()),
deaf: Some(false),
joined_at,
mute: Some(false),
Expand Down Expand Up @@ -85,7 +89,7 @@ mod tests {
&[
Token::Struct {
name: "MemberUpdate",
len: 11,
len: 12,
},
Token::Str("avatar"),
Token::None,
Expand All @@ -95,6 +99,9 @@ mod tests {
Token::Str("guild_id"),
Token::NewtypeStruct { name: "Id" },
Token::Str("1234"),
Token::Str("flags"),
Token::Some,
Token::U64(0),
Token::Str("deaf"),
Token::Some,
Token::Bool(false),
Expand Down

0 comments on commit f773e51

Please sign in to comment.