Browse Source

Cache Message.User

tags/docs-0.9
RogueException 9 years ago
parent
commit
0f092ba522
3 changed files with 13 additions and 13 deletions
  1. +1
    -1
      src/Discord.Net/DiscordClient.cs
  2. +6
    -6
      src/Discord.Net/Models/Channel.cs
  3. +6
    -6
      src/Discord.Net/Models/Message.cs

+ 1
- 1
src/Discord.Net/DiscordClient.cs View File

@@ -758,7 +758,7 @@ namespace Discord
}*/ }*/
if (msg == null) if (msg == null)
{ {
msg = channel.AddMessage(data.Id, data.Author.Id, data.Timestamp.Value);
msg = channel.AddMessage(data.Id, user, data.Timestamp.Value);
//nonce = 0; //nonce = 0;
} }




+ 6
- 6
src/Discord.Net/Models/Channel.cs View File

@@ -240,9 +240,9 @@ namespace Discord
#endregion #endregion


#region Messages #region Messages
internal Message AddMessage(ulong id, ulong userId, DateTime timestamp)
internal Message AddMessage(ulong id, User user, DateTime timestamp)
{ {
Message message = new Message(id, this, userId);
Message message = new Message(id, this, user);
var cacheLength = Client.Config.MessageCacheSize; var cacheLength = Client.Config.MessageCacheSize;
if (cacheLength > 0) if (cacheLength > 0)
{ {
@@ -298,13 +298,13 @@ namespace Discord
Message msg = null; Message msg = null;
if (useCache) if (useCache)
{ {
msg = AddMessage(x.Id, x.Author.Id, x.Timestamp.Value);
msg = AddMessage(x.Id, GetUser(x.Author.Id), x.Timestamp.Value);
var user = msg.User; var user = msg.User;
if (user != null) if (user != null)
user.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp); user.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp);
} }
else else
msg = new Message(x.Id, this, x.Author.Id);
msg = new Message(x.Id, this, GetUser(x.Author.Id));
msg.Update(x); msg.Update(x);
return msg; return msg;
}) })
@@ -352,7 +352,7 @@ namespace Discord
IsTTS = isTTS IsTTS = isTTS
}; };
var model = await Client.ClientAPI.Send(request).ConfigureAwait(false); var model = await Client.ClientAPI.Send(request).ConfigureAwait(false);
msg = AddMessage(model.Id, model.Author.Id, model.Timestamp.Value);
msg = AddMessage(model.Id, IsPrivate ? Client.PrivateUser : Server.CurrentUser, model.Timestamp.Value);
msg.Update(model); msg.Update(model);
} }
return msg; return msg;
@@ -372,7 +372,7 @@ namespace Discord
}; };
var model = await Client.ClientAPI.Send(request).ConfigureAwait(false); var model = await Client.ClientAPI.Send(request).ConfigureAwait(false);


var msg = AddMessage(model.Id, model.Author.Id, model.Timestamp.Value);
var msg = AddMessage(model.Id, IsPrivate ? Client.PrivateUser : Server.CurrentUser, model.Timestamp.Value);
msg.Update(model); msg.Update(model);
return msg; return msg;
} }


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

@@ -171,9 +171,11 @@ namespace Discord
public ulong Id { get; } public ulong Id { get; }
/// <summary> Returns the channel this message was sent to. </summary> /// <summary> Returns the channel this message was sent to. </summary>
public Channel Channel { get; } public Channel Channel { get; }
/// <summary> Returns the author of this message. </summary>
public User User { get; }


/// <summary> Returns true if the message was sent as text-to-speech by someone with permissions to do so. </summary>
public bool IsTTS { get; private set; }
/// <summary> Returns true if the message was sent as text-to-speech by someone with permissions to do so. </summary>
public bool IsTTS { get; private set; }
/// <summary> Returns the state of this message. Only useful if UseMessageQueue is true. </summary> /// <summary> Returns the state of this message. Only useful if UseMessageQueue is true. </summary>
public MessageState State { get; internal set; } public MessageState State { get; internal set; }
/// <summary> Returns the raw content of this message as it was received from the server. </summary> /// <summary> Returns the raw content of this message as it was received from the server. </summary>
@@ -198,14 +200,12 @@ namespace Discord
/// <summary> Returns the server containing the channel this message was sent to. </summary> /// <summary> Returns the server containing the channel this message was sent to. </summary>
public Server Server => Channel.Server; public Server Server => Channel.Server;
/// <summary> Returns the author of this message. </summary>
public User User => Channel.GetUser(_userId);


internal Message(ulong id, Channel channel, ulong userId)
internal Message(ulong id, Channel channel, User user)
{ {
Id = id; Id = id;
Channel = channel; Channel = channel;
_userId = userId;
User = user;


Attachments = _initialAttachments; Attachments = _initialAttachments;
Embeds = _initialEmbeds; Embeds = _initialEmbeds;


Loading…
Cancel
Save