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 started ();
public abstract signal void finished (); public abstract signal void finished ();
public abstract signal void notification (Notification notification); public abstract signal void notification (ref Notification notification);
public abstract signal void status_added (Status status); public abstract signal void status_added (ref Status status, string timeline);
public abstract signal void status_removed (int64 id); public abstract signal void status_removed (int64 id);
private int requests_processing = 0; private int requests_processing = 0;

View File

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

View File

@ -9,7 +9,7 @@ public class Tootle.NotificationsView : AbstractView {
view.remove.connect (on_remove); view.remove.connect (on_remove);
Tootle.accounts.switched.connect(on_account_changed); Tootle.accounts.switched.connect(on_account_changed);
Tootle.app.refresh.connect(on_refresh); Tootle.app.refresh.connect(on_refresh);
Tootle.network.notification.connect (notification => prepend (notification)); Tootle.network.notification.connect (prepend);
request (); request ();
} }
@ -22,7 +22,7 @@ public class Tootle.NotificationsView : AbstractView {
return _("Notifications"); return _("Notifications");
} }
public void prepend (Notification notification) { public void prepend (ref Notification notification) {
if (empty != null) if (empty != null)
empty.destroy (); empty.destroy ();
@ -72,7 +72,7 @@ public class Tootle.NotificationsView : AbstractView {
var obj = node.get_object (); var obj = node.get_object ();
if (obj != null){ if (obj != null){
var notification = Notification.parse_follow_request(obj); 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 (); var obj = node.get_object ();
if (obj != null){ if (obj != null){
var notification = Notification.parse(obj); 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.accounts.switched.connect(on_account_changed);
Tootle.app.refresh.connect(on_refresh); Tootle.app.refresh.connect(on_refresh);
Tootle.network.status_added.connect (on_status_added);
request (); request ();
} }
@ -34,7 +35,14 @@ public class Tootle.TimelineView : AbstractView {
return false; 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) if (empty != null)
empty.destroy (); empty.destroy ();
@ -48,6 +56,9 @@ public class Tootle.TimelineView : AbstractView {
widget.avatar.button_press_event.connect(widget.on_avatar_clicked); widget.avatar.button_press_event.connect(widget.on_avatar_clicked);
view.pack_start(separator, false, false, 0); view.pack_start(separator, false, false, 0);
view.pack_start(widget, false, false, 0); view.pack_start(widget, false, false, 0);
if (first)
view.reorder_child (widget, 0);
} }
public override void clear () { public override void clear () {