Browse Source

Fixed a login crash bug, fixed permissions resolving twice during READY

tags/docs-0.9
RogueException 9 years ago
parent
commit
d68e699556
4 changed files with 36 additions and 40 deletions
  1. +2
    -2
      src/Discord.Net/DiscordClient.cs
  2. +2
    -7
      src/Discord.Net/Models/Channel.cs
  3. +11
    -7
      src/Discord.Net/Models/Role.cs
  4. +21
    -24
      src/Discord.Net/Models/Server.cs

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

@@ -714,7 +714,7 @@ namespace Discord
if (server != null)
{
var role = server.AddRole(data.Data.Id);
role.Update(data.Data);
role.Update(data.Data, false);
Logger.Debug($"GUILD_ROLE_CREATE: {role.Path}");
OnRoleCreated(role);
}
@@ -732,7 +732,7 @@ namespace Discord
if (role != null)
{
var before = Config.EnablePreUpdateEvents ? role.Clone() : null;
role.Update(data.Data);
role.Update(data.Data, true);
Logger.Debug($"GUILD_ROLE_UPDATE: {role.Path}");
OnRoleUpdated(before, role);
}


+ 2
- 7
src/Discord.Net/Models/Channel.cs View File

@@ -141,18 +141,13 @@ namespace Discord
if (client.Config.MessageCacheSize > 0)
_messages = new ConcurrentDictionary<ulong, Message>(2, (int)(client.Config.MessageCacheSize * 1.05));
}
internal void Update(ChannelReference model)
internal void Update(APIChannel model)
{
if (!IsPrivate && model.Name != null)
Name = model.Name;
if (model.Type != null)
Type = model.Type;
}
internal void Update(APIChannel model)
{
Update(model as ChannelReference);

if (model.Position != null)
Position = model.Position.Value;
if (model.Topic != null)


+ 11
- 7
src/Discord.Net/Models/Role.cs View File

@@ -52,9 +52,9 @@ namespace Discord
Color = new Color(0);
}

internal void Update(APIRole model)
internal void Update(APIRole model, bool updatePermissions)
{
if (model.Name != null)
if (model.Name != null)
Name = model.Name;
if (model.Hoist != null)
IsHoisted = model.Hoist.Value;
@@ -64,11 +64,15 @@ namespace Discord
Position = model.Position.Value;
if (model.Color != null)
Color = new Color(model.Color.Value);
if (model.Permissions != null)
Permissions = new ServerPermissions(model.Permissions.Value);

foreach (var member in Members)
Server.UpdatePermissions(member);
if (model.Permissions != null)
{
Permissions = new ServerPermissions(model.Permissions.Value);
if (updatePermissions) //Dont update these during READY
{
foreach (var member in Members)
Server.UpdatePermissions(member);
}
}
}
public async Task Edit(string name = null, ServerPermissions? permissions = null, Color color = null, bool? isHoisted = null, int? position = null)


+ 21
- 24
src/Discord.Net/Models/Server.cs View File

@@ -57,10 +57,6 @@ namespace Discord

/// <summary> Gets the unique identifier for this server. </summary>
public ulong Id { get; }
/// <summary> Gets the default channel for this server. </summary>
public Channel DefaultChannel { get; }
/// <summary> Gets the the role representing all users in a server. </summary>
public Role EveryoneRole { get; }

/// <summary> Gets the name of this server. </summary>
public string Name { get; private set; }
@@ -74,6 +70,10 @@ namespace Discord
public int AFKTimeout { get; private set; }
/// <summary> Gets the date and time you joined this server. </summary>
public DateTime JoinedAt { get; private set; }
/// <summary> Gets the default channel for this server. </summary>
public Channel DefaultChannel { get; private set; }
/// <summary> Gets the the role representing all users in a server. </summary>
public Role EveryoneRole { get; private set; }
/// <summary> Gets all extra features added to this server. </summary>
public IEnumerable<string> Features { get; private set; }
/// <summary> Gets all custom emojis on this server. </summary>
@@ -116,20 +116,12 @@ namespace Discord
{
Client = client;
Id = id;

DefaultChannel = AddChannel(id);
EveryoneRole = AddRole(id);
}
internal void Update(GuildReference model)
internal void Update(Guild model)
{
if (model.Name != null)
Name = model.Name;
}
internal void Update(Guild model)
{
Update(model as GuildReference);

if (model.AFKTimeout != null)
AFKTimeout = model.AFKTimeout.Value;
if (model.JoinedAt != null)
@@ -142,7 +134,17 @@ namespace Discord
IconId = model.Icon;
if (model.Features != null)
Features = model.Features;
if (model.Emojis != null)
if (model.Roles != null)
{
_roles = new ConcurrentDictionary<ulong, Role>(2, model.Roles.Length);
foreach (var x in model.Roles)
{
var role = AddRole(x.Id);
role.Update(x, false);
}
EveryoneRole = _roles[Id];
}
if (model.Emojis != null) //Needs Roles
{
CustomEmojis = model.Emojis.Select(x => new Emoji(x.Id)
{
@@ -152,12 +154,6 @@ namespace Discord
Roles = x.RoleIds.Select(y => GetRole(y)).Where(y => y != null).ToArray()
}).ToArray();
}
if (model.Roles != null)
{
_roles = new ConcurrentDictionary<ulong, Role>(2, model.Roles.Length);
foreach (var x in model.Roles)
AddRole(x.Id).Update(x);
}

//Can be null
_afkChannelId = model.AFKChannelId;
@@ -165,14 +161,15 @@ namespace Discord
}
internal void Update(ExtendedGuild model)
{
Update(model as Guild);

if (model.Channels != null)
{
_channels = new ConcurrentDictionary<ulong, Channel>(2, (int)(model.Channels.Length * 1.05));
foreach (var subModel in model.Channels)
AddChannel(subModel.Id).Update(subModel);
DefaultChannel = _channels[Id];
}
Update(model as Guild); //Needs channels

if (model.Members != null)
{
_users = new ConcurrentDictionary<ulong, Member>(2, (int)(model.Members.Length * 1.05));
@@ -368,7 +365,7 @@ namespace Discord
var createRequest = new CreateRoleRequest(Id);
var createResponse = await Client.ClientAPI.Send(createRequest).ConfigureAwait(false);
var role = AddRole(createResponse.Id);
role.Update(createResponse);
role.Update(createResponse, false);

var editRequest = new UpdateRoleRequest(role.Server.Id, role.Id)
{
@@ -378,7 +375,7 @@ namespace Discord
IsHoisted = isHoisted
};
var editResponse = await Client.ClientAPI.Send(editRequest).ConfigureAwait(false);
role.Update(editResponse);
role.Update(editResponse, true);

return role;
}


Loading…
Cancel
Save