1
1
[GtkTemplate (ui = " /dev/geopjr/Tuba/ui/widgets/announcement.ui" )]
2
2
public class Tuba.Widgets.Announcement : Gtk .ListBoxRow {
3
- public class ReactButton : Gtk .Button {
4
- private Gtk . Label reactions_label;
5
- public string shortcode { get ; private set ; }
6
- public signal void reaction_toggled ();
7
-
8
- private bool _has_reacted = false ;
9
- public bool has_reacted {
10
- get {
11
- return _has_reacted;
12
- }
13
- set {
14
- _has_reacted = value ;
15
- update_reacted (value );
16
- }
17
- }
18
-
19
- private int64 _reactions = 0 ;
20
- public int64 reactions {
21
- get {
22
- return _reactions;
23
- }
24
- set {
25
- _reactions = value ;
26
- reactions_label. label = value . to_string ();
27
- }
28
- }
29
-
30
- public ReactButton (API .EmojiReaction reaction ) {
31
- this . set_accessible_role (Gtk . AccessibleRole . TOGGLE_BUTTON );
32
-
33
- // translators: the variable is the emoji or its name if it's custom
34
- tooltip_text = _(" React with %s " ). printf (reaction. name);
35
- shortcode = reaction. name;
36
-
37
- var badge = new Gtk .Box (Gtk . Orientation . HORIZONTAL , 6 );
38
- if (reaction. url != null ) {
39
- badge. append (new Widgets .Emoji (reaction. url));
40
- } else {
41
- badge. append (new Gtk .Label (reaction. name));
42
- }
43
-
44
- reactions_label = new Gtk .Label (null );
45
- reactions = reaction. count;
46
-
47
- badge. append (reactions_label);
48
- this . child = badge;
49
-
50
- _has_reacted = reaction. me;
51
- if (reaction. me == true ) {
52
- this . add_css_class (" accent" );
53
- this . update_state (Gtk . AccessibleState . PRESSED , Gtk . AccessibleTristate . TRUE , - 1 );
54
- }
55
-
56
- this . clicked. connect (on_clicked);
57
- }
58
-
59
- public void update_reacted (bool reacted = true ) {
60
- if (reacted) {
61
- this . add_css_class (" accent" );
62
- reactions = reactions + 1 ;
63
- this . update_state (Gtk . AccessibleState . PRESSED , Gtk . AccessibleTristate . TRUE , - 1 );
64
- } else {
65
- this . remove_css_class (" accent" );
66
- reactions = reactions - 1 ;
67
- this . update_state (Gtk . AccessibleState . PRESSED , Gtk . AccessibleTristate . FALSE , - 1 );
68
- }
69
- _has_reacted = reacted;
70
- }
71
-
72
- private void on_clicked () {
73
- reaction_toggled ();
74
- }
75
- }
76
-
77
- private API . Announcement announcement { get ; private set ; }
78
3
public signal void open ();
79
4
80
5
[GtkChild ] protected unowned Adw . Avatar avatar;
@@ -84,7 +9,7 @@ public class Tuba.Widgets.Announcement : Gtk.ListBoxRow {
84
9
[GtkChild ] protected unowned Gtk . Image attention_indicator;
85
10
[GtkChild ] protected unowned Gtk . Label date_label;
86
11
[GtkChild ] protected unowned Widgets . MarkupView content;
87
- [GtkChild ] protected unowned Gtk . FlowBox emoji_reactions ;
12
+ [GtkChild ] protected unowned Gtk . Box mainbox ;
88
13
89
14
private void aria_describe_status () {
90
15
// translators: This is an accessibility label.
@@ -142,37 +67,6 @@ public class Tuba.Widgets.Announcement : Gtk.ListBoxRow {
142
67
);
143
68
}
144
69
145
- private Gee . ArrayList<API . EmojiReaction > ? reactions {
146
- set {
147
- if (value == null ) return ;
148
-
149
- var i = 0 ;
150
- Gtk . FlowBoxChild ? fb_child = null ;
151
- while ((fb_child = emoji_reactions. get_child_at_index (i)) != null ) {
152
- emoji_reactions. remove (fb_child);
153
- i = i + 1 ;
154
- }
155
-
156
- foreach (API . EmojiReaction p in value ) {
157
- if (p. count <= 0 ) return ;
158
-
159
- var badge_button = new ReactButton (p);
160
- badge_button. reaction_toggled. connect (on_reaction_toggled);
161
-
162
- // emoji_reactions.append(badge_button); // GTK >= 4.5
163
- emoji_reactions. insert (
164
- new Gtk .FlowBoxChild () {
165
- child = badge_button,
166
- focusable = false
167
- },
168
- - 1
169
- );
170
- }
171
-
172
- emoji_reactions. visible = value . size > 0 ;
173
- }
174
- }
175
-
176
70
void settings_updated () {
177
71
Tuba . toggle_css (this , settings. larger_font_size, " ttl-status-font-large" );
178
72
Tuba . toggle_css (this , settings. larger_line_height, " ttl-status-line-height-large" );
@@ -199,8 +93,6 @@ public class Tuba.Widgets.Announcement : Gtk.ListBoxRow {
199
93
string announcement_date;
200
94
int reactions_count = 0 ;
201
95
public Announcement (API .Announcement t_announcement ) {
202
- announcement = t_announcement;
203
-
204
96
content. instance_emojis = t_announcement. emojis_map;
205
97
content. content = t_announcement. content;
206
98
attention_indicator. visible = ! t_announcement. read;
@@ -226,34 +118,17 @@ public class Tuba.Widgets.Announcement : Gtk.ListBoxRow {
226
118
if (instance_title != " " ) avatar. show_initials = true ;
227
119
if (instance_thumbnail != " " ) Tuba . Helper . Image . request_paintable (instance_thumbnail, null , false , on_cache_response);
228
120
229
- reactions = t_announcement. reactions;
230
121
reactions_count = t_announcement. reactions. size;
122
+ if (reactions_count > 0 )
123
+ mainbox. append (new Widgets .ReactionsRow (t_announcement. id, t_announcement. reactions, true ) {
124
+ margin_top = 16
125
+ });
231
126
232
- announcement . bind_property (" read" , attention_indicator, " visible" , GLib . BindingFlags . SYNC_CREATE | GLib . BindingFlags . INVERT_BOOLEAN );
127
+ t_announcement . bind_property (" read" , attention_indicator, " visible" , GLib . BindingFlags . SYNC_CREATE | GLib . BindingFlags . INVERT_BOOLEAN );
233
128
aria_describe_status ();
234
129
}
235
130
236
131
void on_cache_response (Gdk .Paintable ? data ) {
237
132
avatar. custom_image = data;
238
133
}
239
-
240
- private void on_reaction_toggled (ReactButton btn ) {
241
- var endpoint = @" /api/v1/announcements/$(announcement.id)/reactions/$(btn.shortcode)" ;
242
- var req = btn. has_reacted ? new Request .DELETE (endpoint) : new Request .PUT (endpoint);
243
-
244
- btn. sensitive = false ;
245
- req
246
- .with_account (accounts. active)
247
- .then (() = > {
248
- btn. update_reacted (! btn. has_reacted);
249
- btn. sensitive = true ;
250
- })
251
- .on_error ((code, message) = > {
252
- warning (@" Error while reacting to announcement: $code $message " );
253
- btn. sensitive = true ;
254
-
255
- app. toast (" %s : %s " . printf (_(" Error" ), message));
256
- })
257
- .exec ();
258
- }
259
134
}
0 commit comments