mirror of
https://gitlab.gnome.org/World/tootle
synced 2025-02-16 19:40:41 +01:00
Show follow requests as notifications
This commit is contained in:
parent
1c09eda7ff
commit
4d74bbef3d
@ -25,5 +25,39 @@ public class Tootle.Notification{
|
||||
|
||||
return notification;
|
||||
}
|
||||
|
||||
public static Notification parse_follow_request (Json.Object obj) {
|
||||
var notification = new Notification (-1);
|
||||
var account = Account.parse (obj);
|
||||
|
||||
notification.type = NotificationType.FOLLOW_REQUEST;
|
||||
notification.account = account;
|
||||
|
||||
return notification;
|
||||
}
|
||||
|
||||
public Soup.Message dismiss () {
|
||||
if (type == NotificationType.FOLLOW_REQUEST)
|
||||
return reject_follow_request ();
|
||||
|
||||
var url = "%s/api/v1/notifications/dismiss?id=%lld".printf (Tootle.settings.instance_url, id);
|
||||
var msg = new Soup.Message("POST", url);
|
||||
Tootle.network.queue(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public Soup.Message accept_follow_request () {
|
||||
var url = "%s/api/v1/follow_requests/%lld/authorize".printf (Tootle.settings.instance_url, account.id);
|
||||
var msg = new Soup.Message("POST", url);
|
||||
Tootle.network.queue(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public Soup.Message reject_follow_request () {
|
||||
var url = "%s/api/v1/follow_requests/%lld/reject".printf (Tootle.settings.instance_url, account.id);
|
||||
var msg = new Soup.Message("POST", url);
|
||||
Tootle.network.queue(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ public enum Tootle.NotificationType {
|
||||
MENTION,
|
||||
REBLOG,
|
||||
FAVORITE,
|
||||
FOLLOW;
|
||||
FOLLOW,
|
||||
FOLLOW_REQUEST;
|
||||
|
||||
public string to_string() {
|
||||
switch (this) {
|
||||
@ -14,6 +15,8 @@ public enum Tootle.NotificationType {
|
||||
return "favourite";
|
||||
case FOLLOW:
|
||||
return "follow";
|
||||
case FOLLOW_REQUEST:
|
||||
return "follow_request";
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
@ -29,6 +32,8 @@ public enum Tootle.NotificationType {
|
||||
return FAVORITE;
|
||||
case "follow":
|
||||
return FOLLOW;
|
||||
case "follow_request":
|
||||
return FOLLOW_REQUEST;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
@ -44,6 +49,8 @@ public enum Tootle.NotificationType {
|
||||
return _("<a href=\"%s\"><b>%s</b></a> favorited your toot").printf (account.url, account.display_name);
|
||||
case FOLLOW:
|
||||
return _("<a href=\"%s\"><b>%s</b></a> now follows you").printf (account.url, account.display_name);
|
||||
case FOLLOW_REQUEST:
|
||||
return _("<a href=\"%s\"><b>%s</b></a> wants to follow you").printf (account.url, account.display_name);
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
@ -58,6 +65,7 @@ public enum Tootle.NotificationType {
|
||||
case FAVORITE:
|
||||
return "help-about-symbolic";
|
||||
case FOLLOW:
|
||||
case FOLLOW_REQUEST:
|
||||
return "contact-new-symbolic";
|
||||
default:
|
||||
assert_not_reached();
|
||||
|
@ -85,6 +85,8 @@ public class Tootle.AddAccountView : Tootle.AbstractView {
|
||||
|
||||
|
||||
construct {
|
||||
view.valign = Gtk.Align.CENTER;
|
||||
|
||||
stack = new Stack ();
|
||||
stack.valign = Gtk.Align.CENTER;
|
||||
stack.vexpand = true;
|
||||
|
@ -53,22 +53,38 @@ public class Tootle.NotificationsView : Tootle.AbstractView {
|
||||
}
|
||||
|
||||
public void request (){
|
||||
var url = Tootle.settings.instance_url;
|
||||
url += "/api/v1/notifications";
|
||||
|
||||
var url = "%s/api/v1/follow_requests".printf (Tootle.settings.instance_url);
|
||||
var msg = new Soup.Message("GET", url);
|
||||
Tootle.network.queue(msg, (sess, mess) => {
|
||||
try{
|
||||
Tootle.network.parse_array (mess).foreach_element ((array, i, node) => {
|
||||
var object = node.get_object ();
|
||||
if (object != null){
|
||||
var notification = Notification.parse(object);
|
||||
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 feed");
|
||||
warning ("Can't update follow requests");
|
||||
warning (e.message);
|
||||
}
|
||||
});
|
||||
|
||||
var url2 = "%s/api/v1/notifications".printf (Tootle.settings.instance_url);
|
||||
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);
|
||||
prepend (notification);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (GLib.Error e) {
|
||||
warning ("Can't update notifications");
|
||||
warning (e.message);
|
||||
}
|
||||
});
|
||||
|
@ -8,30 +8,30 @@ public class Tootle.NotificationWidget : Gtk.Grid {
|
||||
public Gtk.Separator? separator;
|
||||
private Gtk.Image image;
|
||||
private Tootle.RichLabel label;
|
||||
private Gtk.Button dismiss_button;
|
||||
private StatusWidget? status_widget;
|
||||
private Gtk.Button dismiss;
|
||||
|
||||
construct {
|
||||
margin = 6;
|
||||
|
||||
image = new Gtk.Image.from_icon_name("notification-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
|
||||
image = new Gtk.Image.from_icon_name("notification-symbolic", Gtk.IconSize.BUTTON);
|
||||
image.margin_start = 32;
|
||||
image.margin_end = 6;
|
||||
label = new RichLabel (_("Unknown Notification"));
|
||||
label.hexpand = true;
|
||||
label.halign = Gtk.Align.START;
|
||||
dismiss_button = new Gtk.Button.from_icon_name ("close-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
|
||||
dismiss_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
|
||||
dismiss_button.tooltip_text = _("Dismiss");
|
||||
dismiss_button.clicked.connect (() => {
|
||||
dismiss = new Gtk.Button.from_icon_name ("close-symbolic", Gtk.IconSize.BUTTON);
|
||||
dismiss.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
|
||||
dismiss.tooltip_text = _("Dismiss");
|
||||
dismiss.clicked.connect (() => {
|
||||
var parent = this.get_parent () as Gtk.Box;
|
||||
notification.dismiss ();
|
||||
parent.remove (this);
|
||||
dismiss (this.notification);
|
||||
});
|
||||
|
||||
attach(image, 1, 2);
|
||||
attach(label, 2, 2);
|
||||
attach(dismiss_button, 3, 2);
|
||||
attach(dismiss, 3, 2);
|
||||
show_all();
|
||||
}
|
||||
|
||||
@ -41,6 +41,11 @@ public class Tootle.NotificationWidget : Gtk.Grid {
|
||||
label.label = notification.type.get_desc (notification.account);
|
||||
get_style_context ().add_class ("notification");
|
||||
|
||||
destroy.connect (() => {
|
||||
if(separator != null)
|
||||
separator.destroy ();
|
||||
});
|
||||
|
||||
if (notification.status != null){
|
||||
status_widget = new StatusWidget (notification.status);
|
||||
status_widget.button_press_event.connect(status_widget.open);
|
||||
@ -48,20 +53,26 @@ public class Tootle.NotificationWidget : Gtk.Grid {
|
||||
attach(status_widget, 1, 3, 3, 1);
|
||||
}
|
||||
|
||||
destroy.connect (() => {
|
||||
if(separator != null)
|
||||
separator.destroy ();
|
||||
});
|
||||
}
|
||||
|
||||
public static Soup.Message dismiss (Notification notification){
|
||||
var url = Tootle.settings.instance_url;
|
||||
url += "api/v1/notifications/dismiss";
|
||||
url += "?id=" + notification.id.to_string ();
|
||||
|
||||
var msg = new Soup.Message("POST", url);
|
||||
Tootle.network.queue(msg, (sess, mess) => {});
|
||||
return msg;
|
||||
if (notification.type == NotificationType.FOLLOW_REQUEST) {
|
||||
var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
|
||||
box.margin_start = 32 + 16 + 8;
|
||||
var accept = new Gtk.Button.with_label (_("Accept"));
|
||||
box.pack_start (accept, false, false, 0);
|
||||
var reject = new Gtk.Button.with_label (_("Reject"));
|
||||
box.pack_start (reject, false, false, 0);
|
||||
|
||||
attach(box, 1, 3, 3, 1);
|
||||
box.show_all ();
|
||||
|
||||
accept.clicked.connect (() => {
|
||||
destroy ();
|
||||
notification.accept_follow_request ();
|
||||
});
|
||||
reject.clicked.connect (() => {
|
||||
destroy ();
|
||||
notification.reject_follow_request ();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
||||
get_style_context ().add_class ("status");
|
||||
|
||||
if (status.reblog != null) {
|
||||
var image = new Gtk.Image.from_icon_name("go-up-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
|
||||
var image = new Gtk.Image.from_icon_name("go-up-symbolic", Gtk.IconSize.BUTTON);
|
||||
image.halign = Gtk.Align.END;
|
||||
image.margin_end = 6;
|
||||
image.margin_top = 6;
|
||||
|
Loading…
x
Reference in New Issue
Block a user