Skip to content

Commit

Permalink
Create unset member instances on presence updates
Browse files Browse the repository at this point in the history
If a presence update for a guild comes in and their associated member
instance is not present (e.g. in a large guild that wasn't member
chunked), then create one with the infomation known out of the presence
update. This includes their user information, guild ID, nickname, and
roles, but not their `deaf`, `joined_at`, and `mute` state.
  • Loading branch information
Zeyla Hellyer committed Jan 17, 2018
1 parent f42408c commit d1113c0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/model/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,25 @@ impl CacheUpdate for PresenceUpdateEvent {
.presences
.insert(self.presence.user_id, self.presence.clone());
}

// Create a partial member instance out of the presence update
// data. This includes everything but `deaf`, `mute`, and
// `joined_at`.
if !guild.members.contains_key(&self.presence.user_id) {
if let Some(user) = self.presence.user.as_ref() {
let roles = self.roles.clone().unwrap_or_default();

guild.members.insert(self.presence.user_id, Member {
deaf: false,
guild_id: guild_id,
joined_at: None,
mute: false,
nick: self.presence.nick.clone(),
user: Arc::clone(&user),
roles,
});
}
}
}
} else if self.presence.status == OnlineStatus::Offline {
cache.presences.remove(&self.presence.user_id);
Expand Down

0 comments on commit d1113c0

Please sign in to comment.