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..61abfcc9b 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,38 @@ 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.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 + // e.g. peertube:// + if (host == null) { + supported = true; + break; + } + + if (!proxy.extra_data_lists_value ("X-Hosts", host)) continue; + // both the host and the scheme + // match at this point + supported = true; + break; + } + + return supported; + } + #endif + public override Type deserialize_array_type (string prop) { switch (prop) { case "history":