Fix online check for Camsoda

This commit is contained in:
0xb00bface 2021-06-26 17:52:01 +02:00
parent adbb1bd562
commit c5e20a40e7
1 changed files with 8 additions and 7 deletions

View File

@ -160,23 +160,24 @@ public class CamsodaModel extends AbstractModel {
}
private void loadModel() throws IOException {
String modelUrl = site.getBaseUrl() + "/api/v1/user/" + getName();
String modelUrl = site.getBaseUrl() + "/api/v1/chat/react/" + getName();
Request req = new Request.Builder()
.url(modelUrl)
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
.header(REFERER, getUrl())
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
.build();
try (Response response = site.getHttpClient().execute(req)) {
if (response.isSuccessful()) {
JSONObject result = new JSONObject(response.body().string());
if (result.optBoolean(STATUS)) {
JSONObject chat = result.getJSONObject("user").getJSONObject("chat");
String body = response.body().string();
try {
JSONObject result = new JSONObject(body);
JSONObject chat = result.getJSONObject("chat");
String status = chat.getString(STATUS);
setOnlineStateByStatus(status);
} else {
throw new IOException("Result was not ok");
} catch (JSONException e) {
throw new IOException("Couldn't parse body as JSON:\n" + body, e);
}
} else throw new HttpException(response.code(), response.message());
}