Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Cached Channel now get updated if a new message is sent
Browse files Browse the repository at this point in the history
updated the pom.xml
  • Loading branch information
JoshiCodes committed Jun 9, 2023
1 parent 3bee0f3 commit 08664f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.joshicodes</groupId>
<artifactId>rja</artifactId>
<version>1.0-alpha.8d</version>
<version>1.0-alpha.8e</version>

<description>
Simple Java API for Revolt.
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/de/joshicodes/rja/object/channel/GenericChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -38,6 +39,16 @@ public static GenericChannel from(final RJA rja, final JsonObject object) {

abstract public ChannelType getType();

public RestAction<GenericChannel> fetch() {
return new RestAction<GenericChannel>(getRJA()) {
@Override
protected GenericChannel execute() {
FetchChannelRequest request = new FetchChannelRequest(getId());
return getRJA().getRequestHandler().sendRequest(getRJA(), request);
}
};
}

@Override
public String getAsMention() {
return "<#" + getId() + ">";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit 08664f7

Please sign in to comment.