Revamp Status

This commit is contained in:
bleakgrey 2018-05-01 16:53:46 +03:00
parent 75afde71e4
commit 1a13f3fcc1
6 changed files with 41 additions and 49 deletions

View File

@ -1,5 +1,7 @@
public class Tootle.Status{ public class Tootle.Status{
public abstract signal void updated ();
public Account account; public Account account;
public int64 id; public int64 id;
public string uri; public string uri;
@ -71,4 +73,34 @@ public class Tootle.Status{
return status; return status;
} }
public void set_reblogged (bool rebl = true){
var action = rebl ? "reblog" : "unreblog";
var msg = new Soup.Message("POST", "%s/api/v1/statuses/%lld/%s".printf (Tootle.settings.instance_url, id, action));
msg.priority = Soup.MessagePriority.HIGH;
msg.finished.connect (() => {
reblogged = rebl;
updated ();
if(rebl)
Tootle.app.toast (_("Boosted!"));
else
Tootle.app.toast (_("Removed boost"));
});
Tootle.network.queue (msg);
}
public void set_favorited (bool fav = true){
var action = fav ? "favourite" : "unfavourite";
var msg = new Soup.Message("POST", "%s/api/v1/statuses/%lld/%s".printf (Tootle.settings.instance_url, id, action));
msg.priority = Soup.MessagePriority.HIGH;
msg.finished.connect (() => {
favorited = fav;
updated ();
if(fav)
Tootle.app.toast (_("Favorited!"));
else
Tootle.app.toast (_("Removed from favorites"));
});
Tootle.network.queue (msg);
}
} }

View File

@ -27,7 +27,7 @@ public class Tootle.NetManager : GLib.Object{
GLib.Object(); GLib.Object();
} }
public Soup.Message queue(Soup.Message msg, Soup.SessionCallback cb){ public Soup.Message queue(Soup.Message msg, Soup.SessionCallback? cb = null){
requests_processing++; requests_processing++;
started (); started ();
@ -51,7 +51,8 @@ public class Tootle.NetManager : GLib.Object{
default: default:
break; break;
} }
cb (sess, mess); if (cb != null)
cb (sess, mess);
}); });
return msg; return msg;
} }

View File

@ -35,7 +35,6 @@ public class Tootle.HomeView : Tootle.AbstractView {
var widget = new StatusWidget(status); var widget = new StatusWidget(status);
widget.separator = separator; widget.separator = separator;
widget.rebind (status);
widget.button_press_event.connect(widget.open); widget.button_press_event.connect(widget.open);
if (!is_status_owned (status)) if (!is_status_owned (status))
widget.avatar.button_press_event.connect(widget.on_avatar_clicked); widget.avatar.button_press_event.connect(widget.on_avatar_clicked);

View File

@ -18,7 +18,6 @@ public class Tootle.StatusView : Tootle.AbstractView {
else else
widget.margin_start = 24; widget.margin_start = 24;
widget.rebind (status);
widget.content.selectable = true; widget.content.selectable = true;
if (widget.spoiler_content != null) if (widget.spoiler_content != null)
widget.spoiler_content.selectable = true; widget.spoiler_content.selectable = true;

View File

@ -42,8 +42,7 @@ public class Tootle.NotificationWidget : Gtk.Grid {
get_style_context ().add_class ("notification"); get_style_context ().add_class ("notification");
if (notification.status != null){ if (notification.status != null){
status_widget = new StatusWidget (this.notification.status); status_widget = new StatusWidget (notification.status);
status_widget.rebind (this.notification.status);
status_widget.button_press_event.connect(status_widget.open); status_widget.button_press_event.connect(status_widget.open);
status_widget.avatar.button_press_event.connect(status_widget.on_avatar_clicked); status_widget.avatar.button_press_event.connect(status_widget.on_avatar_clicked);
attach(status_widget, 1, 3, 3, 1); attach(status_widget, 1, 3, 3, 1);

View File

@ -53,13 +53,13 @@ public class Tootle.StatusWidget : Gtk.EventBox {
reblog.tooltip_text = _("Boost"); reblog.tooltip_text = _("Boost");
reblog.toggled.connect (() => { reblog.toggled.connect (() => {
if (reblog.sensitive) if (reblog.sensitive)
toggle_reblog (); status.set_reblogged (reblog.get_active ());
}); });
favorite = get_action_button ("help-about-symbolic"); favorite = get_action_button ("help-about-symbolic");
favorite.tooltip_text = _("Favorite"); favorite.tooltip_text = _("Favorite");
favorite.toggled.connect (() => { favorite.toggled.connect (() => {
if (favorite.sensitive) if (favorite.sensitive)
toggle_fav (); status.set_favorited (favorite.get_active ());
}); });
reply = get_action_button ("edit-undo-symbolic"); reply = get_action_button ("edit-undo-symbolic");
reply.tooltip_text = _("Reply"); reply.tooltip_text = _("Reply");
@ -87,6 +87,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
public StatusWidget (Status status) { public StatusWidget (Status status) {
this.status = status; this.status = status;
status.updated.connect (rebind);
get_style_context ().add_class ("status"); get_style_context ().add_class ("status");
if (status.reblog != null){ if (status.reblog != null){
@ -123,6 +124,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
if(separator != null) if(separator != null)
separator.destroy (); separator.destroy ();
}); });
rebind ();
} }
public void highlight (){ public void highlight (){
@ -133,7 +135,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
avatar.show_default (avatar_size); avatar.show_default (avatar_size);
} }
public void rebind (Status status = this.status){ public void rebind (){
user.label = "<b>%s</b>".printf (status.get_formal ().account.display_name); user.label = "<b>%s</b>".printf (status.get_formal ().account.display_name);
content.label = status.content; content.label = status.content;
content.mentions = status.mentions; content.mentions = status.mentions;
@ -173,44 +175,4 @@ public class Tootle.StatusWidget : Gtk.EventBox {
return button; return button;
} }
public void toggle_reblog (){
var state = reblog.get_active ();
var action = state ? "reblog" : "unreblog";
var msg = new Soup.Message("POST", Tootle.settings.instance_url + "/api/v1/statuses/" + status.id.to_string () + "/" + action);
msg.finished.connect (() => {
status.reblogged = state;
if (state)
status.reblogs_count += 1;
else
status.reblogs_count -= 1;
rebind ();
});
Tootle.network.queue (msg, (sess, mess) => {
if(state)
Tootle.app.toast (_("Boosted!"));
else
Tootle.app.toast (_("Removed boost"));
});
}
public void toggle_fav (){
var state = favorite.get_active ();
var action = state ? "favourite" : "unfavourite";
var msg = new Soup.Message ("POST", Tootle.settings.instance_url + "/api/v1/statuses/" + status.id.to_string () + "/" + action);
msg.finished.connect (() => {
status.favorited = state;
if (state)
status.favourites_count += 1;
else
status.favourites_count -= 1;
rebind ();
});
Tootle.network.queue (msg, (sess, mess) => {
if(state)
Tootle.app.toast (_("Favorited!"));
else
Tootle.app.toast (_("Removed favorite"));
});
}
} }