Revamp Status
This commit is contained in:
parent
75afde71e4
commit
1a13f3fcc1
|
@ -1,5 +1,7 @@
|
|||
public class Tootle.Status{
|
||||
|
||||
public abstract signal void updated ();
|
||||
|
||||
public Account account;
|
||||
public int64 id;
|
||||
public string uri;
|
||||
|
@ -71,4 +73,34 @@ public class Tootle.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class Tootle.NetManager : 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++;
|
||||
started ();
|
||||
|
||||
|
@ -51,7 +51,8 @@ public class Tootle.NetManager : GLib.Object{
|
|||
default:
|
||||
break;
|
||||
}
|
||||
cb (sess, mess);
|
||||
if (cb != null)
|
||||
cb (sess, mess);
|
||||
});
|
||||
return msg;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ public class Tootle.HomeView : Tootle.AbstractView {
|
|||
|
||||
var widget = new StatusWidget(status);
|
||||
widget.separator = separator;
|
||||
widget.rebind (status);
|
||||
widget.button_press_event.connect(widget.open);
|
||||
if (!is_status_owned (status))
|
||||
widget.avatar.button_press_event.connect(widget.on_avatar_clicked);
|
||||
|
|
|
@ -18,7 +18,6 @@ public class Tootle.StatusView : Tootle.AbstractView {
|
|||
else
|
||||
widget.margin_start = 24;
|
||||
|
||||
widget.rebind (status);
|
||||
widget.content.selectable = true;
|
||||
if (widget.spoiler_content != null)
|
||||
widget.spoiler_content.selectable = true;
|
||||
|
|
|
@ -42,8 +42,7 @@ public class Tootle.NotificationWidget : Gtk.Grid {
|
|||
get_style_context ().add_class ("notification");
|
||||
|
||||
if (notification.status != null){
|
||||
status_widget = new StatusWidget (this.notification.status);
|
||||
status_widget.rebind (this.notification.status);
|
||||
status_widget = new StatusWidget (notification.status);
|
||||
status_widget.button_press_event.connect(status_widget.open);
|
||||
status_widget.avatar.button_press_event.connect(status_widget.on_avatar_clicked);
|
||||
attach(status_widget, 1, 3, 3, 1);
|
||||
|
|
|
@ -53,13 +53,13 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
|||
reblog.tooltip_text = _("Boost");
|
||||
reblog.toggled.connect (() => {
|
||||
if (reblog.sensitive)
|
||||
toggle_reblog ();
|
||||
status.set_reblogged (reblog.get_active ());
|
||||
});
|
||||
favorite = get_action_button ("help-about-symbolic");
|
||||
favorite.tooltip_text = _("Favorite");
|
||||
favorite.toggled.connect (() => {
|
||||
if (favorite.sensitive)
|
||||
toggle_fav ();
|
||||
status.set_favorited (favorite.get_active ());
|
||||
});
|
||||
reply = get_action_button ("edit-undo-symbolic");
|
||||
reply.tooltip_text = _("Reply");
|
||||
|
@ -87,6 +87,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
|||
|
||||
public StatusWidget (Status status) {
|
||||
this.status = status;
|
||||
status.updated.connect (rebind);
|
||||
get_style_context ().add_class ("status");
|
||||
|
||||
if (status.reblog != null){
|
||||
|
@ -123,6 +124,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
|||
if(separator != null)
|
||||
separator.destroy ();
|
||||
});
|
||||
rebind ();
|
||||
}
|
||||
|
||||
public void highlight (){
|
||||
|
@ -133,7 +135,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
|||
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);
|
||||
content.label = status.content;
|
||||
content.mentions = status.mentions;
|
||||
|
@ -173,44 +175,4 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
|||
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"));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue