2018-04-17 14:01:55 +02:00
|
|
|
using Gtk;
|
|
|
|
using Gdk;
|
|
|
|
|
|
|
|
public class Tootle.NotificationsView : Tootle.AbstractView {
|
|
|
|
|
|
|
|
Gtk.Box view;
|
|
|
|
Gtk.ScrolledWindow scroll;
|
|
|
|
|
|
|
|
construct {
|
|
|
|
view = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
|
|
|
|
view.hexpand = true;
|
|
|
|
view.valign = Gtk.Align.START;
|
|
|
|
|
|
|
|
scroll = new Gtk.ScrolledWindow (null, null);
|
|
|
|
scroll.hexpand = true;
|
|
|
|
scroll.vexpand = true;
|
|
|
|
scroll.hscrollbar_policy = Gtk.PolicyType.NEVER;
|
|
|
|
scroll.add (view);
|
|
|
|
add (scroll);
|
|
|
|
}
|
|
|
|
|
|
|
|
public NotificationsView () {
|
|
|
|
base (true);
|
|
|
|
show_all();
|
|
|
|
|
2018-04-18 11:13:22 +02:00
|
|
|
view.remove.connect (on_remove);
|
2018-04-20 13:51:18 +02:00
|
|
|
AccountManager.instance.switched.connect(on_account_changed);
|
2018-04-17 14:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override string get_icon () {
|
|
|
|
return "notification-symbolic";
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string get_name () {
|
|
|
|
return "Notifications";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void prepend(Notification notification){
|
2018-04-18 11:13:22 +02:00
|
|
|
var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
|
|
|
|
separator.show ();
|
|
|
|
|
2018-04-17 14:01:55 +02:00
|
|
|
var widget = new NotificationWidget(notification);
|
2018-04-18 11:13:22 +02:00
|
|
|
widget.separator = separator;
|
|
|
|
view.pack_start(separator, false, false, 0);
|
2018-04-17 14:01:55 +02:00
|
|
|
view.pack_start(widget, false, false, 0);
|
|
|
|
image.icon_name = "notification-new-symbolic";
|
|
|
|
}
|
|
|
|
|
2018-04-18 11:13:22 +02:00
|
|
|
public virtual void on_remove (Widget widget){
|
|
|
|
if (!(widget is NotificationWidget))
|
|
|
|
return;
|
|
|
|
|
|
|
|
//debug ("removed");
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:01:55 +02:00
|
|
|
public virtual void on_account_changed (Account? account){
|
|
|
|
if(account == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var url = Settings.instance.instance_url;
|
|
|
|
url += "/api/v1/notifications";
|
|
|
|
|
|
|
|
var msg = new Soup.Message("GET", url);
|
|
|
|
NetManager.instance.queue(msg, (sess, mess) => {
|
|
|
|
try{
|
|
|
|
NetManager.parse_array (mess).foreach_element ((array, i, node) => {
|
|
|
|
var object = node.get_object ();
|
|
|
|
if (object != null){
|
|
|
|
var notification = Notification.parse(object);
|
|
|
|
prepend (notification);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (GLib.Error e) {
|
|
|
|
warning ("Can't update feed");
|
|
|
|
warning (e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|