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