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)
{
msg = channel.AddMessage(data.Id, data.Author.Id, data.Timestamp.Value);
msg = channel.AddMessage(data.Id, user, data.Timestamp.Value);
//nonce = 0;
}



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

@@ -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;
}


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

@@ -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;


Loading…
Cancel
Save