Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle user in EntityBuilder#createApplicationEmoji as optional #2769

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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