tootle-linux-client/src/Views/HomeView.vala

97 lines
2.6 KiB
Vala
Raw Normal View History

2018-04-14 14:09:06 +02:00
using Gtk;
using Gdk;
public class Tootle.HomeView : Tootle.AbstractView {
private string timeline;
2018-04-26 16:05:03 +02:00
public HomeView (string timeline = "home") {
2018-04-14 14:09:06 +02:00
base (true);
this.timeline = timeline;
2018-04-14 19:53:09 +02:00
2018-04-18 11:13:22 +02:00
view.remove.connect (on_remove);
2018-04-27 20:50:08 +02:00
Tootle.accounts.switched.connect(on_account_changed);
2018-04-14 14:09:06 +02:00
// var s = new Status(1);
// s.content = "Test content, wow!";
// prepend (s);
}
public override string get_icon () {
return "user-home-symbolic";
}
public override string get_name () {
2018-04-26 16:05:03 +02:00
return "Home";
2018-04-14 14:09:06 +02:00
}
2018-04-26 16:05:03 +02:00
public virtual bool is_status_owned (Status status){
return false;
}
public void prepend(Status status){
2018-04-18 11:13:22 +02:00
var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
separator.show ();
2018-04-16 20:22:42 +02:00
var widget = new StatusWidget(status);
2018-04-18 11:13:22 +02:00
widget.separator = separator;
2018-04-26 16:05:03 +02:00
widget.button_press_event.connect(widget.open);
if (!is_status_owned (status))
widget.avatar.button_press_event.connect(widget.on_avatar_clicked);
2018-04-18 11:13:22 +02:00
view.pack_start(separator, false, false, 0);
2018-04-16 22:36:57 +02:00
view.pack_start(widget, false, false, 0);
2018-04-14 14:09:06 +02:00
}
2018-04-18 11:13:22 +02:00
public virtual void on_remove (Widget widget){
if (!(widget is StatusWidget))
return;
2018-04-26 16:05:03 +02:00
//TODO: empty state
2018-04-18 11:13:22 +02:00
}
2018-04-26 16:05:03 +02:00
public virtual string get_url (){
2018-04-27 20:50:08 +02:00
var url = Tootle.settings.instance_url;
2018-04-14 14:09:06 +02:00
url += "api/v1/timelines/";
url += this.timeline;
2018-04-26 16:05:03 +02:00
url += "?limit=25";
2018-04-14 14:09:06 +02:00
2018-04-26 16:05:03 +02:00
if (max_id > 0)
url += "&max_id=" + max_id.to_string ();
return url;
}
public void request (){
var msg = new Soup.Message("GET", get_url ());
2018-04-27 20:50:08 +02:00
Tootle.network.queue(msg, (sess, mess) => {
2018-04-14 14:09:06 +02:00
try{
2018-04-27 20:50:08 +02:00
Tootle.network.parse_array (mess).foreach_element ((array, i, node) => {
2018-04-14 14:09:06 +02:00
var object = node.get_object ();
if (object != null){
var status = Status.parse(object);
2018-04-26 16:05:03 +02:00
max_id = status.id;
2018-04-14 14:09:06 +02:00
prepend (status);
}
});
}
catch (GLib.Error e) {
warning ("Can't update feed");
warning (e.message);
}
});
}
2018-04-26 16:05:03 +02:00
public virtual void on_account_changed (Account? account){
if(account == null)
return;
clear ();
request ();
}
public override void bottom_reached (){
request ();
}
2018-04-14 14:09:06 +02:00
}