Initial Pleroma support (#285)

Co-authored-by: dec05eba <66856951+dec05eba@users.noreply.github.com>
This commit is contained in:
Bleak Grey 2021-02-14 14:49:41 +03:00 committed by GitHub
parent e60aa17934
commit eff22c2bfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 17 deletions

View File

@ -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 ();

View File

@ -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);

View File

@ -23,11 +23,14 @@ public class Tootle.HtmlUtils {
var divided = str
.replace("<br>", "\n")
.replace("</br>", "")
.replace("<br/>", "\n")
.replace("<br />", "\n")
.replace("<p>", "")
.replace("</p>", "\n\n");
.replace("</p>", "\n\n")
.replace("<pre>", "")
.replace("</pre>", "");
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("<strong>", "<b>")
.replace("</strong>", "</b>")
.replace("<em>", "<i>")
.replace("</em>", "</i>")
.replace("<code>", "<span font_family=\"monospace\">")
.replace("</code>", "</span>\n")
.replace("<del>", "<s>")
.replace("</del>", "</s>");
}
public static string uri_encode (string str) {
var restored = Widgets.RichLabel.restore_entities (str);
return Soup.URI.encode (restored, ";&+");

View File

@ -7,6 +7,7 @@ public class Tootle.Request : Soup.Message {
Network.SuccessCallback? cb;
Network.ErrorCallback? error_cb;
HashMap<string, string>? 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");

View File

@ -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;
}
}