Redirected SocketClient's GetGuildEmbed, GetGuilds and GetVoiceRegions to the cache.

This commit is contained in:
RogueException
2016-06-19 19:01:43 -03:00
parent 480034feed
commit 1b5d0546a7
3 changed files with 24 additions and 3 deletions

View File

@@ -279,6 +279,18 @@ namespace Discord
{
return Task.FromResult<IGuild>(DataStore.GetGuild(id));
}
public override Task<GuildEmbed?> GetGuildEmbedAsync(ulong id)
{
var guild = DataStore.GetGuild(id);
if (guild != null)
return Task.FromResult<GuildEmbed?>(new GuildEmbed(guild.IsEmbeddable, guild.EmbedChannelId));
else
return Task.FromResult<GuildEmbed?>(null);
}
public override Task<IReadOnlyCollection<IUserGuild>> GetGuildsAsync()
{
return Task.FromResult<IReadOnlyCollection<IUserGuild>>(Guilds);
}
internal CachedGuild AddGuild(API.Gateway.ExtendedGuild model, DataStore dataStore)
{
var guild = new CachedGuild(this, model, dataStore);
@@ -296,7 +308,7 @@ namespace Discord
guild.RemoveUser(user.Id);
return guild;
}
/// <inheritdoc />
public override Task<IChannel> GetChannelAsync(ulong id)
{
@@ -385,6 +397,11 @@ namespace Discord
}
}
public override Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync()
{
return Task.FromResult<IReadOnlyCollection<IVoiceRegion>>(_voiceRegions.ToReadOnlyCollection());
}
private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string type, object payload)
{
#if BENCHMARK

View File

@@ -16,7 +16,7 @@ using VoiceStateModel = Discord.API.VoiceState;
namespace Discord
{
internal class CachedGuild : Guild, ICachedEntity<ulong>
internal class CachedGuild : Guild, IUserGuild, ICachedEntity<ulong>
{
private TaskCompletionSource<bool> _downloaderPromise;
private ConcurrentHashSet<ulong> _channels;
@@ -42,7 +42,7 @@ namespace Discord
}
}
public IReadOnlyCollection<CachedGuildUser> Members => _members.ToReadOnlyCollection();
public CachedGuild(DiscordSocketClient discord, ExtendedModel model, DataStore dataStore) : base(discord, model)
{
_downloaderPromise = new TaskCompletionSource<bool>();
@@ -257,5 +257,8 @@ namespace Discord
throw new InvalidOperationException($"Unknown channel type: {model.Type.Value}");
}
}
bool IUserGuild.IsOwner => OwnerId == Discord.CurrentUser.Id;
GuildPermissions IUserGuild.Permissions => CurrentUser.GuildPermissions;
}
}

View File

@@ -6,6 +6,7 @@ namespace Discord
{
internal class CachedPublicUser : User, ICachedUser
{
//TODO: Fix removed game/status (add CachedDMUser?)
private int _references;
//private Game? _game;
//private UserStatus _status;