Updated functionality to add files into filelist of new peer. (I know it's not beautiful but atm time is limited)

This commit is contained in:
WickedJack99
2024-04-22 21:56:45 +02:00
parent cb63c6e9ef
commit 1b18713d06

View File

@@ -277,10 +277,25 @@ public class FileReaderWriter {
}
if (containsPeer == false) {
JSONObject peerObject = new JSONObject(
String newPeerAsString =
"{\"ipAddress\":\"" + peerToUpdate.ipAddress() +
"\",\"port\":" + peerToUpdate.port() +
",\"files\":[],\"onlineStatus\":\"offline\"}");
",\"files\":[";
if (peerToUpdate.filesMap() != null) {
for (Map.Entry<String, String> file : peerToUpdate.filesMap().entrySet()) {
JSONObject fileObject = new JSONObject();
fileObject.put("fileName", file.getKey());
fileObject.put("filePath", file.getValue());
newPeerAsString += fileObject.toString() + ",";
}
// Remove last comma if fileList contains at least one file that has name of one char
if (newPeerAsString.endsWith(",")) {
newPeerAsString = newPeerAsString.substring(0, newPeerAsString.length() - 1);
}
}
newPeerAsString += "],\"onlineStatus\":\"" + peerToUpdate.onlineStateToString() + "\"}";
JSONObject peerObject = new JSONObject(newPeerAsString);
peersJSONArray.put(peerObject);
}