diff --git a/pom.xml b/pom.xml index ba3c93f..625bbd4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.joshicodes rja - 1.0-alpha.8d + 1.0-alpha.8e Simple Java API for Revolt. diff --git a/src/main/java/de/joshicodes/rja/object/channel/GenericChannel.java b/src/main/java/de/joshicodes/rja/object/channel/GenericChannel.java index 142c6df..98458a1 100644 --- a/src/main/java/de/joshicodes/rja/object/channel/GenericChannel.java +++ b/src/main/java/de/joshicodes/rja/object/channel/GenericChannel.java @@ -4,6 +4,7 @@ import de.joshicodes.rja.RJA; import de.joshicodes.rja.object.IMentionable; import de.joshicodes.rja.object.message.MessageReceiver; +import de.joshicodes.rja.requests.rest.channel.info.FetchChannelRequest; import de.joshicodes.rja.rest.RestAction; import de.joshicodes.rja.util.JsonUtil; @@ -38,6 +39,16 @@ public static GenericChannel from(final RJA rja, final JsonObject object) { abstract public ChannelType getType(); + public RestAction fetch() { + return new RestAction(getRJA()) { + @Override + protected GenericChannel execute() { + FetchChannelRequest request = new FetchChannelRequest(getId()); + return getRJA().getRequestHandler().sendRequest(getRJA(), request); + } + }; + } + @Override public String getAsMention() { return "<#" + getId() + ">"; diff --git a/src/main/java/de/joshicodes/rja/requests/rest/message/MessageSendRequest.java b/src/main/java/de/joshicodes/rja/requests/rest/message/MessageSendRequest.java index 8eb74d6..6ad9589 100644 --- a/src/main/java/de/joshicodes/rja/requests/rest/message/MessageSendRequest.java +++ b/src/main/java/de/joshicodes/rja/requests/rest/message/MessageSendRequest.java @@ -15,7 +15,11 @@ public MessageSendRequest(String channel) { public Message fetch(RJA rja, int responseCode, JsonElement data) { if(!data.isJsonObject()) return null; - return Message.from(rja, data.getAsJsonObject(), null); + Message m = Message.from(rja, data.getAsJsonObject(), null); + rja.cacheMessage(m); + // update cached channel + rja.getChannelCache().stream().filter(c -> c.getId().equals(m.getChannelId())).findFirst().ifPresent(c -> rja.cacheChannel(c.fetch().complete())); + return m; } }