Cache Message.User
This commit is contained in:
@@ -758,7 +758,7 @@ namespace Discord
|
||||
}*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -240,9 +240,9 @@ namespace Discord
|
||||
#endregion
|
||||
|
||||
#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;
|
||||
if (cacheLength > 0)
|
||||
{
|
||||
@@ -298,13 +298,13 @@ namespace Discord
|
||||
Message msg = null;
|
||||
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;
|
||||
if (user != null)
|
||||
user.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp);
|
||||
}
|
||||
else
|
||||
msg = new Message(x.Id, this, x.Author.Id);
|
||||
msg = new Message(x.Id, this, GetUser(x.Author.Id));
|
||||
msg.Update(x);
|
||||
return msg;
|
||||
})
|
||||
@@ -352,7 +352,7 @@ namespace Discord
|
||||
IsTTS = isTTS
|
||||
};
|
||||
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);
|
||||
}
|
||||
return msg;
|
||||
@@ -372,7 +372,7 @@ namespace Discord
|
||||
};
|
||||
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);
|
||||
return msg;
|
||||
}
|
||||
|
||||
@@ -171,9 +171,11 @@ namespace Discord
|
||||
public ulong Id { get; }
|
||||
/// <summary> Returns the channel this message was sent to. </summary>
|
||||
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>
|
||||
public MessageState State { get; internal set; }
|
||||
/// <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>
|
||||
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;
|
||||
Channel = channel;
|
||||
_userId = userId;
|
||||
User = user;
|
||||
|
||||
Attachments = _initialAttachments;
|
||||
Embeds = _initialEmbeds;
|
||||
|
||||
Reference in New Issue
Block a user