From c2b7568597908fcfdcfaa35f129e90f4340673cd Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 7 Sep 2023 22:10:49 -0500 Subject: [PATCH] Better defaults for OpenGraphParser --- build.gradle | 2 +- .../services/XmppConnectionService.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index bbd6b5310..e7126a8e0 100644 --- a/build.gradle +++ b/build.gradle @@ -119,7 +119,7 @@ dependencies { implementation 'com.caverock:androidsvg-aar:1.4' implementation 'org.tomlj:tomlj:1.1.0' implementation 'com.tbuonomo:dotsindicator:4.2' - implementation 'com.github.Priyansh-Kedia:OpenGraphParser:2.5.5' + implementation 'com.github.Priyansh-Kedia:OpenGraphParser:2.5.6' implementation 'me.xdrop:fuzzywuzzy:1.4.0' // INSERT } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 4fa21fb26..1dc47fd35 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -66,6 +66,7 @@ import com.google.common.base.Optional; import com.google.common.base.Strings; import com.google.common.io.Files; +import com.kedia.ogparser.JsoupProxy; import com.kedia.ogparser.OpenGraphCallback; import com.kedia.ogparser.OpenGraphParser; import com.kedia.ogparser.OpenGraphResult; @@ -1792,9 +1793,9 @@ public class XmppConnectionService extends Service { } }); return; - } else if (response.isSuccessful() && html && !useTorToConnect()) { + } else if (response.isSuccessful() && html) { Semaphore waiter = new Semaphore(0); - new OpenGraphParser(new OpenGraphCallback() { + OpenGraphParser.Builder openGraphBuilder = new OpenGraphParser.Builder(new OpenGraphCallback() { @Override public void onPostResponse(OpenGraphResult result) { Element rdf = new Element("Description", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); @@ -1825,7 +1826,14 @@ public class XmppConnectionService extends Service { public void onError(String error) { waiter.release(); } - }, false, null).parse(link.toString()); + }) + .showNullOnEmpty(false) + .maxBodySize(4000) + .timeout(5000); + if (useTorToConnect()) { + openGraphBuilder = openGraphBuilder.jsoupProxy(new JsoupProxy("127.0.0.1", 8118)); + } + openGraphBuilder.build().parse(link.toString()); waiter.acquire(); } } catch (final IOException | InterruptedException e) { } -- 2.45.2