Skip to content

Commit

Permalink
minor optimization + make sure top level components are action rows (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha-133 authored Aug 30, 2024
1 parent 466b491 commit 623a457
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Discord.Net.Rest/API/Common/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal class Message
public Optional<Message> ReferencedMessage { get; set; }

[JsonProperty("components")]
public Optional<ActionRowComponent[]> Components { get; set; }
public Optional<IMessageComponent[]> Components { get; set; }

[JsonProperty("interaction")]
public Optional<MessageInteraction> Interaction { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ internal virtual void Update(Model model)

if (model.Components.IsSpecified)
{
Components = model.Components.Value.Select(x => new ActionRowComponent(x.Components.Select<IMessageComponent, IMessageComponent>(y =>
Components = model.Components.Value.Where(x => x.Type is ComponentType.ActionRow)
.Select(x => new ActionRowComponent(((API.ActionRowComponent)x).Components.Select<IMessageComponent, IMessageComponent>(y =>
{
switch (y.Type)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Discord.Net.Rest/Extensions/EntityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static API.Message ToMessage(this API.InteractionResponse model, IDiscord
Content = (data.Content.IsSpecified && data.Content.Value == null) ? Optional<string>.Unspecified : data.Content,
Embeds = data.Embeds,
AllowedMentions = data.AllowedMentions,
Components = data.Components,
Components = data.Components.GetValueOrDefault(Array.Empty<API.ActionRowComponent>()),
Flags = data.Flags,
};

Expand Down
3 changes: 2 additions & 1 deletion src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ internal virtual void Update(ClientState state, Model model)

if (model.Components.IsSpecified)
{
Components = model.Components.Value.Select(x => new ActionRowComponent(x.Components.Select<IMessageComponent, IMessageComponent>(y =>
Components = model.Components.Value.Where(x => x.Type is ComponentType.ActionRow)
.Select(x => new ActionRowComponent(((API.ActionRowComponent)x).Components.Select<IMessageComponent, IMessageComponent>(y =>
{
switch (y.Type)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,23 @@ internal static SocketGuildUser Create(SocketGuild guild, ClientState state, Use
{
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model));
entity.Update(state, model);
entity.UpdateRoles(new ulong[0]);
entity.UpdateRoles([]);
return entity;
}
internal static SocketGuildUser Create(SocketGuild guild, ClientState state, MemberModel model)
{
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User));
entity.Update(state, model);
if (!model.Roles.IsSpecified)
entity.UpdateRoles(new ulong[0]);
entity.UpdateRoles([]);
return entity;
}
internal static SocketGuildUser Create(SocketGuild guild, ClientState state, PresenceModel model)
{
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User));
entity.Update(state, model, false);
if (!model.Roles.IsSpecified)
entity.UpdateRoles(new ulong[0]);
entity.UpdateRoles([]);
return entity;
}
internal void Update(ClientState state, MemberModel model)
Expand Down

0 comments on commit 623a457

Please sign in to comment.