From eff22c2bfc73f3b23e61b4c52111a88ceeb6225c Mon Sep 17 00:00:00 2001
From: Bleak Grey
Date: Sun, 14 Feb 2021 14:49:41 +0300
Subject: [PATCH] Initial Pleroma support (#285)
Co-authored-by: dec05eba <66856951+dec05eba@users.noreply.github.com>
---
src/Dialogs/Compose.vala | 12 ++++++------
src/Dialogs/NewAccount.vala | 10 +++++-----
src/Html.vala | 19 +++++++++++++++++--
src/Request.vala | 11 +++++++++++
src/Widgets/RichLabel.vala | 12 ++++++++----
5 files changed, 47 insertions(+), 17 deletions(-)
diff --git a/src/Dialogs/Compose.vala b/src/Dialogs/Compose.vala
index cc31b52..67787bd 100644
--- a/src/Dialogs/Compose.vala
+++ b/src/Dialogs/Compose.vala
@@ -290,17 +290,17 @@ public class Tootle.Dialogs.Compose : Hdy.Window {
var req = new Request.POST (@"/api/v1/statuses?$media_param")
.with_account (accounts.active)
- .with_param ("visibility", visibility_popover.selected.to_string ())
- .with_param ("status", HtmlUtils.uri_encode (status.content));
+ .with_form_data ("visibility", visibility_popover.selected.to_string ())
+ .with_form_data ("status", status.content);
if (cw_button.active) {
- req.with_param ("sensitive", "true");
- req.with_param ("spoiler_text", HtmlUtils.uri_encode (cw.text));
+ req.with_form_data ("sensitive", "true");
+ req.with_form_data ("spoiler_text", cw.text);
}
if (status.in_reply_to_id != null)
- req.with_param ("in_reply_to_id", status.in_reply_to_id);
+ req.with_form_data ("in_reply_to_id", status.in_reply_to_id);
if (status.in_reply_to_account_id != null)
- req.with_param ("in_reply_to_account_id", status.in_reply_to_account_id);
+ req.with_form_data ("in_reply_to_account_id", status.in_reply_to_account_id);
yield req.await ();
diff --git a/src/Dialogs/NewAccount.vala b/src/Dialogs/NewAccount.vala
index 1c60d40..5353d39 100644
--- a/src/Dialogs/NewAccount.vala
+++ b/src/Dialogs/NewAccount.vala
@@ -3,7 +3,7 @@ using Gtk;
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/dialogs/new_account.ui")]
public class Tootle.Dialogs.NewAccount: Hdy.Window {
- const string scopes = "read%20write%20follow";
+ const string scopes = "read write follow";
protected bool is_working { get; set; default = false; }
protected string? redirect_uri { get; set; }
@@ -131,10 +131,10 @@ public class Tootle.Dialogs.NewAccount: Hdy.Window {
var msg = new Request.POST (@"/api/v1/apps")
.with_account (account)
- .with_param ("client_name", Build.NAME)
- .with_param ("website", Build.WEBSITE)
- .with_param ("scopes", scopes)
- .with_param ("redirect_uris", redirect_uri = setup_redirect_uri ());
+ .with_form_data ("client_name", Build.NAME)
+ .with_form_data ("website", Build.WEBSITE)
+ .with_form_data ("scopes", scopes)
+ .with_form_data ("redirect_uris", redirect_uri = setup_redirect_uri ());
yield msg.await ();
var root = network.parse (msg);
diff --git a/src/Html.vala b/src/Html.vala
index 71db98d..0f6c060 100644
--- a/src/Html.vala
+++ b/src/Html.vala
@@ -23,11 +23,14 @@ public class Tootle.HtmlUtils {
var divided = str
.replace("
", "\n")
.replace("", "")
+ .replace("
", "\n")
.replace("
", "\n")
.replace("", "")
- .replace("
", "\n\n");
+ .replace("
", "\n\n")
+ .replace("", "")
+ .replace("
", "");
- var html_params = new Regex ("(class|target|rel)=\"(.|\n)*?\"", RegexCompileFlags.CASELESS);
+ var html_params = new Regex ("(class|target|rel|data-user|data-tag)=\"(.|\n)*?\"", RegexCompileFlags.CASELESS);
var simplified = html_params.replace (divided, -1, 0, "");
while (simplified.has_suffix ("\n"))
@@ -41,6 +44,18 @@ public class Tootle.HtmlUtils {
}
}
+ public static string replace_with_pango_markup (string str) {
+ return str
+ .replace("", "")
+ .replace("", "")
+ .replace("", "")
+ .replace("", "")
+ .replace("", "")
+ .replace("
", "\n")
+ .replace("", "")
+ .replace("", "");
+ }
+
public static string uri_encode (string str) {
var restored = Widgets.RichLabel.restore_entities (str);
return Soup.URI.encode (restored, ";&+");
diff --git a/src/Request.vala b/src/Request.vala
index 744cb6c..c561248 100644
--- a/src/Request.vala
+++ b/src/Request.vala
@@ -7,6 +7,7 @@ public class Tootle.Request : Soup.Message {
Network.SuccessCallback? cb;
Network.ErrorCallback? error_cb;
HashMap? pars;
+ Soup.Multipart? form_data;
weak InstanceAccount? account;
bool needs_token = false;
@@ -67,6 +68,13 @@ public class Tootle.Request : Soup.Message {
return this;
}
+ public Request with_form_data (string name, string val) {
+ if (form_data == null)
+ form_data = new Soup.Multipart(FORM_MIME_TYPE_MULTIPART);
+ form_data.append_form_string(name, val);
+ return this;
+ }
+
public Request exec () {
var parameters = "";
if (pars != null) {
@@ -89,6 +97,9 @@ public class Tootle.Request : Soup.Message {
});
}
+ if (form_data != null)
+ form_data.to_message(request_headers, request_body);
+
if (needs_token) {
if (account == null) {
warning (@"No account was specified or found for $method: $url$parameters");
diff --git a/src/Widgets/RichLabel.vala b/src/Widgets/RichLabel.vala
index 64a27e9..10a61fa 100644
--- a/src/Widgets/RichLabel.vala
+++ b/src/Widgets/RichLabel.vala
@@ -69,10 +69,7 @@ public class Tootle.Widgets.RichLabel : Label {
return true;
}
- var resolve = settings.aggressive_resolving || ("@" in url);
- if (!resolve)
- Desktop.open_uri (url);
- else {
+ if (should_resolve_url (url)) {
accounts.active.resolve.begin (url, (obj, res) => {
try {
accounts.active.resolve.end (res).open ();
@@ -84,8 +81,15 @@ public class Tootle.Widgets.RichLabel : Label {
}
});
}
+ else {
+ Desktop.open_uri (url);
+ }
+
return true;
}
+ public static bool should_resolve_url (string url) {
+ return settings.aggressive_resolving || "@" in url || "user" in url;
+ }
}