Fixed more unknown user errors

This commit is contained in:
RogueException
2016-06-12 20:19:37 -03:00
parent 2a9ac298fb
commit 2fc306c2e4
4 changed files with 11 additions and 11 deletions

View File

@@ -900,7 +900,7 @@ namespace Discord
if (data.ChannelId == null) if (data.ChannelId == null)
guild.RemoveVoiceState(data.UserId); guild.RemoveVoiceState(data.UserId);
else else
guild.AddOrUpdateVoiceState(data); guild.AddOrUpdateVoiceState(data, DataStore);
var user = guild.GetUser(data.UserId); var user = guild.GetUser(data.UserId);
if (user != null) if (user != null)

View File

@@ -16,7 +16,7 @@ namespace Discord
{ {
public bool IsDeaf { get; private set; } public bool IsDeaf { get; private set; }
public bool IsMute { get; private set; } public bool IsMute { get; private set; }
public DateTime JoinedAt { get; private set; } public DateTime? JoinedAt { get; private set; }
public string Nickname { get; private set; } public string Nickname { get; private set; }
public GuildPermissions GuildPermissions { get; private set; } public GuildPermissions GuildPermissions { get; private set; }

View File

@@ -13,7 +13,7 @@ namespace Discord
/// <summary> Returns true if the guild has muted this user. </summary> /// <summary> Returns true if the guild has muted this user. </summary>
bool IsMute { get; } bool IsMute { get; }
/// <summary> Gets when this user joined this guild. </summary> /// <summary> Gets when this user joined this guild. </summary>
DateTime JoinedAt { get; } DateTime? JoinedAt { get; }
/// <summary> Gets the nickname for this user. </summary> /// <summary> Gets the nickname for this user. </summary>
string Nickname { get; } string Nickname { get; }
/// <summary> Gets the guild-level permissions granted to this user by their roles. </summary> /// <summary> Gets the guild-level permissions granted to this user by their roles. </summary>

View File

@@ -79,7 +79,6 @@ namespace Discord
_channels = channels; _channels = channels;
var members = new ConcurrentDictionary<ulong, CachedGuildUser>(); var members = new ConcurrentDictionary<ulong, CachedGuildUser>();
var presences = new ConcurrentDictionary<ulong, Presence>();
if (model.Members != null) if (model.Members != null)
{ {
DownloadedMemberCount = 0; DownloadedMemberCount = 0;
@@ -89,24 +88,25 @@ namespace Discord
if (!model.Large) if (!model.Large)
_downloaderPromise.SetResult(true); _downloaderPromise.SetResult(true);
} }
_members = members;
var presences = new ConcurrentDictionary<ulong, Presence>();
if (model.Presences != null) if (model.Presences != null)
{ {
for (int i = 0; i < model.Presences.Length; i++) for (int i = 0; i < model.Presences.Length; i++)
{ {
var presence = model.Presences[i]; var presence = model.Presences[i];
AddOrUpdatePresence(presence, presences); AddOrUpdatePresence(presence, presences);
if (presence.Roles.IsSpecified) //AddUser(presence, dataStore, members);
AddUser(presence, dataStore, members); //TODO: Does this ever happen?
} }
} }
_presences = presences; _presences = presences;
_members = members;
var voiceStates = new ConcurrentDictionary<ulong, VoiceState>(); var voiceStates = new ConcurrentDictionary<ulong, VoiceState>();
if (model.VoiceStates != null) if (model.VoiceStates != null)
{ {
for (int i = 0; i < model.VoiceStates.Length; i++) for (int i = 0; i < model.VoiceStates.Length; i++)
AddOrUpdateVoiceState(model.VoiceStates[i], voiceStates); AddOrUpdateVoiceState(model.VoiceStates[i], dataStore, voiceStates);
} }
_voiceStates = voiceStates; _voiceStates = voiceStates;
} }
@@ -165,9 +165,9 @@ namespace Discord
return null; return null;
} }
public VoiceState AddOrUpdateVoiceState(VoiceStateModel model, ConcurrentDictionary<ulong, VoiceState> voiceStates = null) public VoiceState AddOrUpdateVoiceState(VoiceStateModel model, DataStore dataStore, ConcurrentDictionary<ulong, VoiceState> voiceStates = null)
{ {
var voiceChannel = GetChannel(model.ChannelId.Value) as CachedVoiceChannel; var voiceChannel = dataStore.GetChannel(model.ChannelId.Value) as CachedVoiceChannel;
var voiceState = new VoiceState(voiceChannel, model.SessionId, model.SelfMute, model.SelfDeaf, model.Suppress); var voiceState = new VoiceState(voiceChannel, model.SessionId, model.SelfMute, model.SelfDeaf, model.Suppress);
(voiceStates ?? _voiceStates)[model.UserId] = voiceState; (voiceStates ?? _voiceStates)[model.UserId] = voiceState;
return voiceState; return voiceState;
@@ -214,7 +214,6 @@ namespace Discord
} }
public CachedGuildUser AddUser(PresenceModel model, DataStore dataStore, ConcurrentDictionary<ulong, CachedGuildUser> members = null) public CachedGuildUser AddUser(PresenceModel model, DataStore dataStore, ConcurrentDictionary<ulong, CachedGuildUser> members = null)
{ {
var user = Discord.GetOrAddUser(model.User, dataStore);
members = members ?? _members; members = members ?? _members;
CachedGuildUser member; CachedGuildUser member;
@@ -222,6 +221,7 @@ namespace Discord
member.Update(model, UpdateSource.WebSocket); member.Update(model, UpdateSource.WebSocket);
else else
{ {
var user = Discord.GetOrAddUser(model.User, dataStore);
member = new CachedGuildUser(this, user, model); member = new CachedGuildUser(this, user, model);
members[user.Id] = member; members[user.Id] = member;
user.AddRef(); user.AddRef();