Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 42 additions & 2 deletions src/API/Status/PreviewCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}
Expand All @@ -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;
Copy link
Copy Markdown
Contributor

@Rafostar Rafostar May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for information, this is fine cause it might save you from calling .substring (4) below in a (I guess rare) situation where Clapper is compiled without this option, so you can leave it as-is. But other than that (including compiled with but none installed) it is perfectly safe for applications to call Clapper.get_global_enhancer_proxies() - in this case returned GListModel will simply have zero elements and for loop would not execute.

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":
Expand Down