Browse Source

Cleaned up docstrings, improved GetUser performance

tags/1.0-rc
RogueException 9 years ago
parent
commit
227643c0fc
14 changed files with 22 additions and 25 deletions
  1. +1
    -1
      src/Discord.Net/API/DiscordAPIClient.cs
  2. +1
    -2
      src/Discord.Net/DiscordClient.cs
  3. +0
    -2
      src/Discord.Net/DiscordConfig.cs
  4. +4
    -5
      src/Discord.Net/DiscordSocketClient.cs
  5. +0
    -1
      src/Discord.Net/Entities/Guilds/Guild.cs
  6. +1
    -1
      src/Discord.Net/Entities/Permissions/Permissions.cs
  7. +1
    -1
      src/Discord.Net/Entities/SnowflakeEntity.cs
  8. +1
    -2
      src/Discord.Net/Entities/Users/IUser.cs
  9. +1
    -0
      src/Discord.Net/Entities/WebSocket/CachedDMChannel.cs
  10. +8
    -5
      src/Discord.Net/Entities/WebSocket/CachedTextChannel.cs
  11. +1
    -1
      src/Discord.Net/Entities/WebSocket/ICachedMessageChannel.cs
  12. +1
    -1
      src/Discord.Net/Entities/WebSocket/MessageCache.cs
  13. +1
    -1
      src/Discord.Net/Net/Rest/DefaultRestClient.cs
  14. +1
    -2
      src/Discord.Net/Net/WebSockets/DefaultWebsocketClient.cs

+ 1
- 1
src/Discord.Net/API/DiscordAPIClient.cs View File

@@ -155,7 +155,7 @@ namespace Discord.API
}
private async Task LogoutInternalAsync()
{
//TODO: An exception here will lock the client into the unusable LoggingOut state. How should we handle? (Add same solution to both DiscordClients too)
//An exception here will lock the client into the unusable LoggingOut state, but that's probably fine since our client is in an undefined state too.
if (LoginState == LoginState.LoggedOut) return;
LoginState = LoginState.LoggingOut;


+ 1
- 2
src/Discord.Net/DiscordClient.cs View File

@@ -41,8 +41,7 @@ namespace Discord

_connectionLock = new SemaphoreSlim(1, 1);
_requestQueue = new RequestQueue();

//TODO: Is there any better way to do this WebSocketProvider access?
ApiClient = new API.DiscordApiClient(config.RestClientProvider, (config as DiscordSocketConfig)?.WebSocketProvider, requestQueue: _requestQueue);
ApiClient.SentRequest += async (method, endpoint, millis) => await _log.VerboseAsync("Rest", $"{method} {endpoint}: {millis} ms").ConfigureAwait(false);
}


+ 0
- 2
src/Discord.Net/DiscordConfig.cs View File

@@ -3,8 +3,6 @@ using System.Reflection;

namespace Discord
{
//TODO: Add socket config items in their own class

public class DiscordConfig
{
public static string Version { get; } = typeof(DiscordConfig).GetTypeInfo().Assembly?.GetName().Version.ToString(3) ?? "Unknown";


+ 4
- 5
src/Discord.Net/DiscordSocketClient.cs View File

@@ -361,8 +361,7 @@ namespace Discord
case "READY":
{
await _gatewayLogger.DebugAsync("Received Dispatch (READY)").ConfigureAwait(false);

//TODO: Make downloading large guilds optional
var data = (payload as JToken).ToObject<ReadyEvent>(_serializer);
var dataStore = _dataStoreProvider(ShardId, _totalShards, data.Guilds.Length, data.PrivateChannels.Length);

@@ -741,7 +740,7 @@ namespace Discord
var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel;
if (channel != null)
{
var author = channel.GetUser(data.Author.Value.Id);
var author = channel.GetUser(data.Author.Value.Id, true);

if (author != null)
{
@@ -780,7 +779,7 @@ namespace Discord
else if (data.Author.IsSpecified)
{
//Edited message isnt in cache, create a detached one
var author = channel.GetUser(data.Author.Value.Id);
var author = channel.GetUser(data.Author.Value.Id, true);
if (author != null)
after = new Message(channel, author, data);
}
@@ -879,7 +878,7 @@ namespace Discord
var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel;
if (channel != null)
{
var user = channel.GetUser(data.UserId);
var user = channel.GetUser(data.UserId, true);
if (user != null)
await UserIsTyping.RaiseAsync(channel, user).ConfigureAwait(false);
}


+ 0
- 1
src/Discord.Net/Entities/Guilds/Guild.cs View File

@@ -130,7 +130,6 @@ namespace Discord
}
public async Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args)
{
//TODO: Update channels
await Discord.ApiClient.ModifyGuildChannelsAsync(Id, args).ConfigureAwait(false);
}
public async Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args)


+ 1
- 1
src/Discord.Net/Entities/Permissions/Permissions.cs View File

@@ -131,7 +131,7 @@ namespace Discord
if (perms != null)
resolvedPermissions = (resolvedPermissions & ~perms.Value.DenyValue) | perms.Value.AllowValue;
//TODO: C# Typeswitch candidate
//TODO: C#7 Typeswitch candidate
var textChannel = channel as ITextChannel;
var voiceChannel = channel as IVoiceChannel;
if (textChannel != null && !GetValue(resolvedPermissions, ChannelPermission.ReadMessages))


+ 1
- 1
src/Discord.Net/Entities/SnowflakeEntity.cs View File

@@ -4,7 +4,7 @@ namespace Discord
{
internal abstract class SnowflakeEntity : Entity<ulong>, ISnowflakeEntity
{
//TODO: Candidate for Extension Property. Lets us remove this class.
//TODO: C#7 Candidate for Extension Property. Lets us remove this class.
public DateTime CreatedAt => DateTimeUtils.FromSnowflake(Id);

public SnowflakeEntity(ulong id)


+ 1
- 2
src/Discord.Net/Entities/Users/IUser.cs View File

@@ -12,8 +12,7 @@ namespace Discord
bool IsBot { get; }
/// <summary> Gets the username for this user. </summary>
string Username { get; }

//TODO: CreateDMChannel is a candidate to move to IGuildUser, and User made a common class, depending on next friends list update
/// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary>
Task<IDMChannel> CreateDMChannelAsync();
}


+ 1
- 0
src/Discord.Net/Entities/WebSocket/CachedDMChannel.cs View File

@@ -66,6 +66,7 @@ namespace Discord
public CachedDMChannel Clone() => MemberwiseClone() as CachedDMChannel;

IMessage IMessageChannel.GetCachedMessage(ulong id) => GetMessage(id);
ICachedUser ICachedMessageChannel.GetUser(ulong id, bool skipCheck) => GetUser(id);
ICachedChannel ICachedChannel.Clone() => Clone();
}
}

+ 8
- 5
src/Discord.Net/Entities/WebSocket/CachedTextChannel.cs View File

@@ -27,12 +27,15 @@ namespace Discord
public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync() => Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members);
public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset)
=> Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members.Skip(offset).Take(limit).ToImmutableArray());
public CachedGuildUser GetUser(ulong id)
public CachedGuildUser GetUser(ulong id, bool skipCheck = false)
{
//TODO: It's slow to do a perms check here... Maybe only do it on external calls?
var user = Guild.GetUser(id);
if (user != null && Permissions.GetValue(Permissions.ResolveChannel(user, this, user.GuildPermissions.RawValue), ChannelPermission.ReadMessages))
return user;
if (user != null && !skipCheck)
{
ulong perms = Permissions.ResolveChannel(user, this, user.GuildPermissions.RawValue);
if (Permissions.GetValue(perms, ChannelPermission.ReadMessages))
return user;
}
return null;
}

@@ -69,7 +72,7 @@ namespace Discord
IReadOnlyCollection<ICachedUser> ICachedMessageChannel.Members => Members;

IMessage IMessageChannel.GetCachedMessage(ulong id) => GetMessage(id);
ICachedUser ICachedMessageChannel.GetUser(ulong id) => GetUser(id);
ICachedUser ICachedMessageChannel.GetUser(ulong id, bool skipCheck) => GetUser(id, skipCheck);
ICachedChannel ICachedChannel.Clone() => Clone();
}
}

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

@@ -11,6 +11,6 @@ namespace Discord
CachedMessage GetMessage(ulong id);
CachedMessage RemoveMessage(ulong id);

ICachedUser GetUser(ulong id);
ICachedUser GetUser(ulong id, bool skipCheck = false);
}
}

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

@@ -120,7 +120,7 @@ namespace Discord
var guild = (_channel as ICachedGuildChannel).Guild;
return cachedMessages.Concat(downloadedMessages.Select(x =>
{
IUser user = _channel.GetUser(x.Author.Value.Id);
IUser user = _channel.GetUser(x.Author.Value.Id, true);
if (user == null)
{
var newUser = new User(_channel.Discord, x.Author.Value);


+ 1
- 1
src/Discord.Net/Net/Rest/DefaultRestClient.cs View File

@@ -92,7 +92,7 @@ namespace Discord.Net.Rest
{
foreach (var p in multipartParams)
{
//TODO: C# Typeswitch candidate
//TODO: C#7 Typeswitch candidate
var stringValue = p.Value as string;
if (stringValue != null) { content.Add(new StringContent(stringValue), p.Key); continue; }
var byteArrayValue = p.Value as byte[];


+ 1
- 2
src/Discord.Net/Net/WebSockets/DefaultWebsocketClient.cs View File

@@ -124,8 +124,7 @@ namespace Discord.Net.WebSockets
_sendLock.Release();
}
}

//TODO: Check this code
private async Task RunAsync(CancellationToken cancelToken)
{
var buffer = new ArraySegment<byte>(new byte[ReceiveChunkSize]);


Loading…
Cancel
Save