@@ -8,7 +8,7 @@ namespace Discord.WebSocket | |||||
{ | { | ||||
internal static class SocketChannelHelper | internal static class SocketChannelHelper | ||||
{ | { | ||||
public static IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ISocketMessageChannel channel, DiscordSocketClient discord, MessageCache messages, | |||||
public static IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ISocketMessageChannel channel, DiscordSocketClient discord, IMessageCache messages, | |||||
ulong? fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) | ulong? fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) | ||||
{ | { | ||||
if (dir == Direction.After && fromMessageId == null) | if (dir == Direction.After && fromMessageId == null) | ||||
@@ -54,7 +54,7 @@ namespace Discord.WebSocket | |||||
return ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit, options); | return ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit, options); | ||||
} | } | ||||
} | } | ||||
public static IReadOnlyCollection<SocketMessage> GetCachedMessages(ISocketMessageChannel channel, DiscordSocketClient discord, MessageCache messages, | |||||
public static IReadOnlyCollection<SocketMessage> GetCachedMessages(ISocketMessageChannel channel, DiscordSocketClient discord, IMessageCache messages, | |||||
ulong? fromMessageId, Direction dir, int limit) | ulong? fromMessageId, Direction dir, int limit) | ||||
{ | { | ||||
if (messages != null) //Cache enabled | if (messages != null) //Cache enabled | ||||
@@ -16,7 +16,7 @@ namespace Discord.WebSocket | |||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | ||||
public class SocketDMChannel : SocketChannel, IDMChannel, ISocketPrivateChannel, ISocketMessageChannel | public class SocketDMChannel : SocketChannel, IDMChannel, ISocketPrivateChannel, ISocketMessageChannel | ||||
{ | { | ||||
private readonly MessageCache _messages; | |||||
private readonly IMessageCache _messages; | |||||
/// <summary> | /// <summary> | ||||
/// Gets the recipient of the channel. | /// Gets the recipient of the channel. | ||||
@@ -20,7 +20,7 @@ namespace Discord.WebSocket | |||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | ||||
public class SocketGroupChannel : SocketChannel, IGroupChannel, ISocketPrivateChannel, ISocketMessageChannel, ISocketAudioChannel | public class SocketGroupChannel : SocketChannel, IGroupChannel, ISocketPrivateChannel, ISocketMessageChannel, ISocketAudioChannel | ||||
{ | { | ||||
private readonly MessageCache _messages; | |||||
private readonly IMessageCache _messages; | |||||
private readonly ConcurrentDictionary<ulong, SocketVoiceState> _voiceStates; | private readonly ConcurrentDictionary<ulong, SocketVoiceState> _voiceStates; | ||||
private string _iconId; | private string _iconId; | ||||
@@ -16,7 +16,7 @@ namespace Discord.WebSocket | |||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | ||||
public class SocketTextChannel : SocketGuildChannel, ITextChannel, ISocketMessageChannel | public class SocketTextChannel : SocketGuildChannel, ITextChannel, ISocketMessageChannel | ||||
{ | { | ||||
private readonly MessageCache _messages; | |||||
private readonly IMessageCache _messages; | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public string Topic { get; private set; } | public string Topic { get; private set; } | ||||
@@ -0,0 +1,18 @@ | |||||
using System.Collections.Generic; | |||||
using Discord.WebSocket; | |||||
namespace Discord | |||||
{ | |||||
internal interface IMessageCache | |||||
{ | |||||
public IReadOnlyCollection<SocketMessage> Messages { get; } | |||||
public void Add(SocketMessage message); | |||||
public SocketMessage Remove(ulong id); | |||||
public SocketMessage Get(ulong id); | |||||
public IReadOnlyCollection<SocketMessage> GetMany(ulong? fromMessageId, Direction dir, int limit); | |||||
} | |||||
} |
@@ -6,7 +6,7 @@ using System.Linq; | |||||
namespace Discord.WebSocket | namespace Discord.WebSocket | ||||
{ | { | ||||
internal class MessageCache | |||||
internal class MessageCache : IMessageCache | |||||
{ | { | ||||
private readonly ConcurrentDictionary<ulong, SocketMessage> _messages; | private readonly ConcurrentDictionary<ulong, SocketMessage> _messages; | ||||
private readonly ConcurrentQueue<ulong> _orderedMessages; | private readonly ConcurrentQueue<ulong> _orderedMessages; | ||||