-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathGroupedNotificationsResults.vala
More file actions
118 lines (105 loc) · 3.83 KB
/
GroupedNotificationsResults.vala
File metadata and controls
118 lines (105 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
public class Tuba.API.GroupedNotificationsResults : Entity {
public class NotificationGroup : API.Notification, Widgetizable {
// public int64 most_recent_notification_id { get; set; }
public Gee.ArrayList<string> sample_account_ids { get; set; }
public string? status_id { get; set; default = null; }
public Gee.ArrayList<API.Account> tuba_accounts { get; set; }
public override Type deserialize_array_type (string prop) {
switch (prop) {
case "sample-account-ids":
return Type.STRING;
}
return base.deserialize_array_type (prop);
}
public NotificationGroup.from_notification (API.Notification notification) {
this.patch (notification);
// this.most_recent_notification_id = notification.id;
this.sample_account_ids = new Gee.ArrayList<string>.wrap ({notification.account.id});
if (notification.status != null) this.status_id = notification.status.id;
this.tuba_accounts = new Gee.ArrayList<API.Account>.wrap ({notification.account});
}
public override Gtk.Widget to_widget () {
if (tuba_accounts.size == 1 || group_key.has_prefix ("ungrouped-")) return base.to_widget ();
switch (this.kind) {
case InstanceAccount.KIND_FOLLOW:
case InstanceAccount.KIND_ADMIN_SIGNUP:
return create_basic_card ();
case InstanceAccount.KIND_MENTION:
case InstanceAccount.KIND_REBLOG:
case InstanceAccount.KIND_FAVOURITE:
case InstanceAccount.KIND_POLL:
case InstanceAccount.KIND_FOLLOW_REQUEST:
case InstanceAccount.KIND_REMOTE_REBLOG:
case InstanceAccount.KIND_EDITED:
case InstanceAccount.KIND_REPLY:
case InstanceAccount.KIND_SEVERED_RELATIONSHIPS:
case InstanceAccount.KIND_ADMIN_REPORT:
case InstanceAccount.KIND_STATUS:
case InstanceAccount.KIND_PLEROMA_REACTION:
case InstanceAccount.KIND_REACTION:
case InstanceAccount.KIND_ANNUAL_REPORT:
case InstanceAccount.KIND_MODERATION_WARNING:
case InstanceAccount.KIND_QUOTE:
case InstanceAccount.KIND_QUOTE_UPDATE:
return new Widgets.GroupedNotification (this);
default:
return base.to_widget ();
}
}
private Gtk.Widget create_basic_card () {
var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 16) {
margin_top = 8,
margin_bottom = 8,
margin_start = 16,
margin_end = 16
};
Tuba.InstanceAccount.Kind res_kind;
var sub_box = Widgets.GroupedNotification.group_box (this, this.kind, out res_kind);
var group_icon = new Gtk.Image.from_icon_name (res_kind.icon) {
margin_bottom = 22,
margin_top = 3,
css_classes = {"grouped-icon"},
halign = CENTER
};
switch (this.kind) {
case InstanceAccount.KIND_FAVOURITE:
group_icon.add_css_class ("star");
break;
case InstanceAccount.KIND_REBLOG:
group_icon.add_css_class ("reblog");
break;
case InstanceAccount.KIND_ADMIN_SIGNUP:
group_icon.add_css_class ("sign-up");
break;
case InstanceAccount.KIND_FOLLOW:
case InstanceAccount.KIND_FOLLOW_REQUEST:
group_icon.add_css_class ("follow");
break;
}
box.append (group_icon);
box.append (sub_box);
var row = new Widgets.ListBoxRowWrapper () {
child = box,
activatable = false
};
return row;
}
}
public Gee.ArrayList<API.Account> accounts { get; set; }
public Gee.ArrayList<API.Status> statuses { get; set; }
public Gee.ArrayList<NotificationGroup> notification_groups { get; set; }
public override Type deserialize_array_type (string prop) {
switch (prop) {
case "accounts":
return typeof (API.Account);
case "statuses":
return typeof (API.Status);
case "notification-groups":
return typeof (NotificationGroup);
}
return base.deserialize_array_type (prop);
}
public static GroupedNotificationsResults from (Json.Node node) throws Error {
return Entity.from_json (typeof (API.GroupedNotificationsResults), node) as API.GroupedNotificationsResults;
}
}