From 214ca84ca7328685dd4cf06e44e409c78c35f13e Mon Sep 17 00:00:00 2001 From: Brandon Smith Date: Thu, 13 Aug 2015 13:57:05 -0300 Subject: [PATCH] More Bugfixes --- Discord.Net/Channel.cs | 1 + Discord.Net/DiscordClient.cs | 4 ++-- Discord.Net/DiscordWebSocket.cs | 11 +++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Discord.Net/Channel.cs b/Discord.Net/Channel.cs index 31fff3cbb..5fb5be194 100644 --- a/Discord.Net/Channel.cs +++ b/Discord.Net/Channel.cs @@ -24,6 +24,7 @@ namespace Discord public string RecipientId { get; internal set; } public User Recipient { get { return _client.GetUser(RecipientId); } } + [JsonIgnore] public IEnumerable Messages { get { return _client.Messages.Where(x => x.ChannelId == Id); } } //Not Implemented diff --git a/Discord.Net/DiscordClient.cs b/Discord.Net/DiscordClient.cs index cb4fac018..2ae330499 100644 --- a/Discord.Net/DiscordClient.cs +++ b/Discord.Net/DiscordClient.cs @@ -343,7 +343,7 @@ namespace Discord case "MESSAGE_UPDATE": { var data = e.Event.ToObject(); - var msg = _messages.Update(data.Id, data); + var msg = _messages.Update(data.Id, data.ChannelId, data); RaiseMessageUpdated(msg); } break; @@ -600,7 +600,7 @@ namespace Discord { int index = i * DiscordAPI.MaxMessageSize; var msg = await DiscordAPI.SendMessage(channelId, text.Substring(index, Math.Min(2000, text.Length - index)), mentions, _httpOptions); - _messages.Update(msg.Id, msg); + _messages.Update(msg.Id, channelId, msg); await Task.Delay(1000); } } diff --git a/Discord.Net/DiscordWebSocket.cs b/Discord.Net/DiscordWebSocket.cs index 87bfd1f5d..27caee53d 100644 --- a/Discord.Net/DiscordWebSocket.cs +++ b/Discord.Net/DiscordWebSocket.cs @@ -23,13 +23,14 @@ namespace Discord private ConcurrentQueue _sendQueue; private int _heartbeatInterval; private DateTime _lastHeartbeat; - private AutoResetEvent _connectWaitOnLogin; + private AutoResetEvent _connectWaitOnLogin, _connectWaitOnLogin2; public async Task ConnectAsync(string url, HttpOptions options) { await DisconnectAsync(); _connectWaitOnLogin = new AutoResetEvent(false); + _connectWaitOnLogin2 = new AutoResetEvent(false); _sendQueue = new ConcurrentQueue(); _webSocket = new ClientWebSocket(); @@ -66,8 +67,9 @@ namespace Discord msg.Payload.Properties["$referring_domain"] = ""; SendMessage(msg, cancelToken); - if (!_connectWaitOnLogin.WaitOne(ReadyTimeout)) + if (!_connectWaitOnLogin.WaitOne(ReadyTimeout)) //Pre-Event throw new Exception("No reply from Discord server"); + _connectWaitOnLogin2.WaitOne(); //Post-Event } public async Task DisconnectAsync() { @@ -116,10 +118,11 @@ namespace Discord _heartbeatInterval = payload.HeartbeatInterval; SendMessage(new WebSocketCommands.UpdateStatus(), cancelToken); SendMessage(new WebSocketCommands.KeepAlive(), cancelToken); - } + _connectWaitOnLogin.Set(); //Pre-Event + } RaiseGotEvent(msg.Type, msg.Payload as JToken); if (msg.Type == "READY") - _connectWaitOnLogin.Set(); + _connectWaitOnLogin2.Set(); //Post-Event break; default: RaiseOnDebugMessage("Unknown WebSocket operation ID: " + msg.Operation);