mirror of
https://gitlab.gnome.org/World/tootle
synced 2025-02-16 19:40:41 +01:00
Display status context in StatusView
This commit is contained in:
parent
80b083d6b9
commit
c45ef06e92
@ -23,7 +23,7 @@ public class Tootle.CacheManager : GLib.Object{
|
||||
}
|
||||
|
||||
//TODO: actually cache images
|
||||
public void load_avatar (string url, Granite.Widgets.Avatar avatar, int size = 32){
|
||||
public void load_avatar (string url, Granite.Widgets.Avatar avatar, int size){
|
||||
var msg = new Soup.Message("GET", url);
|
||||
msg.finished.connect(()=>{
|
||||
uint8[] buf = msg.response_body.data;
|
||||
|
@ -47,7 +47,7 @@ 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 ("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);
|
||||
@ -57,7 +57,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 ("Data: \n%s\n", (string) msg.response_body.data);
|
||||
//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);
|
||||
|
@ -2,6 +2,7 @@ using Gtk;
|
||||
|
||||
public class Tootle.StatusView : Tootle.AbstractView {
|
||||
|
||||
Status root_status;
|
||||
Gtk.Box view;
|
||||
Gtk.ScrolledWindow scroll;
|
||||
|
||||
@ -16,17 +17,58 @@ public class Tootle.StatusView : Tootle.AbstractView {
|
||||
scroll.hscrollbar_policy = Gtk.PolicyType.NEVER;
|
||||
scroll.add (view);
|
||||
add (scroll);
|
||||
|
||||
show_all ();
|
||||
}
|
||||
|
||||
public StatusView (Status status) {
|
||||
base (false);
|
||||
|
||||
root_status = status;
|
||||
request_context ();
|
||||
}
|
||||
|
||||
private void prepend (Status status, bool is_root = false){
|
||||
var widget = new StatusWidget(status);
|
||||
|
||||
if (is_root)
|
||||
widget.highlight ();
|
||||
else
|
||||
widget.margin_start = 24;
|
||||
|
||||
widget.rebind (status);
|
||||
widget.content.selectable = true;
|
||||
view.pack_start (widget, false, false, 0);
|
||||
|
||||
show_all();
|
||||
}
|
||||
|
||||
public Soup.Message request_context (){
|
||||
var url = "%s/api/v1/statuses/%lld/context".printf (Settings.instance.instance_url, root_status.id);
|
||||
var msg = new Soup.Message("GET", url);
|
||||
NetManager.instance.queue(msg, (sess, mess) => {
|
||||
try{
|
||||
var root = NetManager.parse (mess);
|
||||
|
||||
var ancestors = root.get_array_member ("ancestors");
|
||||
ancestors.foreach_element ((array, i, node) => {
|
||||
var object = node.get_object ();
|
||||
if (object != null)
|
||||
prepend (Status.parse(object));
|
||||
});
|
||||
|
||||
prepend (root_status, true);
|
||||
|
||||
var descendants = root.get_array_member ("descendants");
|
||||
descendants.foreach_element ((array, i, node) => {
|
||||
var object = node.get_object ();
|
||||
if (object != null)
|
||||
prepend (Status.parse(object));
|
||||
});
|
||||
}
|
||||
catch (GLib.Error e) {
|
||||
warning ("Can't get context for a status");
|
||||
warning (e.message);
|
||||
}
|
||||
});
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,10 +5,11 @@ public class Tootle.StatusWidget : Gtk.Grid {
|
||||
|
||||
public Status status;
|
||||
|
||||
public Gtk.Separator? separator;
|
||||
public int avatar_size;
|
||||
public Granite.Widgets.Avatar avatar;
|
||||
public Gtk.Label user;
|
||||
public Gtk.Label content;
|
||||
public Gtk.Separator? separator;
|
||||
|
||||
Gtk.Box counters;
|
||||
Gtk.Label reblogs;
|
||||
@ -20,7 +21,8 @@ public class Tootle.StatusWidget : Gtk.Grid {
|
||||
construct {
|
||||
margin = 6;
|
||||
|
||||
avatar = new Granite.Widgets.Avatar.with_default_icon (32);
|
||||
avatar_size = 32;
|
||||
avatar = new Granite.Widgets.Avatar.with_default_icon (avatar_size);
|
||||
avatar.valign = Gtk.Align.START;
|
||||
avatar.margin_end = 6;
|
||||
user = new Gtk.Label (_("Anonymous"));
|
||||
@ -92,6 +94,12 @@ public class Tootle.StatusWidget : Gtk.Grid {
|
||||
});
|
||||
}
|
||||
|
||||
public void highlight (){
|
||||
content.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
|
||||
avatar_size = 48;
|
||||
avatar.show_default (avatar_size);
|
||||
}
|
||||
|
||||
public void rebind (Status status = this.status){
|
||||
var user_label = status.reblog != null ? status.reblog.account.display_name : status.account.display_name;
|
||||
user.label = "<b>%s</b>".printf (user_label);
|
||||
@ -106,7 +114,7 @@ public class Tootle.StatusWidget : Gtk.Grid {
|
||||
favorite.sensitive = true;
|
||||
|
||||
var avatar_url = status.reblog != null ? status.reblog.account.avatar : status.account.avatar;
|
||||
CacheManager.instance.load_avatar (avatar_url, this.avatar);
|
||||
CacheManager.instance.load_avatar (avatar_url, this.avatar, this.avatar_size);
|
||||
}
|
||||
|
||||
private Gtk.ToggleButton get_action_button (bool reblog = true){
|
||||
|
Loading…
x
Reference in New Issue
Block a user