Split GetGuildsAsync into GetGuildsAsync and GetGuildSummariesAsync
This commit is contained in:
@@ -918,17 +918,28 @@ namespace Discord.API
|
||||
//Was this an empty batch?
|
||||
if (models.Length == 0) break;
|
||||
|
||||
//We can't assume these messages to be sorted by id (fails in rare cases), lets search for the highest/lowest id ourselves
|
||||
switch (args.RelativeDirection)
|
||||
{
|
||||
case Direction.Before:
|
||||
case Direction.Around:
|
||||
default:
|
||||
result[i] = models;
|
||||
relativeId = models[models.Length - 1].Id;
|
||||
relativeId = ulong.MaxValue;
|
||||
for (int j = 0; j < models.Length; j++)
|
||||
{
|
||||
if (models[j].Id < relativeId.Value)
|
||||
relativeId = models[j].Id;
|
||||
}
|
||||
break;
|
||||
case Direction.After:
|
||||
result[runs - i - 1] = models;
|
||||
relativeId = models[0].Id;
|
||||
relativeId = ulong.MinValue;
|
||||
for (int j = 0; j < models.Length; j++)
|
||||
{
|
||||
if (models[j].Id > relativeId.Value)
|
||||
relativeId = models[j].Id;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -194,11 +194,23 @@ namespace Discord
|
||||
return null;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<IReadOnlyCollection<IUserGuild>> GetGuildsAsync()
|
||||
public virtual async Task<IReadOnlyCollection<IUserGuild>> GetGuildSummariesAsync()
|
||||
{
|
||||
var models = await ApiClient.GetMyGuildsAsync().ConfigureAwait(false);
|
||||
return models.Select(x => new UserGuild(this, x)).ToImmutableArray();
|
||||
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<IReadOnlyCollection<IGuild>> GetGuildsAsync()
|
||||
{
|
||||
var summaryModels = await ApiClient.GetMyGuildsAsync().ConfigureAwait(false);
|
||||
var guilds = ImmutableArray.CreateBuilder<IGuild>(summaryModels.Count);
|
||||
foreach (var summaryModel in summaryModels)
|
||||
{
|
||||
var guildModel = await ApiClient.GetGuildAsync(summaryModel.Id).ConfigureAwait(false);
|
||||
if (guildModel != null)
|
||||
guilds.Add(new Guild(this, guildModel));
|
||||
}
|
||||
return guilds.ToImmutable();
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public virtual async Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null)
|
||||
|
||||
@@ -190,24 +190,29 @@ namespace Discord
|
||||
ConnectionState = ConnectionState.Disconnecting;
|
||||
await _gatewayLogger.InfoAsync("Disconnecting").ConfigureAwait(false);
|
||||
|
||||
await _gatewayLogger.DebugAsync("Disconnecting - CancelToken").ConfigureAwait(false);
|
||||
//Signal tasks to complete
|
||||
try { _cancelToken.Cancel(); } catch { }
|
||||
|
||||
await _gatewayLogger.DebugAsync("Disconnecting - ApiClient").ConfigureAwait(false);
|
||||
//Disconnect from server
|
||||
await ApiClient.DisconnectAsync().ConfigureAwait(false);
|
||||
|
||||
//Wait for tasks to complete
|
||||
await _gatewayLogger.DebugAsync("Disconnecting - Heartbeat").ConfigureAwait(false);
|
||||
var heartbeatTask = _heartbeatTask;
|
||||
if (heartbeatTask != null)
|
||||
await heartbeatTask.ConfigureAwait(false);
|
||||
_heartbeatTask = null;
|
||||
|
||||
await _gatewayLogger.DebugAsync("Disconnecting - Guild Downloader").ConfigureAwait(false);
|
||||
var guildDownloadTask = _guildDownloadTask;
|
||||
if (guildDownloadTask != null)
|
||||
await guildDownloadTask.ConfigureAwait(false);
|
||||
_guildDownloadTask = null;
|
||||
|
||||
//Clear large guild queue
|
||||
await _gatewayLogger.DebugAsync("Disconnecting - Clean Large Guilds").ConfigureAwait(false);
|
||||
while (_largeGuilds.TryDequeue(out guildId)) { }
|
||||
|
||||
ConnectionState = ConnectionState.Disconnected;
|
||||
@@ -293,10 +298,14 @@ namespace Discord
|
||||
else
|
||||
return Task.FromResult<GuildEmbed?>(null);
|
||||
}
|
||||
public override Task<IReadOnlyCollection<IUserGuild>> GetGuildsAsync()
|
||||
public override Task<IReadOnlyCollection<IUserGuild>> GetGuildSummariesAsync()
|
||||
{
|
||||
return Task.FromResult<IReadOnlyCollection<IUserGuild>>(Guilds);
|
||||
}
|
||||
public override Task<IReadOnlyCollection<IGuild>> GetGuildsAsync()
|
||||
{
|
||||
return Task.FromResult<IReadOnlyCollection<IGuild>>(Guilds);
|
||||
}
|
||||
internal CachedGuild AddGuild(ExtendedGuild model, DataStore dataStore)
|
||||
{
|
||||
var guild = new CachedGuild(this, model, dataStore);
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
namespace Discord
|
||||
{
|
||||
//TODO: Add docstrings
|
||||
//TODO: Docstrings should explain when REST requests are sent and how many
|
||||
public interface IDiscordClient : IDisposable
|
||||
{
|
||||
LoginState LoginState { get; }
|
||||
@@ -28,7 +29,8 @@ namespace Discord
|
||||
Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync();
|
||||
|
||||
Task<IGuild> GetGuildAsync(ulong id);
|
||||
Task<IReadOnlyCollection<IUserGuild>> GetGuildsAsync();
|
||||
Task<IReadOnlyCollection<IGuild>> GetGuildsAsync();
|
||||
Task<IReadOnlyCollection<IUserGuild>> GetGuildSummariesAsync();
|
||||
Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null);
|
||||
|
||||
Task<IInvite> GetInviteAsync(string inviteIdOrXkcd);
|
||||
|
||||
Reference in New Issue
Block a user