DownloadMessages shouldn't pop newer messages out of the message cache when downloading older ones.
This commit is contained in:
@@ -217,7 +217,7 @@ namespace Discord
|
|||||||
|
|
||||||
|
|
||||||
/// <summary> Downloads last count messages from the server, returning all messages before or after relativeMessageId, if it's provided. </summary>
|
/// <summary> Downloads last count messages from the server, returning all messages before or after relativeMessageId, if it's provided. </summary>
|
||||||
public async Task<Message[]> DownloadMessages(Channel channel, int count, string relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before, bool cache = false)
|
public async Task<Message[]> DownloadMessages(Channel channel, int count, string relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before, bool cache = true)
|
||||||
{
|
{
|
||||||
if (channel == null) throw new ArgumentNullException(nameof(channel));
|
if (channel == null) throw new ArgumentNullException(nameof(channel));
|
||||||
if (count < 0) throw new ArgumentNullException(nameof(count));
|
if (count < 0) throw new ArgumentNullException(nameof(count));
|
||||||
|
|||||||
@@ -140,10 +140,11 @@ namespace Discord
|
|||||||
|
|
||||||
internal void AddMessage(Message message)
|
internal void AddMessage(Message message)
|
||||||
{
|
{
|
||||||
|
//Race conditions are okay here - it just means the queue will occasionally go higher than the requested cache size, and fixed later.
|
||||||
var cacheLength = _client.Config.MessageCacheLength;
|
var cacheLength = _client.Config.MessageCacheLength;
|
||||||
if (cacheLength > 0)
|
if (cacheLength > 0)
|
||||||
{
|
{
|
||||||
var oldestIds = _messages.Select(x => x.Value.Id).OrderBy(x => x).Take(_messages.Count - cacheLength);
|
var oldestIds = _messages.Where(x => x.Value.Timestamp < message.Timestamp).Select(x => x.Key).OrderBy(x => x).Take(_messages.Count - cacheLength);
|
||||||
foreach (var id in oldestIds)
|
foreach (var id in oldestIds)
|
||||||
{
|
{
|
||||||
Message removed;
|
Message removed;
|
||||||
|
|||||||
Reference in New Issue
Block a user