Skip to content

Commit

Permalink
Handle user in EntityBuilder#createApplicationEmoji as optional (#2769)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xirado authored Nov 10, 2024
1 parent 51f907c commit 411d0c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
22 changes: 17 additions & 5 deletions src/main/java/net/dv8tion/jda/internal/JDAImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ public RestAction<ApplicationEmoji> createApplicationEmoji(@Nonnull String name,
return new RestActionImpl<>(this, route, body, (response, request) ->
{
final DataObject obj = response.getObject();
return entityBuilder.createApplicationEmoji(this, obj);
final User selfUser = getSelfUser();
return entityBuilder.createApplicationEmoji(this, obj, selfUser);
});
}

Expand All @@ -710,7 +711,12 @@ public RestAction<List<ApplicationEmoji>> retrieveApplicationEmojis()
{
try
{
list.add(entityBuilder.createApplicationEmoji(this, emojis.getObject(i)));
final DataObject emoji = emojis.getObject(i);
final User owner = emoji.optObject("user")
.map(entityBuilder::createUser)
.orElse(null);

list.add(entityBuilder.createApplicationEmoji(this, emoji, owner));
}
catch (ParsingException e)
{
Expand All @@ -728,9 +734,15 @@ public RestAction<ApplicationEmoji> retrieveApplicationEmojiById(@Nonnull String
{
Checks.isSnowflake(emojiId);
Route.CompiledRoute route = Route.Applications.GET_APPLICATION_EMOJI.compile(getSelfUser().getApplicationId(), emojiId);
return new RestActionImpl<>(this, route,
(response, request) -> entityBuilder.createApplicationEmoji(this, response.getObject())
);
return new RestActionImpl<>(this, route, (response, request) ->
{
final DataObject emoji = response.getObject();
final User owner = emoji.optObject("user")
.map(entityBuilder::createUser)
.orElse(null);

return entityBuilder.createApplicationEmoji(this, emoji, owner);
});
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,11 @@ public RichCustomEmojiImpl createEmoji(GuildImpl guildObj, DataObject json)
.setAvailable(json.getBoolean("available", true));
}

public ApplicationEmojiImpl createApplicationEmoji(JDAImpl api, DataObject json)
public ApplicationEmojiImpl createApplicationEmoji(JDAImpl api, DataObject json, User owner)
{
final long emojiId = json.getUnsignedLong("id");
final User user = createUser(json.getObject("user"));
return new ApplicationEmojiImpl(emojiId, api, user)

return new ApplicationEmojiImpl(emojiId, api, owner)
.setAnimated(json.getBoolean("animated"))
.setName(json.getString("name"));
}
Expand Down

0 comments on commit 411d0c5

Please sign in to comment.