Skip to content

Commit

Permalink
fix(cache, model): Member#joined_at can sometimes be null (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
kane50613 authored Oct 25, 2023
1 parent b936a54 commit 44752d1
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 39 deletions.
6 changes: 3 additions & 3 deletions twilight-cache-inmemory/src/event/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ mod tests {
avatar: None,
communication_disabled_until: None,
flags,
joined_at: timestamp,
joined_at: Some(timestamp),
nick: None,
pending: false,
permissions: Permissions::empty(),
Expand Down Expand Up @@ -201,7 +201,7 @@ mod tests {
communication_disabled_until: None,
deaf: false,
flags,
joined_at: timestamp,
joined_at: Some(timestamp),
mute: false,
nick: Some("member nick".to_owned()),
permissions: None,
Expand Down Expand Up @@ -281,7 +281,7 @@ mod tests {
communication_disabled_until: None,
deaf: false,
flags,
joined_at: timestamp,
joined_at: Some(timestamp),
mute: false,
nick: None,
permissions: Some(Permissions::empty()),
Expand Down
2 changes: 1 addition & 1 deletion twilight-cache-inmemory/src/event/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ mod tests {

#[test]
fn message_create() -> Result<(), ImageHashParseError> {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let cache = InMemoryCache::builder()
.resource_types(ResourceType::MESSAGE | ResourceType::MEMBER | ResourceType::USER)
.message_cache_size(2)
Expand Down
2 changes: 1 addition & 1 deletion twilight-cache-inmemory/src/event/voice_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ mod tests {

#[test]
fn voice_states_members() -> Result<(), ImageHashParseError> {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));

let cache = InMemoryCache::new();

Expand Down
2 changes: 1 addition & 1 deletion twilight-cache-inmemory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ mod tests {

#[test]
fn highest_role() {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let cache = InMemoryCache::new();
let guild_id = Id::new(1);
let user = test::user(Id::new(1));
Expand Down
10 changes: 5 additions & 5 deletions twilight-cache-inmemory/src/model/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct CachedMember {
pub(crate) communication_disabled_until: Option<Timestamp>,
pub(crate) deaf: Option<bool>,
pub(crate) flags: MemberFlags,
pub(crate) joined_at: Timestamp,
pub(crate) joined_at: Option<Timestamp>,
pub(crate) mute: Option<bool>,
pub(crate) nick: Option<String>,
pub(crate) pending: bool,
Expand Down Expand Up @@ -66,7 +66,7 @@ impl CachedMember {
}

/// [`Timestamp`] of this member's join date.
pub const fn joined_at(&self) -> Timestamp {
pub const fn joined_at(&self) -> Option<Timestamp> {
self.joined_at
}

Expand Down Expand Up @@ -259,7 +259,7 @@ mod tests {
);

fn cached_member() -> CachedMember {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;
CachedMember {
avatar: None,
Expand Down Expand Up @@ -300,7 +300,7 @@ mod tests {

#[test]
fn eq_member() {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let member = Member {
Expand All @@ -322,7 +322,7 @@ mod tests {

#[test]
fn eq_partial_member() {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let member = PartialMember {
Expand Down
4 changes: 2 additions & 2 deletions twilight-cache-inmemory/src/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ mod tests {
/// [`root`]: super::InMemoryCachePermissions::root
#[test]
fn root() -> Result<(), Box<dyn Error>> {
let joined_at = Timestamp::from_str("2021-09-19T14:17:32.000000+00:00")?;
let joined_at = Some(Timestamp::from_str("2021-09-19T14:17:32.000000+00:00")?);

let cache = InMemoryCache::new();
let permissions = cache.permissions();
Expand Down Expand Up @@ -1114,7 +1114,7 @@ mod tests {
communication_disabled_until: Some(in_past),
guild_id: GUILD_ID,
deaf: None,
joined_at: Timestamp::from_secs(1).unwrap(),
joined_at: Some(Timestamp::from_secs(1).unwrap()),
mute: None,
nick: None,
pending: false,
Expand Down
4 changes: 2 additions & 2 deletions twilight-cache-inmemory/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn cache() -> InMemoryCache {

#[allow(clippy::too_many_lines)]
pub fn cache_with_message_and_reactions() -> InMemoryCache {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let cache = InMemoryCache::new();
let avatar = ImageHash::parse(b"6961d9f1fdb5880bf4a3ec6348d3bbcf").unwrap();
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;
Expand Down Expand Up @@ -277,7 +277,7 @@ pub fn guild_channel_text() -> (Id<GuildMarker>, Id<ChannelMarker>, Channel) {
}

pub fn member(id: Id<UserMarker>) -> Member {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

Member {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct InteractionMember {
/// Defaults to an empty bitfield.
pub flags: MemberFlags,
/// Member guild join date.
pub joined_at: Timestamp,
pub joined_at: Option<Timestamp>,
/// Member nickname.
pub nick: Option<String>,
/// Whether the user has yet to pass the guild's Membership Screening
Expand Down Expand Up @@ -118,7 +118,7 @@ mod tests {
#[test]
#[allow(clippy::too_many_lines)]
fn test_data_resolved() -> Result<(), TimestampParseError> {
let joined_at = Timestamp::from_str("2021-08-10T12:18:37.000000+00:00")?;
let joined_at = Some(Timestamp::from_str("2021-08-10T12:18:37.000000+00:00")?);
let timestamp = Timestamp::from_str("2020-02-02T02:02:02.020000+00:00")?;
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

Expand Down Expand Up @@ -355,6 +355,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2021-08-10T12:18:37.000000+00:00"),
Token::Str("nick"),
Token::None,
Expand Down Expand Up @@ -440,6 +441,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2021-08-10T12:18:37.000000+00:00"),
Token::Str("mute"),
Token::Bool(false),
Expand Down
4 changes: 3 additions & 1 deletion twilight-model/src/application/interaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ mod tests {
#[test]
#[allow(clippy::too_many_lines, deprecated)]
fn test_interaction_full() -> Result<(), TimestampParseError> {
let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?;
let joined_at = Some(Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?);
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let value = Interaction {
Expand Down Expand Up @@ -651,6 +651,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2020-01-01T00:00:00.000000+00:00"),
Token::Str("nick"),
Token::Some,
Expand Down Expand Up @@ -725,6 +726,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2020-01-01T00:00:00.000000+00:00"),
Token::Str("mute"),
Token::Bool(false),
Expand Down
3 changes: 2 additions & 1 deletion twilight-model/src/channel/message/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod tests {
#[allow(clippy::too_many_lines)]
#[test]
fn message_interaction() -> Result<(), Box<dyn Error>> {
let joined_at = Timestamp::from_str("2015-04-26T06:26:56.936000+00:00")?;
let joined_at = Some(Timestamp::from_str("2015-04-26T06:26:56.936000+00:00")?);
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let value = MessageInteraction {
Expand Down Expand Up @@ -108,6 +108,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2015-04-26T06:26:56.936000+00:00"),
Token::Str("mute"),
Token::Bool(true),
Expand Down
3 changes: 2 additions & 1 deletion twilight-model/src/channel/message/mention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod tests {

#[test]
fn mention_with_member() -> Result<(), TimestampParseError> {
let joined_at = Timestamp::from_str("2015-04-26T06:26:56.936000+00:00")?;
let joined_at = Some(Timestamp::from_str("2015-04-26T06:26:56.936000+00:00")?);
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let value = Mention {
Expand Down Expand Up @@ -148,6 +148,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2015-04-26T06:26:56.936000+00:00"),
Token::Str("mute"),
Token::Bool(true),
Expand Down
6 changes: 4 additions & 2 deletions twilight-model/src/channel/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mod tests {
#[allow(clippy::too_many_lines)]
#[test]
fn message_deserialization() {
let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00").unwrap();
let joined_at = Some(Timestamp::from_str("2020-01-01T00:00:00.000000+00:00").unwrap());
let timestamp = Timestamp::from_micros(1_580_608_922_020_000).expect("non zero");
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

Expand Down Expand Up @@ -358,6 +358,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2020-01-01T00:00:00.000000+00:00"),
Token::Str("mute"),
Token::Bool(false),
Expand Down Expand Up @@ -408,7 +409,7 @@ mod tests {
#[test]
fn message_deserialization_complete() -> Result<(), TimestampParseError> {
let edited_timestamp = Timestamp::from_str("2021-08-10T12:41:51.602000+00:00")?;
let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?;
let joined_at = Some(Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?);
let timestamp = Timestamp::from_micros(1_580_608_922_020_000).expect("non zero");
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

Expand Down Expand Up @@ -616,6 +617,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2020-01-01T00:00:00.000000+00:00"),
Token::Str("mute"),
Token::Bool(false),
Expand Down
3 changes: 2 additions & 1 deletion twilight-model/src/gateway/payload/incoming/member_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod tests {

#[test]
fn member_add() {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let value = MemberAdd {
Expand Down Expand Up @@ -91,6 +91,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2021-09-19T17:30:45.000000+00:00"),
Token::Str("mute"),
Token::Bool(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod tests {
#[allow(clippy::too_many_lines)]
#[test]
fn simple_member_chunk() -> Result<(), TimestampParseError> {
let joined_at = Timestamp::from_str("2020-04-04T04:04:04.000000+00:00")?;
let joined_at = Some(Timestamp::from_str("2020-04-04T04:04:04.000000+00:00")?);
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let input = serde_json::json!({
Expand Down
5 changes: 3 additions & 2 deletions twilight-model/src/gateway/payload/incoming/member_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct MemberUpdate {
pub communication_disabled_until: Option<Timestamp>,
pub guild_id: Id<GuildMarker>,
pub deaf: Option<bool>,
pub joined_at: Timestamp,
pub joined_at: Option<Timestamp>,
pub mute: Option<bool>,
pub nick: Option<String>,
/// Whether the user has yet to pass the guild's [Membership Screening]
Expand All @@ -42,7 +42,7 @@ mod tests {

#[test]
fn member_update() {
let joined_at = Timestamp::from_micros(1_488_234_110_121_000).expect("non zero");
let joined_at = Some(Timestamp::from_micros(1_488_234_110_121_000).expect("non zero"));
let communication_disabled_until =
Timestamp::from_micros(1_641_027_600_000_000).expect("non zero");

Expand Down Expand Up @@ -97,6 +97,7 @@ mod tests {
Token::Some,
Token::Bool(false),
Token::Str("joined_at"),
Token::Some,
Token::Str("2017-02-27T22:21:50.121000+00:00"),
Token::Str("mute"),
Token::Some,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ mod tests {
const JOIN_TIMESTAMP: &str = "2015-04-26T06:26:56.936000+00:00";
const PREMIUM_SINCE: &str = "2021-03-16T14:29:19.046000+00:00";

let joined_at = Timestamp::from_str(JOIN_TIMESTAMP).expect("timestamp error");
let joined_at = Some(Timestamp::from_str(JOIN_TIMESTAMP).expect("timestamp error"));
let premium_since = Timestamp::from_str(PREMIUM_SINCE).expect("timestamp error");
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

Expand Down Expand Up @@ -234,6 +234,7 @@ mod tests {
Token::NewtypeStruct { name: "GuildId" },
Token::Str("1"),
Token::Str("joined_at"),
Token::Some,
Token::Str(JOIN_TIMESTAMP),
Token::Str("mute"),
Token::Bool(true),
Expand Down
3 changes: 2 additions & 1 deletion twilight-model/src/gateway/payload/incoming/typing_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod tests {
#[allow(clippy::too_many_lines)]
#[test]
fn typing_start_with_member() -> Result<(), TimestampParseError> {
let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?;
let joined_at = Some(Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?);
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let value = TypingStart {
Expand Down Expand Up @@ -102,6 +102,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2020-01-01T00:00:00.000000+00:00"),
Token::Str("mute"),
Token::Bool(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod tests {
#[test]
#[allow(clippy::too_many_lines)]
fn voice_state_update() {
let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero");
let joined_at = Some(Timestamp::from_secs(1_632_072_645).expect("non zero"));
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let value = VoiceStateUpdate(VoiceState {
Expand Down Expand Up @@ -115,6 +115,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2021-09-19T17:30:45.000000+00:00"),
Token::Str("mute"),
Token::Bool(false),
Expand Down Expand Up @@ -181,7 +182,7 @@ mod tests {
#[test]
#[allow(clippy::too_many_lines)]
fn voice_state_update_deser_tokens() -> Result<(), TimestampParseError> {
let joined_at = Timestamp::from_str("2016-12-08T18:41:21.954000+00:00")?;
let joined_at = Some(Timestamp::from_str("2016-12-08T18:41:21.954000+00:00")?);
let request_to_speak_timestamp = Timestamp::from_str("2021-03-31T18:45:31.297561+00:00")?;
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

Expand Down Expand Up @@ -266,6 +267,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2016-12-08T18:41:21.954000+00:00"),
Token::Str("mute"),
Token::Bool(false),
Expand Down
3 changes: 2 additions & 1 deletion twilight-model/src/gateway/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod tests {
#[allow(clippy::too_many_lines)]
#[test]
fn reaction_with_member() {
let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00").unwrap();
let joined_at = Some(Timestamp::from_str("2020-01-01T00:00:00.000000+00:00").unwrap());
let flags = MemberFlags::BYPASSES_VERIFICATION | MemberFlags::DID_REJOIN;

let value = GatewayReaction {
Expand Down Expand Up @@ -118,6 +118,7 @@ mod tests {
Token::Str("flags"),
Token::U64(flags.bits()),
Token::Str("joined_at"),
Token::Some,
Token::Str("2020-01-01T00:00:00.000000+00:00"),
Token::Str("mute"),
Token::Bool(false),
Expand Down
Loading

0 comments on commit 44752d1

Please sign in to comment.