More Bugfixes

This commit is contained in:
Brandon Smith
2015-08-13 13:57:05 -03:00
parent adf30ad4e5
commit 214ca84ca7
3 changed files with 10 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ namespace Discord
public string RecipientId { get; internal set; } public string RecipientId { get; internal set; }
public User Recipient { get { return _client.GetUser(RecipientId); } } public User Recipient { get { return _client.GetUser(RecipientId); } }
[JsonIgnore]
public IEnumerable<Message> Messages { get { return _client.Messages.Where(x => x.ChannelId == Id); } } public IEnumerable<Message> Messages { get { return _client.Messages.Where(x => x.ChannelId == Id); } }
//Not Implemented //Not Implemented

View File

@@ -343,7 +343,7 @@ namespace Discord
case "MESSAGE_UPDATE": case "MESSAGE_UPDATE":
{ {
var data = e.Event.ToObject<WebSocketEvents.MessageUpdate>(); var data = e.Event.ToObject<WebSocketEvents.MessageUpdate>();
var msg = _messages.Update(data.Id, data); var msg = _messages.Update(data.Id, data.ChannelId, data);
RaiseMessageUpdated(msg); RaiseMessageUpdated(msg);
} }
break; break;
@@ -600,7 +600,7 @@ namespace Discord
{ {
int index = i * DiscordAPI.MaxMessageSize; int index = i * DiscordAPI.MaxMessageSize;
var msg = await DiscordAPI.SendMessage(channelId, text.Substring(index, Math.Min(2000, text.Length - index)), mentions, _httpOptions); 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); await Task.Delay(1000);
} }
} }

View File

@@ -23,13 +23,14 @@ namespace Discord
private ConcurrentQueue<byte[]> _sendQueue; private ConcurrentQueue<byte[]> _sendQueue;
private int _heartbeatInterval; private int _heartbeatInterval;
private DateTime _lastHeartbeat; private DateTime _lastHeartbeat;
private AutoResetEvent _connectWaitOnLogin; private AutoResetEvent _connectWaitOnLogin, _connectWaitOnLogin2;
public async Task ConnectAsync(string url, HttpOptions options) public async Task ConnectAsync(string url, HttpOptions options)
{ {
await DisconnectAsync(); await DisconnectAsync();
_connectWaitOnLogin = new AutoResetEvent(false); _connectWaitOnLogin = new AutoResetEvent(false);
_connectWaitOnLogin2 = new AutoResetEvent(false);
_sendQueue = new ConcurrentQueue<byte[]>(); _sendQueue = new ConcurrentQueue<byte[]>();
_webSocket = new ClientWebSocket(); _webSocket = new ClientWebSocket();
@@ -66,8 +67,9 @@ namespace Discord
msg.Payload.Properties["$referring_domain"] = ""; msg.Payload.Properties["$referring_domain"] = "";
SendMessage(msg, cancelToken); SendMessage(msg, cancelToken);
if (!_connectWaitOnLogin.WaitOne(ReadyTimeout)) if (!_connectWaitOnLogin.WaitOne(ReadyTimeout)) //Pre-Event
throw new Exception("No reply from Discord server"); throw new Exception("No reply from Discord server");
_connectWaitOnLogin2.WaitOne(); //Post-Event
} }
public async Task DisconnectAsync() public async Task DisconnectAsync()
{ {
@@ -116,10 +118,11 @@ namespace Discord
_heartbeatInterval = payload.HeartbeatInterval; _heartbeatInterval = payload.HeartbeatInterval;
SendMessage(new WebSocketCommands.UpdateStatus(), cancelToken); SendMessage(new WebSocketCommands.UpdateStatus(), cancelToken);
SendMessage(new WebSocketCommands.KeepAlive(), cancelToken); SendMessage(new WebSocketCommands.KeepAlive(), cancelToken);
} _connectWaitOnLogin.Set(); //Pre-Event
}
RaiseGotEvent(msg.Type, msg.Payload as JToken); RaiseGotEvent(msg.Type, msg.Payload as JToken);
if (msg.Type == "READY") if (msg.Type == "READY")
_connectWaitOnLogin.Set(); _connectWaitOnLogin2.Set(); //Post-Event
break; break;
default: default:
RaiseOnDebugMessage("Unknown WebSocket operation ID: " + msg.Operation); RaiseOnDebugMessage("Unknown WebSocket operation ID: " + msg.Operation);