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 { 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() Request req = new Request.Builder()
.url(modelUrl) .url(modelUrl)
.header(ACCEPT, MIMETYPE_APPLICATION_JSON) .header(ACCEPT, MIMETYPE_APPLICATION_JSON)
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage()) .header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST) .header(REFERER, getUrl())
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent) .header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
.build(); .build();
try (Response response = site.getHttpClient().execute(req)) { try (Response response = site.getHttpClient().execute(req)) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
JSONObject result = new JSONObject(response.body().string()); String body = response.body().string();
if (result.optBoolean(STATUS)) { try {
JSONObject chat = result.getJSONObject("user").getJSONObject("chat"); JSONObject result = new JSONObject(body);
JSONObject chat = result.getJSONObject("chat");
String status = chat.getString(STATUS); String status = chat.getString(STATUS);
setOnlineStateByStatus(status); setOnlineStateByStatus(status);
} else { } catch (JSONException e) {
throw new IOException("Result was not ok"); throw new IOException("Couldn't parse body as JSON:\n" + body, e);
} }
} else throw new HttpException(response.code(), response.message()); } else throw new HttpException(response.code(), response.message());
} }