minor optimization + make sure top level components are action rows (#2991)

This commit is contained in:
Mihail Gribkov
2024-08-30 23:34:15 +03:00
committed by GitHub
parent 466b491c3c
commit 623a45765d
5 changed files with 9 additions and 7 deletions

View File

@@ -82,7 +82,7 @@ internal class Message
public Optional<Message> ReferencedMessage { get; set; } public Optional<Message> ReferencedMessage { get; set; }
[JsonProperty("components")] [JsonProperty("components")]
public Optional<ActionRowComponent[]> Components { get; set; } public Optional<IMessageComponent[]> Components { get; set; }
[JsonProperty("interaction")] [JsonProperty("interaction")]
public Optional<MessageInteraction> Interaction { get; set; } public Optional<MessageInteraction> Interaction { get; set; }

View File

@@ -171,7 +171,8 @@ namespace Discord.Rest
if (model.Components.IsSpecified) 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) switch (y.Type)
{ {

View File

@@ -198,7 +198,7 @@ namespace Discord.Rest
Content = (data.Content.IsSpecified && data.Content.Value == null) ? Optional<string>.Unspecified : data.Content, Content = (data.Content.IsSpecified && data.Content.Value == null) ? Optional<string>.Unspecified : data.Content,
Embeds = data.Embeds, Embeds = data.Embeds,
AllowedMentions = data.AllowedMentions, AllowedMentions = data.AllowedMentions,
Components = data.Components, Components = data.Components.GetValueOrDefault(Array.Empty<API.ActionRowComponent>()),
Flags = data.Flags, Flags = data.Flags,
}; };

View File

@@ -204,7 +204,8 @@ namespace Discord.WebSocket
if (model.Components.IsSpecified) 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) switch (y.Type)
{ {

View File

@@ -152,7 +152,7 @@ namespace Discord.WebSocket
{ {
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model)); var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model));
entity.Update(state, model); entity.Update(state, model);
entity.UpdateRoles(new ulong[0]); entity.UpdateRoles([]);
return entity; return entity;
} }
internal static SocketGuildUser Create(SocketGuild guild, ClientState state, MemberModel model) internal static SocketGuildUser Create(SocketGuild guild, ClientState state, MemberModel model)
@@ -160,7 +160,7 @@ namespace Discord.WebSocket
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User)); var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User));
entity.Update(state, model); entity.Update(state, model);
if (!model.Roles.IsSpecified) if (!model.Roles.IsSpecified)
entity.UpdateRoles(new ulong[0]); entity.UpdateRoles([]);
return entity; return entity;
} }
internal static SocketGuildUser Create(SocketGuild guild, ClientState state, PresenceModel model) internal static SocketGuildUser Create(SocketGuild guild, ClientState state, PresenceModel model)
@@ -168,7 +168,7 @@ namespace Discord.WebSocket
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User)); var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User));
entity.Update(state, model, false); entity.Update(state, model, false);
if (!model.Roles.IsSpecified) if (!model.Roles.IsSpecified)
entity.UpdateRoles(new ulong[0]); entity.UpdateRoles([]);
return entity; return entity;
} }
internal void Update(ClientState state, MemberModel model) internal void Update(ClientState state, MemberModel model)