Browse Source

Crash fix and some added documentation.

tags/docs-0.9
RogueException 9 years ago
parent
commit
ee9ccf816b
4 changed files with 29 additions and 15 deletions
  1. +3
    -3
      src/Discord.Net/Collections/Messages.cs
  2. +8
    -8
      src/Discord.Net/DiscordClient.API.cs
  3. +16
    -3
      src/Discord.Net/DiscordClient.cs
  4. +2
    -1
      src/Discord.Net/Models/Message.cs

+ 3
- 3
src/Discord.Net/Collections/Messages.cs View File

@@ -11,18 +11,18 @@ namespace Discord.Collections
_msgCleaner = new MessageCleaner(client);
}

internal Message GetOrAdd(string id, string channelId) => GetOrAdd(id, () => new Message(_client, id, channelId));
internal Message GetOrAdd(string id, string channelId, string userId) => GetOrAdd(id, () => new Message(_client, id, channelId, userId));
internal new Message TryRemove(string id) => base.TryRemove(id);
internal new Message Remap(string oldKey, string newKey) => base.Remap(oldKey, newKey);

protected override void OnCreated(Message item)
{
item.Channel.AddMessage(item.UserId);
item.Channel.AddMessage(item.Id);
item.User.AddRef();
}
protected override void OnRemoved(Message item)
{
item.Channel.RemoveMessage(item.UserId);
item.Channel.RemoveMessage(item.Id);
item.User.RemoveRef();
}



+ 8
- 8
src/Discord.Net/DiscordClient.API.cs View File

@@ -254,7 +254,7 @@ namespace Discord
var nonce = GenerateNonce();
if (_config.UseMessageQueue)
{
var msg = _messages.GetOrAdd("nonce_" + nonce, channelId);
var msg = _messages.GetOrAdd("nonce_" + nonce, channelId, _currentUserId);
msg.Update(new Net.API.Message
{
Content = blockText,
@@ -269,9 +269,9 @@ namespace Discord
}
else
{
var response = await _api.SendMessage(channelId, blockText, mentions, nonce).ConfigureAwait(false);
var msg = _messages.GetOrAdd(response.Id, channelId);
msg.Update(response);
var model = await _api.SendMessage(channelId, blockText, mentions, nonce).ConfigureAwait(false);
var msg = _messages.GetOrAdd(model.Id, channelId, model.Author.Id);
msg.Update(model);
try { RaiseMessageSent(result[i]); } catch { }
}
await Task.Delay(1000).ConfigureAwait(false);
@@ -319,9 +319,9 @@ namespace Discord
if (text.Length > DiscordAPIClient.MaxMessageSize)
text = text.Substring(0, DiscordAPIClient.MaxMessageSize);

var response = await _api.EditMessage(channelId, messageId, text, mentions).ConfigureAwait(false);
var msg = _messages.GetOrAdd(messageId, channelId);
msg.Update(response);
var model = await _api.EditMessage(channelId, messageId, text, mentions).ConfigureAwait(false);
var msg = _messages.GetOrAdd(messageId, channelId, model.Author.Id);
msg.Update(model);
}

/// <summary> Deletes the provided message. </summary>
@@ -402,7 +402,7 @@ namespace Discord
var msgs = await _api.GetMessages(channel.Id, count).ConfigureAwait(false);
return msgs.Select(x =>
{
var msg = _messages.GetOrAdd(x.Id, x.ChannelId);
var msg = _messages.GetOrAdd(x.Id, x.ChannelId, x.Author.Id);
msg.Update(x);
if (_config.TrackActivity)
{


+ 16
- 3
src/Discord.Net/DiscordClient.cs View File

@@ -42,23 +42,36 @@ namespace Discord
/// <summary> Returns the current logged-in user. </summary>
public User CurrentUser => _currentUser;
private User _currentUser;
/// <summary> Returns the id of the server this user is currently connected to for voice. </summary>
public string CurrentVoiceServerId => _voiceSocket.CurrentVoiceServerId;
/// <summary> Returns the server this user is currently connected to for voice. </summary>
public Server CurrentVoiceServer => _servers[_voiceSocket.CurrentVoiceServerId];

/// <summary> Returns the current connection state of this client. </summary>
public DiscordClientState State => (DiscordClientState)_state;
private int _state;

/// <summary> Returns the configuration object used to make this client. Note that this object cannot be edited directly - to change the configuration of this client, use the DiscordClient(DiscordClientConfig config) constructor. </summary>
public DiscordClientConfig Config => _config;
private readonly DiscordClientConfig _config;

/// <summary> Returns a collection of all channels this client is a member of. </summary>
public Channels Channels => _channels;
private readonly Channels _channels;
/// <summary> Returns a collection of all user-server pairs this client can currently see. </summary>
public Members Members => _members;
private readonly Members _members;
/// <summary> Returns a collection of all messages this client has seen since logging in and currently has in cache. </summary>
public Messages Messages => _messages;
private readonly Messages _messages;
//TODO: Do we need the roles cache?
/// <summary> Returns a collection of all role-server pairs this client can currently see. </summary>
public Roles Roles => _roles;
private readonly Roles _roles;
/// <summary> Returns a collection of all servers this client is a member of. </summary>
public Servers Servers => _servers;
private readonly Servers _servers;
/// <summary> Returns a collection of all users this client can currently see. </summary>
public Users Users => _users;
private readonly Users _users;

@@ -343,7 +356,7 @@ namespace Discord
}
if (msg == null)
msg = _messages.GetOrAdd(data.Id, data.ChannelId);
msg = _messages.GetOrAdd(data.Id, data.ChannelId, data.Author.Id);
msg.Update(data);
if (_config.TrackActivity)
msg.User.UpdateActivity(data.Timestamp);
@@ -355,7 +368,7 @@ namespace Discord
case "MESSAGE_UPDATE":
{
var data = e.Payload.ToObject<Events.MessageUpdate>(_serializer);
var msg = _messages.GetOrAdd(data.Id, data.ChannelId);
var msg = _messages.GetOrAdd(data.Id, data.ChannelId, data.Author.Id);
msg.Update(data);
RaiseEvent(nameof(MessageUpdated), () => RaiseMessageUpdated(msg));
}


+ 2
- 1
src/Discord.Net/Models/Message.cs View File

@@ -114,11 +114,12 @@ namespace Discord
[JsonIgnore]
public Member Member => _client.Members[ServerId, UserId];

internal Message(DiscordClient client, string id, string channelId)
internal Message(DiscordClient client, string id, string channelId, string userId)
{
_client = client;
Id = id;
ChannelId = channelId;
UserId = userId;
}

internal void Update(Net.API.Message model)


Loading…
Cancel
Save