mirror of
https://gitlab.gnome.org/World/tootle
synced 2025-02-16 19:40:41 +01:00
Implement post publishing
This commit is contained in:
parent
f6b37d9dd6
commit
03323f073c
@ -39,9 +39,9 @@ public enum Tootle.StatusVisibility {
|
||||
case PUBLIC:
|
||||
return "network-workgroup-symbolic";
|
||||
case UNLISTED:
|
||||
return "security-medium-symbolic";
|
||||
return "view-private-symbolic";
|
||||
case PRIVATE:
|
||||
return "security-high-symbolic";
|
||||
return "security-medium-symbolic";
|
||||
case DIRECT:
|
||||
return "user-available-symbolic";
|
||||
default:
|
||||
|
@ -7,6 +7,7 @@ public class Tootle.TootDialog : Gtk.Dialog {
|
||||
private Gtk.TextView text;
|
||||
private Gtk.Label counter;
|
||||
private Gtk.MenuButton visibility;
|
||||
private Gtk.Button publish;
|
||||
|
||||
private StatusVisibility visibility_opt;
|
||||
|
||||
@ -28,10 +29,10 @@ public class Tootle.TootDialog : Gtk.Dialog {
|
||||
close.clicked.connect(() => {
|
||||
this.destroy ();
|
||||
});
|
||||
var publish = add_button(_("Toot!"), 5) as Gtk.Button;
|
||||
publish = add_button(_("Toot!"), 5) as Gtk.Button;
|
||||
publish.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
|
||||
publish.clicked.connect (() => {
|
||||
this.destroy (); //TODO: actually publish toots
|
||||
publish_post ();
|
||||
});
|
||||
|
||||
text = new Gtk.TextView ();
|
||||
@ -47,7 +48,7 @@ public class Tootle.TootDialog : Gtk.Dialog {
|
||||
actions.pack_start (visibility, false, false, 6);
|
||||
actions.pack_start (counter, false, false, 6);
|
||||
content.pack_start (text, false, false, 0);
|
||||
content.set_size_request (300, 100);
|
||||
content.set_size_request (300, 150);
|
||||
}
|
||||
|
||||
private Gtk.MenuButton get_visibility_btn (){
|
||||
@ -89,8 +90,10 @@ public class Tootle.TootDialog : Gtk.Dialog {
|
||||
|
||||
private void update_counter (){
|
||||
var len = text.buffer.text.length;
|
||||
var remain = 500 - len;
|
||||
publish.sensitive = (remain >= 0);
|
||||
|
||||
counter.label = (500 - len).to_string ();
|
||||
counter.label = remain.to_string ();
|
||||
}
|
||||
|
||||
public static void open (Gtk.Window? parent){
|
||||
@ -102,5 +105,25 @@ public class Tootle.TootDialog : Gtk.Dialog {
|
||||
dialog.show_all ();
|
||||
}
|
||||
}
|
||||
|
||||
public void publish_post(){
|
||||
var text_escaped = text.buffer.text.replace (" ", "%20");
|
||||
var pars = "?status=" + text_escaped;
|
||||
pars += "&visibility=" + visibility_opt.to_string ();
|
||||
|
||||
var msg = new Soup.Message("POST", Settings.instance.instance_url + "/api/v1/statuses" + pars);
|
||||
NetManager.instance.queue(msg, (sess, mess) => {
|
||||
try{
|
||||
var root = NetManager.parse (mess);
|
||||
var status = Status.parse (root);
|
||||
Tootle.window.home.prepend (status);
|
||||
this.destroy ();
|
||||
}
|
||||
catch (GLib.Error e) {
|
||||
warning ("Can't publish post.");
|
||||
warning (e.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ public class Tootle.MainWindow: Gtk.Window {
|
||||
Spinner spinner;
|
||||
Button button_toot;
|
||||
|
||||
HomeView home = new HomeView ();
|
||||
LocalView feed_local = new LocalView ();
|
||||
public HomeView home = new HomeView ();
|
||||
public LocalView feed_local = new LocalView ();
|
||||
FederatedView feed_federated = new FederatedView ();
|
||||
|
||||
public MainWindow (Gtk.Application application) {
|
||||
|
@ -45,9 +45,9 @@ public class Tootle.NetManager : GLib.Object{
|
||||
}
|
||||
|
||||
public static Json.Object parse(Soup.Message msg) throws GLib.Error{
|
||||
// stdout.printf ("Status Code: %u\n", msg.status_code);
|
||||
// stdout.printf ("Message length: %lld\n", msg.response_body.length);
|
||||
// stdout.printf ("Data: \n%s\n", (string) msg.response_body.data);
|
||||
stdout.printf ("Status Code: %u\n", msg.status_code);
|
||||
stdout.printf ("Message length: %lld\n", msg.response_body.length);
|
||||
stdout.printf ("Data: \n%s\n", (string) msg.response_body.data);
|
||||
|
||||
var parser = new Json.Parser ();
|
||||
parser.load_from_data ((string) msg.response_body.flatten ().data, -1);
|
||||
@ -56,7 +56,7 @@ public class Tootle.NetManager : GLib.Object{
|
||||
|
||||
public static Json.Array parse_array(Soup.Message msg) throws GLib.Error{
|
||||
// stdout.printf ("Status Code: %u\n", msg.status_code);
|
||||
// stdout.printf ("Message length: %lld\n", msg.response_body.length);
|
||||
// stdout.printf ("Message length: %lld\n", msg.response_body.length);
|
||||
// stdout.printf ("Data: \n%s\n", (string) msg.response_body.data);
|
||||
|
||||
var parser = new Json.Parser ();
|
||||
|
Loading…
x
Reference in New Issue
Block a user