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 1 commit
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
6 changes: 3 additions & 3 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,7 @@ 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);
return entityBuilder.createApplicationEmoji(this, obj, true);
Xirado marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand All @@ -710,7 +710,7 @@ public RestAction<List<ApplicationEmoji>> retrieveApplicationEmojis()
{
try
{
list.add(entityBuilder.createApplicationEmoji(this, emojis.getObject(i)));
list.add(entityBuilder.createApplicationEmoji(this, emojis.getObject(i), false));
}
catch (ParsingException e)
{
Expand All @@ -729,7 +729,7 @@ 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())
(response, request) -> entityBuilder.createApplicationEmoji(this, response.getObject(), false)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,10 +1021,15 @@ 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, boolean newlyCreated)
{
final long emojiId = json.getUnsignedLong("id");
final User user = createUser(json.getObject("user"));
final User user = newlyCreated
? api.getSelfUser()
: json.optObject("user")
.map(this::createUser)
.orElse(null);

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