Browse Source

Fix SocketGuild

pull/1595/head
Paulo 5 years ago
parent
commit
f21f1d78b0
1 changed files with 29 additions and 4 deletions
  1. +29
    -4
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 29
- 4
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -809,17 +809,37 @@ namespace Discord.WebSocket
var members = Users;
var self = CurrentUser;
_members.Clear();
_members.TryAdd(self.Id, self);
if (self != null)
_members.TryAdd(self.Id, self);

DownloadedMemberCount = _members.Count;

foreach (var member in members)
{
if (member.Id != self.Id)
if (member.Id != self?.Id)
member.GlobalUser.RemoveRef(Discord);
}
}

/// <summary>
/// Gets a collection of all users in this guild.
/// </summary>
/// <remarks>
/// <para>This method retrieves all users found within this guild throught REST.</para>
/// <para>Users returned by this method are not cached.</para>
/// </remarks>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous get operation. The task result contains a collection of guild
/// users found within this guild.
/// </returns>
public IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> GetUsersAsync(RequestOptions options = null)
{
if (HasAllMembers)
return ImmutableArray.Create(Users).ToAsyncEnumerable<IReadOnlyCollection<IGuildUser>>();
return GuildHelper.GetUsersAsync(this, Discord, null, null, options);
}

/// <inheritdoc />
public async Task DownloadUsersAsync()
{
@@ -1201,8 +1221,13 @@ namespace Discord.WebSocket
=> await CreateRoleAsync(name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false);

/// <inheritdoc />
Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IReadOnlyCollection<IGuildUser>>(Users);
async Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload && !HasAllMembers)
return (await GetUsersAsync(options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
else
return Users;
}

/// <inheritdoc />
async Task<IGuildUser> IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func, RequestOptions options)


Loading…
Cancel
Save