From 44b2f47113942e654d6bec8894d9a4c0222119c9 Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Fri, 23 May 2025 08:08:09 +0300 Subject: [PATCH 1/3] feat(clapper): prepare for 0.10 --- meson.build | 3 ++ src/API/Status/PreviewCard.vala | 53 +++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 697f20ece..b5bfb4a01 100644 --- a/meson.build +++ b/meson.build @@ -101,6 +101,9 @@ endif if clapper_dep.found () and clapper_gtk_dep.found () add_project_arguments(['--define=CLAPPER'], language: 'vala') + if clapper_dep.version().version_compare('>=0.10') + add_project_arguments(['--define=CLAPPER_0_10'], language: 'vala') + endif if (clapper_dep.get_variable('features').split().contains('mpris')) add_project_arguments(['--define=CLAPPER_MPRIS'], language: 'vala') endif diff --git a/src/API/Status/PreviewCard.vala b/src/API/Status/PreviewCard.vala index 0f97dcf08..4018f9576 100644 --- a/src/API/Status/PreviewCard.vala +++ b/src/API/Status/PreviewCard.vala @@ -95,7 +95,11 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable { if (_special_card == null) { if (is_peertube) { #if CLAPPER - if (Clapper.enhancer_check (typeof (Clapper.Extractable), "peertube", null, null)) { + #if CLAPPER_0_10 + if (enhancer_check ("peertube")) { + #else + if (Clapper.enhancer_check (typeof (Clapper.Extractable), "peertube", null, null)) { + #endif _special_card = CardSpecialType.PEERTUBE; } else { _special_card = CardSpecialType.BASIC; @@ -111,7 +115,11 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable { _special_card = CardSpecialType.BASIC; #if CLAPPER // TODO: maybe limit to https only - if (Clapper.enhancer_check (typeof (Clapper.Extractable), this.tuba_uri.get_scheme (), this.tuba_uri.get_host (), null)) + #if CLAPPER_0_10 + if (enhancer_check (this.tuba_uri.get_scheme (), this.tuba_uri.get_host ())) + #else + if (Clapper.enhancer_check (typeof (Clapper.Extractable), this.tuba_uri.get_scheme (), this.tuba_uri.get_host (), null)) + #endif _special_card = CardSpecialType.CLAPPER; #endif } @@ -121,6 +129,47 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable { } } + #if CLAPPER_0_10 + private bool enhancer_check (string scheme, string? t_host = null) { + if (!Clapper.WITH_ENHANCERS_LOADER) return false; + bool supported = false; + + string? host = t_host; + if (host != null && host.has_prefix ("www.")) host = host.substring (4); + + var proxies = Clapper.get_global_enhancer_proxies (); + for (var i = 0; i < proxies.get_n_proxies (); i++) { + var proxy = proxies.get_proxy (i); + + string? proxy_schemes = proxy.get_extra_data ("X-Schemes"); + if (proxy_schemes == null || proxy_schemes == "") continue; + + string[] schemes = proxy_schemes.split (";"); + if (!(scheme in schemes)) continue; + + // We were only looking for scheme matching + // e.g. peertube:// + if (host == null) { + supported = true; + break; + } + + string? proxy_hosts = proxy.get_extra_data ("X-Hosts"); + if (proxy_hosts == null || proxy_hosts == "") continue; + + string[] hosts = proxy_hosts.split (";"); + // both the host and the scheme + // match at this point + if (host in hosts) { + supported = true; + break; + } + } + + return supported; + } + #endif + public override Type deserialize_array_type (string prop) { switch (prop) { case "history": From b29d25e6b4a0de5f22fac02af7661565bbc3263a Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Sat, 24 May 2025 04:32:45 +0300 Subject: [PATCH 2/3] fix: optimize lookups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafał Dzięgiel --- src/API/Status/PreviewCard.vala | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/API/Status/PreviewCard.vala b/src/API/Status/PreviewCard.vala index 4018f9576..68772ad81 100644 --- a/src/API/Status/PreviewCard.vala +++ b/src/API/Status/PreviewCard.vala @@ -139,14 +139,9 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable { var proxies = Clapper.get_global_enhancer_proxies (); for (var i = 0; i < proxies.get_n_proxies (); i++) { - var proxy = proxies.get_proxy (i); - - string? proxy_schemes = proxy.get_extra_data ("X-Schemes"); - if (proxy_schemes == null || proxy_schemes == "") continue; - - string[] schemes = proxy_schemes.split (";"); - if (!(scheme in schemes)) continue; + var proxy = proxies.peek_proxy (i); + if (!proxy.extra_data_lists_value ("X-Schemes", scheme)) continue; // We were only looking for scheme matching // e.g. peertube:// if (host == null) { @@ -154,16 +149,11 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable { break; } - string? proxy_hosts = proxy.get_extra_data ("X-Hosts"); - if (proxy_hosts == null || proxy_hosts == "") continue; - - string[] hosts = proxy_hosts.split (";"); + if (!proxy.extra_data_lists_value ("X-Hosts", host)) continue; // both the host and the scheme // match at this point - if (host in hosts) { - supported = true; - break; - } + supported = true; + break; } return supported; From f0955f1d717b4a5e593707a1ef03f63dfa720050 Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Sat, 24 May 2025 04:39:15 +0300 Subject: [PATCH 3/3] feat: check proxy interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafał Dzięgiel --- src/API/Status/PreviewCard.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/API/Status/PreviewCard.vala b/src/API/Status/PreviewCard.vala index 68772ad81..61abfcc9b 100644 --- a/src/API/Status/PreviewCard.vala +++ b/src/API/Status/PreviewCard.vala @@ -140,6 +140,7 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable { var proxies = Clapper.get_global_enhancer_proxies (); for (var i = 0; i < proxies.get_n_proxies (); i++) { var proxy = proxies.peek_proxy (i); + if (!proxy.target_has_interface (typeof (Clapper.Extractable))) continue; if (!proxy.extra_data_lists_value ("X-Schemes", scheme)) continue; // We were only looking for scheme matching