2018-04-17 14:01:55 +02:00
|
|
|
using Gtk;
|
|
|
|
using Gdk;
|
|
|
|
|
|
|
|
public class Tootle.NotificationsView : Tootle.AbstractView {
|
|
|
|
|
|
|
|
public NotificationsView () {
|
2018-05-05 17:38:01 +02:00
|
|
|
base ();
|
2018-04-17 14:01:55 +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-05-05 17:38:01 +02:00
|
|
|
Tootle.app.refresh.connect(on_refresh);
|
|
|
|
|
|
|
|
request ();
|
2018-04-17 14:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override string get_icon () {
|
|
|
|
return "notification-symbolic";
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string get_name () {
|
2018-05-09 23:46:24 +02:00
|
|
|
return _("Notifications");
|
2018-04-17 14:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2018-04-22 12:33:19 +02:00
|
|
|
|
|
|
|
if (view.get_children ().length () <= 1)
|
|
|
|
image.icon_name = get_icon ();
|
2018-04-18 11:13:22 +02:00
|
|
|
}
|
2018-05-03 10:11:31 +02:00
|
|
|
|
|
|
|
public virtual void on_refresh (){
|
|
|
|
clear ();
|
|
|
|
request ();
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:01:55 +02:00
|
|
|
public virtual void on_account_changed (Account? account){
|
|
|
|
if(account == null)
|
|
|
|
return;
|
2018-05-05 17:38:01 +02:00
|
|
|
|
|
|
|
on_refresh ();
|
2018-05-03 10:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void request (){
|
2018-05-09 17:32:53 +02:00
|
|
|
var url = "%s/api/v1/follow_requests".printf (Tootle.settings.instance_url);
|
2018-04-17 14:01:55 +02:00
|
|
|
var msg = new Soup.Message("GET", url);
|
2018-04-27 20:50:08 +02:00
|
|
|
Tootle.network.queue(msg, (sess, mess) => {
|
2018-04-17 14:01:55 +02:00
|
|
|
try{
|
2018-04-27 20:50:08 +02:00
|
|
|
Tootle.network.parse_array (mess).foreach_element ((array, i, node) => {
|
2018-05-09 17:32:53 +02:00
|
|
|
var obj = node.get_object ();
|
|
|
|
if (obj != null){
|
|
|
|
var notification = Notification.parse_follow_request(obj);
|
|
|
|
prepend (notification);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (GLib.Error e) {
|
|
|
|
warning ("Can't update follow requests");
|
|
|
|
warning (e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-15 18:33:49 +02:00
|
|
|
var url2 = "%s/api/v1/notifications?limit=30".printf (Tootle.settings.instance_url);
|
2018-05-09 17:32:53 +02:00
|
|
|
var msg2 = new Soup.Message("GET", url2);
|
|
|
|
Tootle.network.queue(msg2, (sess, mess) => {
|
|
|
|
try{
|
|
|
|
Tootle.network.parse_array (mess).foreach_element ((array, i, node) => {
|
|
|
|
var obj = node.get_object ();
|
|
|
|
if (obj != null){
|
|
|
|
var notification = Notification.parse(obj);
|
2018-04-17 14:01:55 +02:00
|
|
|
prepend (notification);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (GLib.Error e) {
|
2018-05-09 17:32:53 +02:00
|
|
|
warning ("Can't update notifications");
|
2018-04-17 14:01:55 +02:00
|
|
|
warning (e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|