Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/GeopJr/Tuba into feat/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr committed Aug 11, 2023
2 parents 998a2f4 + 38aeeb1 commit d38e5f3
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 1 deletion.
4 changes: 3 additions & 1 deletion data/dev.geopjr.Tuba.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<key name="window-h" type="i">
<default>700</default>
</key>

<key name="muted-notification-types" type="as">
<default>[]</default>
</key>
</schema>
</schemalist>
89 changes: 89 additions & 0 deletions data/ui/dialogs/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,95 @@
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Push Notifications</property>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">New Followers</property>
<property name="activatable-widget">new_followers_notifications_switch</property>
<child>
<object class="GtkSwitch" id="new_followers_notifications_switch">
<property name="valign">center</property>
<property name="active">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">New Follower Requests</property>
<property name="activatable-widget">new_follower_requests_notifications_switch</property>
<child>
<object class="GtkSwitch" id="new_follower_requests_notifications_switch">
<property name="valign">center</property>
<property name="active">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Favorites</property>
<property name="activatable-widget">favorites_notifications_switch</property>
<child>
<object class="GtkSwitch" id="favorites_notifications_switch">
<property name="valign">center</property>
<property name="active">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Mentions</property>
<property name="activatable-widget">mentions_notifications_switch</property>
<child>
<object class="GtkSwitch" id="mentions_notifications_switch">
<property name="valign">center</property>
<property name="active">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Boosts</property>
<property name="activatable-widget">boosts_notifications_switch</property>
<child>
<object class="GtkSwitch" id="boosts_notifications_switch">
<property name="valign">center</property>
<property name="active">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Poll Results</property>
<property name="activatable-widget">poll_results_notifications_switch</property>
<child>
<object class="GtkSwitch" id="poll_results_notifications_switch">
<property name="valign">center</property>
<property name="active">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Edits</property>
<property name="activatable-widget">edits_notifications_switch</property>
<child>
<object class="GtkSwitch" id="edits_notifications_switch">
<property name="valign">center</property>
<property name="active">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
Expand Down
46 changes: 46 additions & 0 deletions src/Dialogs/Preferences.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[GtkTemplate (ui = "/dev/geopjr/Tuba/ui/dialogs/preferences.ui")]
public class Tuba.Dialogs.Preferences : Adw.PreferencesWindow {
struct NotificationTypeMute {
public Gtk.Switch switch_widget;
public string event;
}

[GtkChild] unowned Adw.ComboRow scheme_combo_row;
[GtkChild] unowned Adw.ComboRow post_visibility_combo_row;
Expand All @@ -19,6 +23,32 @@ public class Tuba.Dialogs.Preferences : Adw.PreferencesWindow {
[GtkChild] unowned Gtk.Switch media_viewer_expand_pictures;
[GtkChild] unowned Gtk.Switch enlarge_custom_emojis;

[GtkChild] unowned Gtk.Switch new_followers_notifications_switch;
[GtkChild] unowned Gtk.Switch new_follower_requests_notifications_switch;
[GtkChild] unowned Gtk.Switch favorites_notifications_switch;
[GtkChild] unowned Gtk.Switch mentions_notifications_switch;
[GtkChild] unowned Gtk.Switch boosts_notifications_switch;
[GtkChild] unowned Gtk.Switch poll_results_notifications_switch;
[GtkChild] unowned Gtk.Switch edits_notifications_switch;

NotificationTypeMute[] notification_type_mutes;

void update_notification_mutes () {
string[] res = {};

foreach (var notification_type_mute in notification_type_mutes) {
if (!notification_type_mute.switch_widget.active) res += notification_type_mute.event;
}

settings.muted_notification_types = res;
}

void update_notification_mutes_switches () {
foreach (var notification_type_mute in notification_type_mutes) {
notification_type_mute.switch_widget.active = !(notification_type_mute.event in settings.muted_notification_types);
}
}

private bool lang_changed { get; set; default=false; }

static construct {
Expand Down Expand Up @@ -48,11 +78,26 @@ public class Tuba.Dialogs.Preferences : Adw.PreferencesWindow {
}

setup_languages_combo_row ();
setup_notification_mutes ();
bind ();
show ();
close_request.connect (on_window_closed);
}

void setup_notification_mutes () {
notification_type_mutes = {
{ new_followers_notifications_switch, InstanceAccount.KIND_FOLLOW },
{ new_follower_requests_notifications_switch, InstanceAccount.KIND_FOLLOW_REQUEST },
{ favorites_notifications_switch, InstanceAccount.KIND_FAVOURITE },
{ mentions_notifications_switch, InstanceAccount.KIND_MENTION },
{ boosts_notifications_switch, InstanceAccount.KIND_REBLOG},
{ poll_results_notifications_switch, InstanceAccount.KIND_POLL},
{ edits_notifications_switch, InstanceAccount.KIND_EDITED }
};

update_notification_mutes_switches ();
}

public static void open () {
new Preferences ();
}
Expand Down Expand Up @@ -141,6 +186,7 @@ public class Tuba.Dialogs.Preferences : Adw.PreferencesWindow {
}
}

update_notification_mutes ();
return false;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Services/Accounts/InstanceAccount.vala
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ public class Tuba.InstanceAccount : API.Account, Streamable {
// }

public void send_toast (API.Notification obj) {
if (obj.kind != null && (obj.kind in settings.muted_notification_types)) return;

var toast = obj.to_toast (this);
var id = obj.id;
app.send_notification (id, toast);
Expand Down
3 changes: 3 additions & 0 deletions src/Services/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class Tuba.Settings : GLib.Settings {
public bool media_viewer_expand_pictures { get; set; }
public bool enlarge_custom_emojis { get; set; }

public string[] muted_notification_types { get; set; default = {}; }

public Settings () {
Object (schema_id: Build.DOMAIN);
init ("active-account");
Expand All @@ -40,6 +42,7 @@ public class Tuba.Settings : GLib.Settings {
init ("letterbox-media");
init ("media-viewer-expand-pictures");
init ("enlarge-custom-emojis");
init ("muted-notification-types");

changed.connect (on_changed);
}
Expand Down

0 comments on commit d38e5f3

Please sign in to comment.