Real-time home updates

This commit is contained in:
bleakgrey 2018-05-19 19:01:54 +03:00
parent d02b3d3f6c
commit a8bfbaa685
4 changed files with 20 additions and 9 deletions

View File

@ -8,8 +8,8 @@ public class Tootle.NetManager : GLib.Object {
public abstract signal void started ();
public abstract signal void finished ();
public abstract signal void notification (Notification notification);
public abstract signal void status_added (Status status);
public abstract signal void notification (ref Notification notification);
public abstract signal void status_added (ref Status status, string timeline);
public abstract signal void status_removed (int64 id);
private int requests_processing = 0;

View File

@ -40,7 +40,7 @@ public class Tootle.Notificator : GLib.Object {
switch (type) {
case "update":
var status = Status.parse (sanitize (root));
network.status_added (status);
network.status_added (ref status, "home");
break;
case "delete":
var id = int64.parse (root.get_string_member("payload"));
@ -49,7 +49,7 @@ public class Tootle.Notificator : GLib.Object {
case "notification":
var notif = Notification.parse (sanitize (root));
toast (notif);
network.notification (notif);
network.notification (ref notif);
break;
default:
warning ("Unknown push event: %s", type);

View File

@ -9,7 +9,7 @@ public class Tootle.NotificationsView : AbstractView {
view.remove.connect (on_remove);
Tootle.accounts.switched.connect(on_account_changed);
Tootle.app.refresh.connect(on_refresh);
Tootle.network.notification.connect (notification => prepend (notification));
Tootle.network.notification.connect (prepend);
request ();
}
@ -22,7 +22,7 @@ public class Tootle.NotificationsView : AbstractView {
return _("Notifications");
}
public void prepend (Notification notification) {
public void prepend (ref Notification notification) {
if (empty != null)
empty.destroy ();
@ -72,7 +72,7 @@ public class Tootle.NotificationsView : AbstractView {
var obj = node.get_object ();
if (obj != null){
var notification = Notification.parse_follow_request(obj);
prepend (notification);
prepend (ref notification);
}
});
}
@ -90,7 +90,7 @@ public class Tootle.NotificationsView : AbstractView {
var obj = node.get_object ();
if (obj != null){
var notification = Notification.parse(obj);
prepend (notification);
prepend (ref notification);
}
});
}

View File

@ -18,6 +18,7 @@ public class Tootle.TimelineView : AbstractView {
Tootle.accounts.switched.connect(on_account_changed);
Tootle.app.refresh.connect(on_refresh);
Tootle.network.status_added.connect (on_status_added);
request ();
}
@ -34,7 +35,14 @@ public class Tootle.TimelineView : AbstractView {
return false;
}
public void prepend (ref Status status){
private void on_status_added (ref Status status, string timeline) {
if (timeline != this.timeline)
return;
prepend (ref status, true);
}
public void prepend (ref Status status, bool first = false){
if (empty != null)
empty.destroy ();
@ -48,6 +56,9 @@ public class Tootle.TimelineView : AbstractView {
widget.avatar.button_press_event.connect(widget.on_avatar_clicked);
view.pack_start(separator, false, false, 0);
view.pack_start(widget, false, false, 0);
if (first)
view.reorder_child (widget, 0);
}
public override void clear () {