Browse Source

Ensure recipients have been cached before creating private channels.

tags/docs-0.9
Brandon Smith 10 years ago
parent
commit
c5b7aa2ad1
2 changed files with 13 additions and 3 deletions
  1. +1
    -1
      src/Discord.Net/Collections/Channels.cs
  2. +12
    -2
      src/Discord.Net/DiscordClient.cs

+ 1
- 1
src/Discord.Net/Collections/Channels.cs View File

@@ -22,7 +22,7 @@ namespace Discord.Collections
if (user.PrivateChannelId != null)
throw new Exception("User already has a private channel.");
user.PrivateChannelId = item.Id;
item.Recipient.AddRef();
user.AddRef();
}
}
protected override void OnRemoved(Channel item)


+ 12
- 2
src/Discord.Net/DiscordClient.cs View File

@@ -283,7 +283,9 @@ namespace Discord
}
foreach (var model in data.PrivateChannels)
{
var channel = _channels.GetOrAdd(model.Id, null, model.Recipient?.Id);
var user = _users.GetOrAdd(model.Recipient.Id);
user.Update(data.Recipient);
var channel = _channels.GetOrAdd(model.Id, null, user.Id);
channel.Update(model);
}
}
@@ -324,7 +326,15 @@ namespace Discord
case "CHANNEL_CREATE":
{
var data = e.Payload.ToObject<Events.ChannelCreate>(_serializer);
var channel = _channels.GetOrAdd(data.Id, data.GuildId, data.Recipient?.Id);
Channel channel;
if (data.IsPrivate)
{
var user = _users.GetOrAdd(data.Recipient.Id);
user.Update(data.Recipient);
channel = _channels.GetOrAdd(data.Id, null, user.Id);
}
else
channel = _channels.GetOrAdd(data.Id, data.GuildId, null);
channel.Update(data);
RaiseChannelCreated(channel);
}


Loading…
Cancel
Save