diff --git a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java index e8b9a623bd..eca23f512e 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java @@ -1217,7 +1217,7 @@ public PrivateChannel createPrivateChannel(DataObject json, UserImpl user) if (recipient != null) { //update the channel if we have found the user - channel.setUser(user); + channel.setUser(recipient); } } if (recipient != null) @@ -1363,17 +1363,34 @@ public ReceivedMessage createMessage(DataObject jsonObject, @Nullable MessageCha final long authorId = author.getLong("id"); MemberImpl member = null; - if (channel == null && jsonObject.isNull("guild_id")) + if (jsonObject.isNull("guild_id")) { - DataObject channelData = DataObject.empty() - .put("id", channelId); - //if we see an author that isn't us, we can assume that is the other side of this private channel - //if the author is us, we learn no information about the user at the other end - if (authorId != getJDA().getSelfUser().getIdLong()) + //we know it's a private channel + PrivateChannelImpl priv = (PrivateChannelImpl) channel; + + boolean isAuthorSelfUser = authorId == getJDA().getSelfUser().getIdLong(); + if (priv == null) + { + DataObject channelData = DataObject.empty() + .put("id", channelId); + + //if we see an author that isn't us, we can assume that is the other side of this private channel + //if the author is us, we learn no information about the user at the other end + if (!isAuthorSelfUser) channelData.put("recipient", author); - //even without knowing the user at the other end, we can still construct a minimal channel - channel = createPrivateChannel(channelData); + + //even without knowing the user at the other end, we can still construct a minimal channel + channel = createPrivateChannel(channelData); + } + else if (priv.getUser() == null && !isAuthorSelfUser) + { + //if we see an author that isn't us, we can assume that is the other side of this private channel + //if the author is us, we learn no information about the user at the other end + priv.setUser(createUser(author)); + } + } + else if (channel == null) throw new IllegalArgumentException(MISSING_CHANNEL); diff --git a/src/main/java/net/dv8tion/jda/internal/entities/PrivateChannelImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/PrivateChannelImpl.java index 8b6d331510..0b94190e64 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/PrivateChannelImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/PrivateChannelImpl.java @@ -184,6 +184,9 @@ public String toString() private void updateUser() { + //if the user is null then we don't even know their ID, and so we have to check that first + if (user == null) + return; // Load user from cache if one exists, otherwise we might have an outdated user instance User realUser = getJDA().getUserById(user.getIdLong()); if (realUser != null) diff --git a/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java index 7f0a423467..6de60fa586 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java @@ -25,6 +25,7 @@ import net.dv8tion.jda.internal.entities.EmoteImpl; import net.dv8tion.jda.internal.entities.GuildImpl; import net.dv8tion.jda.internal.entities.MemberImpl; +import net.dv8tion.jda.internal.entities.PrivateChannelImpl; import net.dv8tion.jda.internal.requests.WebSocketClient; import net.dv8tion.jda.internal.utils.JDALogger; @@ -168,7 +169,15 @@ protected Long handleInternally(DataObject content) MessageReaction reaction = new MessageReaction(channel, rEmote, messageId, userId == api.getSelfUser().getIdLong(), -1); if (channel.getType() == ChannelType.PRIVATE) + { api.usedPrivateChannel(reaction.getChannel().getIdLong()); + PrivateChannelImpl priv = (PrivateChannelImpl) channel; + //try to add the user here if we need to, as we have their ID + if (priv.getUser() == null && user != null) + { + priv.setUser(user); + } + } if (add) {