Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/main/java/com/lgs/eden/api/auth/LoginResponseData.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String toString() {
"code=" + code +
", userID=" + userID +
", username='" + username + '\'' +
", avatar=" + avatar +
", avatar=" + avatarPath +
'}';
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/lgs/eden/api/nexus/NexusHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.lgs.eden.api.nexus.helpers.RequestObject;
import com.lgs.eden.api.profile.friends.FriendConversationView;
import com.lgs.eden.application.AppWindowHandler;
import com.lgs.eden.utils.Utility;
import io.socket.client.Ack;
import io.socket.client.IO;
import io.socket.client.Socket;
Expand Down Expand Up @@ -84,6 +85,12 @@ private NexusHandler(Socket socket) {
((ImpSocket)this.callback).setParent(this);
((ImpSocket)this.games).setParent(this);
((ImpSocket)this.profile).setParent(this);

socket.on("avatar-changed", args -> {
if (args.length == 1 && args[0] instanceof String avatarPath){
Utility.reloadImage(avatarPath);
}
});
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/lgs/eden/utils/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public final class Utility {
*/
public static Image loadImage(String path) throws NullPointerException {
if (images.containsKey(path)) return images.get(path);
return reloadImage(path);
}

public static Image reloadImage(String path) {
try {
if (path.startsWith("/")) images.put(path, new Image(Objects.requireNonNull(Utility.class.getResourceAsStream(path))));
else images.put(path, new Image(path));
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/lgs/eden/views/profile/EditProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

/**
* Edit profile view
Expand Down Expand Up @@ -108,6 +109,10 @@ private void onSubmitChanges(){
} else {
try {
LoginResponseData d = API.imp.editProfile(newUsername, newAvatar, newDesc);
// clear cache
if(!Objects.equals(d.avatarPath, "null")) {
Utility.reloadImage(d.avatarPath);
}
AppWindowHandler.updateLoginResponse(d);
// go back
AppWindowHandler.setScreen(Profile.getScreen(), ViewsPath.PROFILE);
Expand Down