From c91b7bee1f6b8a5ac34864cd05373b7d700aad48 Mon Sep 17 00:00:00 2001 From: jafea7 Date: Sun, 30 Mar 2025 16:58:27 +1100 Subject: [PATCH] Fix BC online check (reusedname) --- .../ctbrec/sites/bonga/BongaCamsModel.java | 56 +++++++------------ 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/common/src/main/java/ctbrec/sites/bonga/BongaCamsModel.java b/common/src/main/java/ctbrec/sites/bonga/BongaCamsModel.java index 003bccb2..c5c66024 100644 --- a/common/src/main/java/ctbrec/sites/bonga/BongaCamsModel.java +++ b/common/src/main/java/ctbrec/sites/bonga/BongaCamsModel.java @@ -38,7 +38,7 @@ public class BongaCamsModel extends AbstractModel { private static final String SUCCESS = "success"; private static final String STATUS = "status"; - private static final Pattern ONLINE_BADGE_REGEX = Pattern.compile("class=\"badge_online\s*\""); + // private static final Pattern ONLINE_BADGE_REGEX = Pattern.compile("class=\"badge_online\s*\""); @Setter private boolean online = false; @@ -51,13 +51,6 @@ public class BongaCamsModel extends AbstractModel { @Override public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException { if (ignoreCache) { - boolean modelIsConnected = basicOnlineCheck(); - if (!modelIsConnected) { - onlineState = OFFLINE; - online = false; - return false; - } - return completeOnlineCheck(); } return online; @@ -74,44 +67,33 @@ public class BongaCamsModel extends AbstractModel { String chatType = performerData.optString("showType"); boolean isAway = performerData.optBoolean("isAway"); - onlineState = mapState(chatType); - if (onlineState == ONLINE) { - if (isStreamAvailable()) { - if (isAway) { - onlineState = AWAY; - online = false; + // looks like isOnline key is new. Treat it's absence as true (old behavior) + boolean jsonIsOnline = performerData.optBoolean("isOnline", true); + + if (!jsonIsOnline) { + onlineState = OFFLINE; + online = false; + } else { + onlineState = mapState(chatType); + if (onlineState == ONLINE) { + if (isStreamAvailable()) { + if (isAway) { + onlineState = AWAY; + online = false; + } else { + online = true; + } } else { - online = true; + online = false; + onlineState = AWAY; } } else { online = false; - onlineState = AWAY; } - } else { - online = false; } return online; } - private boolean basicOnlineCheck() { - try { - String url = site.getBaseUrl() + "/profile/" + getName().toLowerCase(); - Request req = newRequestBuilder().url(url).build(); - try (Response resp = site.getHttpClient().execute(req)) { - if (resp.isSuccessful()) { - String body = Objects.requireNonNull(resp.body(), HTTP_RESPONSE_BODY_IS_NULL).string(); - Matcher m = ONLINE_BADGE_REGEX.matcher(body); - return m.find(); - } else { - return false; - } - } - } catch (Exception e) { - log.warn("Couldn't check if model is connected: {}", e.getLocalizedMessage()); - return false; - } - } - public State mapState(String roomState) { return switch (roomState) { case "private", "fullprivate" -> PRIVATE;