Browse Source

Create IMessageCache

pull/1766/head
Daniel Baynton 4 years ago
parent
commit
ad67e17ff1
6 changed files with 24 additions and 6 deletions
  1. +2
    -2
      src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs
  2. +1
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
  3. +1
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs
  4. +1
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
  5. +18
    -0
      src/Discord.Net.WebSocket/Entities/Messages/IMessageCache.cs
  6. +1
    -1
      src/Discord.Net.WebSocket/Entities/Messages/MessageCache.cs

+ 2
- 2
src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs View File

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


+ 1
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs View File

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


+ 1
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs View File

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


+ 1
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

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


+ 18
- 0
src/Discord.Net.WebSocket/Entities/Messages/IMessageCache.cs View File

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

+ 1
- 1
src/Discord.Net.WebSocket/Entities/Messages/MessageCache.cs View File

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


Loading…
Cancel
Save