Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PreviewCard): remove dialog #679

Merged
merged 3 commits into from
Dec 17, 2023
Merged
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
117 changes: 53 additions & 64 deletions src/API/Status/PreviewCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -157,72 +157,61 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable {
}

public static void open_special_card (CardSpecialType card_special_type, string card_url) {
app.question.begin (
{card_special_type.to_dialog_title (), false},
{card_special_type.to_dialog_body (card_url), false},
app.main_window,
{ { _("Proceed"), Adw.ResponseAppearance.DESTRUCTIVE}, { _("Cancel"), Adw.ResponseAppearance.DEFAULT } },
false,
(obj, res) => {
if (app.question.end (res).truthy ()) {
if (card_special_type.open_special_card (card_url)) {
return;
};
string special_api_url = "";
string special_host = "";
try {
card_special_type.parse_url (card_url, out special_host, out special_api_url);
} catch {
Host.open_uri (card_url);
return;
}
if (card_special_type.open_special_card (card_url)) {
return;
};
string special_api_url = "";
string special_host = "";
try {
card_special_type.parse_url (card_url, out special_host, out special_api_url);
} catch {
Host.open_uri (card_url);
return;
}


new Request.GET (special_api_url)
.then ((in_stream) => {
bool failed = true;
var parser = Network.get_parser_from_inputstream (in_stream);
var node = network.parse_node (parser);
string res_url = "";
API.BookWyrm? bookwyrm_obj = null;

switch (card_special_type) {
case API.PreviewCard.CardSpecialType.PEERTUBE:
var peertube_obj = API.PeerTube.from (node);

peertube_obj.get_video (card_url, out res_url, out failed);
break;
case API.PreviewCard.CardSpecialType.FUNKWHALE:
var funkwhale_obj = API.Funkwhale.from (node);

funkwhale_obj.get_track (special_host, out res_url, out failed);
break;
case API.PreviewCard.CardSpecialType.BOOKWYRM:
bookwyrm_obj = API.BookWyrm.from (node);
res_url = bookwyrm_obj.id;

if (bookwyrm_obj.title != null && bookwyrm_obj.title != "") failed = false;
break;
default:
assert_not_reached ();
}

if (failed || res_url == "") {
Host.open_uri (card_url);
} else {
if (bookwyrm_obj == null) {
app.main_window.show_media_viewer (res_url, Tuba.Attachment.MediaType.VIDEO, null, 0, null, false, null, card_url, true);
} else {
app.main_window.show_book (bookwyrm_obj, card_url);
}
}
})
.on_error (() => {
Host.open_uri (card_url);
})
.exec ();
new Request.GET (special_api_url)
.then ((in_stream) => {
bool failed = true;
var parser = Network.get_parser_from_inputstream (in_stream);
var node = network.parse_node (parser);
string res_url = "";
API.BookWyrm? bookwyrm_obj = null;

switch (card_special_type) {
case API.PreviewCard.CardSpecialType.PEERTUBE:
var peertube_obj = API.PeerTube.from (node);

peertube_obj.get_video (card_url, out res_url, out failed);
break;
case API.PreviewCard.CardSpecialType.FUNKWHALE:
var funkwhale_obj = API.Funkwhale.from (node);

funkwhale_obj.get_track (special_host, out res_url, out failed);
break;
case API.PreviewCard.CardSpecialType.BOOKWYRM:
bookwyrm_obj = API.BookWyrm.from (node);
res_url = bookwyrm_obj.id;

if (bookwyrm_obj.title != null && bookwyrm_obj.title != "") failed = false;
break;
default:
assert_not_reached ();
}
}
);

if (failed || res_url == "") {
Host.open_uri (card_url);
} else {
if (bookwyrm_obj == null) {
app.main_window.show_media_viewer (res_url, Tuba.Attachment.MediaType.VIDEO, null, 0, null, false, null, card_url, true);
} else {
app.main_window.show_book (bookwyrm_obj, card_url);
}
}
})
.on_error (() => {
Host.open_uri (card_url);
})
.exec ();
}
}