@@ -57,16 +57,17 @@ public class Tuba.Dialogs.Report : Adw.Dialog {
5757 Adw . PreferencesPage page_2;
5858 Adw . PreferencesPage page_3;
5959 Adw . PreferencesPage page_4;
60- Adw . SwitchRow forward_switch;
6160 Adw . EntryRow additional_info;
6261
62+ Gee . HashMap<string, Adw . SwitchRow > forward_switches = new Gee .HashMap<string, Adw . SwitchRow > ();
6363 Gee . HashMap<Category , Gtk . CheckButton > check_buttons = new Gee .HashMap<Category , Gtk . CheckButton > ();
6464 Gee . HashMap<string, Gtk . CheckButton > rules_buttons = new Gee .HashMap<string, Gtk . CheckButton > ();
6565 Gee . HashMap<string, Gtk . CheckButton > status_buttons = new Gee .HashMap<string, Gtk . CheckButton > ();
6666 Category [] categories = {Category . SPAM };
6767 string account_id = " " ;
6868 string ? status_id = null ;
6969 bool has_rules = false ;
70+ string account_domain = " " ;
7071 construct {
7172 has_rules = accounts. active. instance_info. rules != null && accounts. active. instance_info. rules. size > 0 ;
7273
@@ -109,9 +110,10 @@ public class Tuba.Dialogs.Report : Adw.Dialog {
109110 this . close_attempt. connect (on_back);
110111 }
111112
112- public Report (API .Account account , string ? status_id = null ) {
113+ public Report (API .Account account , string ? status_id = null , Gee .ArrayList<API . Mention >? mentions = null ) {
114+ account_domain = account. domain;
113115 // translators: the variable is an account handle
114- this . title = _(" Reporting %s " ). printf (@" $(account.username)@$(account.domain )" );
116+ this . title = _(" Reporting %s " ). printf (@" $(account.username)@$(account_domain ) " );
115117 this . status_id = status_id;
116118 populate_posts (account. id, status_id);
117119 account_id = account. id;
@@ -121,7 +123,7 @@ public class Tuba.Dialogs.Report : Adw.Dialog {
121123 install_page_2 ();
122124 }
123125 install_page_3 ();
124- install_page_4 (account . domain );
126+ install_page_4 (mentions );
125127
126128 this . present (app. main_window);
127129 }
@@ -259,7 +261,7 @@ public class Tuba.Dialogs.Report : Adw.Dialog {
259261 carousel.append (page_3_stack );
260262 }
261263
262- private void install_page_4 (string domain ) {
264+ private void install_page_4 (Gee . ArrayList< API . Mention > ? mentions = null ) {
263265 page_4 = new Adw .PreferencesPage () {
264266 hexpand = true ,
265267 vexpand = true ,
@@ -279,20 +281,39 @@ public class Tuba.Dialogs.Report : Adw.Dialog {
279281 additional_info.changed.connect (on_additional_info_changed );
280282 group_4.add (additional_info );
281283
282- if (accounts .active .domain != domain ) {
283- forward_switch = new Adw .SwitchRow () {
284- // translators: you can find this string translated on https://github.com/mastodon/mastodon/tree/main/app/javascript/mastodon/locales
285- // the variable is an instance name e.g. 'Forward to mastodon.social'
286- title = _ ("Forward to %s ").printf (domain ),
287- active = true
288- };
289- group_4.add (forward_switch );
284+ if (accounts .active .domain != account_domain ) add_forward_row (account_domain , group_4 , true );
285+ if (accounts .active .tuba_api_versions .mastodon >= 2 && status_id != null && status_id != "" && mentions != null && mentions .size > 0 ) {
286+ mentions. @foreach (mention = > {
287+ if (mention. acct != null && mention. acct != " " && mention. acct. contains (" @" )) {
288+ string [] acct_parts = mention. acct. split (" @" , 2 );
289+ if (
290+ acct_parts. length >= 2
291+ && acct_parts[1 ] != " "
292+ && acct_parts[1 ] != account_domain
293+ && ! forward_switches. has_key (acct_parts[1 ])
294+ )
295+ add_forward_row (acct_parts[1 ], group_4, false );
296+ }
297+
298+ return true ;
299+ });
290300 }
291301
292302 page_4.add (group_4 );
293303 carousel.append (page_4 );
294304 }
295305
306+ private inline void add_forward_row (string temp_domain , Adw .PreferencesGroup group , bool active ) {
307+ var forward_switch = new Adw .SwitchRow () {
308+ // translators: you can find this string translated on https://github.com/mastodon/mastodon/tree/main/app/javascript/mastodon/locales
309+ // the variable is an instance name e.g. 'Forward to mastodon.social'
310+ title = _ ("Forward to %s ").printf (temp_domain ),
311+ active = active
312+ };
313+ group.add (forward_switch );
314+ forward_switches.set (temp_domain , forward_switch );
315+ }
316+
296317 private void on_back () {
297318 uint car_pos = (uint ) carousel. position;
298319 if (car_pos >= 1 ) {
@@ -343,13 +364,27 @@ public class Tuba.Dialogs.Report : Adw.Dialog {
343364 }
344365
345366 private void submit () {
346- bool forward = false ;
347- if (forward_switch != null ) forward = forward_switch. active;
348-
349367 var msg = new Request .POST (" /api/v1/reports" )
350368 .with_account (accounts. active)
351- .with_form_data (" account_id" , account_id)
352- .with_form_data (" forward" , forward. to_string ());
369+ .with_form_data (" account_id" , account_id);
370+
371+ if (forward_switches. size == 1 && forward_switches. has_key (account_domain)) {
372+ msg. with_form_data (" forward" , forward_switches. get (account_domain). active. to_string ());
373+ } else {
374+ bool has_forward = false ;
375+ forward_switches. foreach (e = > {
376+ if (((Adw . SwitchRow ) e. value ). active) {
377+ if (! has_forward) {
378+ has_forward = true ;
379+ msg. with_form_data (" forward" , " true" );
380+ }
381+ msg. with_form_data (" forward_to_domains[]" , ((string ) e. key));
382+ }
383+
384+ return true ;
385+ });
386+ if (! has_forward) msg. with_form_data (" forward" , " false" );
387+ }
353388
354389 if (additional_info. text != " " ) msg. with_form_data (" comment" , additional_info. text);
355390
0 commit comments