From 68d272d8ee5cb6d639c11c46a7102639bd1bff9c Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Thu, 28 Nov 2024 02:49:17 +0200 Subject: [PATCH] feat(Status): warn before copying link to a private post (#1222) --- data/dev.geopjr.Tuba.gschema.xml | 3 +++ data/ui/dialogs/preferences.ui | 5 +++++ src/Dialogs/Preferences.vala | 2 ++ src/Services/Settings.vala | 2 ++ src/Widgets/Status.vala | 34 ++++++++++++++++++++++++++++++-- 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/data/dev.geopjr.Tuba.gschema.xml b/data/dev.geopjr.Tuba.gschema.xml index 87348043b..bae42d3d7 100644 --- a/data/dev.geopjr.Tuba.gschema.xml +++ b/data/dev.geopjr.Tuba.gschema.xml @@ -85,6 +85,9 @@ true + + true + true diff --git a/data/ui/dialogs/preferences.ui b/data/ui/dialogs/preferences.ui index 3b5288e04..24eac9185 100644 --- a/data/ui/dialogs/preferences.ui +++ b/data/ui/dialogs/preferences.ui @@ -164,6 +164,11 @@ Warn before replying to an old post + + + Warn before copying a link to a private post + + 0 diff --git a/src/Dialogs/Preferences.vala b/src/Dialogs/Preferences.vala index 8ad9f0ed9..465fbd0be 100644 --- a/src/Dialogs/Preferences.vala +++ b/src/Dialogs/Preferences.vala @@ -129,6 +129,7 @@ public class Tuba.Dialogs.Preferences : Adw.PreferencesDialog { [GtkChild] unowned Adw.SwitchRow advanced_boost_dialog; [GtkChild] unowned Adw.SwitchRow darken_images_on_dark_mode; [GtkChild] unowned Adw.SwitchRow reply_to_old_post_reminder; + [GtkChild] unowned Adw.SwitchRow copy_private_link_reminder; [GtkChild] unowned Adw.EntryRow proxy_entry; [GtkChild] unowned Adw.SwitchRow dim_trivial_notifications; @@ -301,6 +302,7 @@ public class Tuba.Dialogs.Preferences : Adw.PreferencesDialog { settings.bind ("advanced-boost-dialog", advanced_boost_dialog, "active", SettingsBindFlags.DEFAULT); settings.bind ("darken-images-on-dark-mode", darken_images_on_dark_mode, "active", SettingsBindFlags.DEFAULT); settings.bind ("reply-to-old-post-reminder", reply_to_old_post_reminder, "active", SettingsBindFlags.DEFAULT); + settings.bind ("copy-private-link-reminder", copy_private_link_reminder, "active", SettingsBindFlags.DEFAULT); settings.bind ("dim-trivial-notifications", dim_trivial_notifications, "active", SettingsBindFlags.DEFAULT); settings.bind ("analytics", analytics_switch, "active", SettingsBindFlags.DEFAULT); settings.bind ("update-contributors", update_contributors, "active", SettingsBindFlags.DEFAULT); diff --git a/src/Services/Settings.vala b/src/Services/Settings.vala index fabde08ed..39e84a36f 100644 --- a/src/Services/Settings.vala +++ b/src/Services/Settings.vala @@ -122,6 +122,7 @@ public class Tuba.Settings : GLib.Settings { public bool group_push_notifications { get; set; } public bool advanced_boost_dialog { get; set; } public bool reply_to_old_post_reminder { get; set; } + public bool copy_private_link_reminder { get; set; } public bool spellchecker_enabled { get; set; } public bool darken_images_on_dark_mode { get; set; } public double media_viewer_last_used_volume { get; set; } @@ -154,6 +155,7 @@ public class Tuba.Settings : GLib.Settings { "group-push-notifications", "advanced-boost-dialog", "reply-to-old-post-reminder", + "copy-private-link-reminder", "spellchecker-enabled", "darken-images-on-dark-mode", "media-viewer-last-used-volume", diff --git a/src/Widgets/Status.vala b/src/Widgets/Status.vala index ca3bf4a16..3e481a711 100644 --- a/src/Widgets/Status.vala +++ b/src/Widgets/Status.vala @@ -369,8 +369,38 @@ } private void copy_url () { - Host.copy (status.formal.url ?? status.formal.account.url); - app.toast (_("Copied post url to clipboard")); + if (status.formal.url != null && settings.copy_private_link_reminder && (status.formal.visibility == "direct" || status.formal.visibility == "private")) { + string body; + if (status.formal.visibility == "direct") { + body = _("Only mentioned people will be able to view it."); + } else if (status.formal.account.is_self ()) { + body = _("Only mentioned people and your followers will be able to view it."); + } else { + // translators: dialog subtitle shown when copying a link to a private post, the variable is a handle + body = _("Only mentioned people and people that follow %s will be able to view it.").printf (status.formal.account.full_handle); + } + + app.question.begin ( + // translators: the variable is the post visibility e.g. Public, Unlisted... + {_("This post's visibility is %s").printf (accounts.active.visibility[status.formal.visibility].name), false}, + { body, false }, + app.main_window, + { { _("Copy"), Adw.ResponseAppearance.SUGGESTED }, { _("Don't remind me again"), Adw.ResponseAppearance.DEFAULT } }, + null, + false, + (obj, res) => { + if (app.question.end (res) == Tuba.Application.QuestionAnswer.NO) { + settings.copy_private_link_reminder = false; + } + + Host.copy (status.formal.url); + app.toast (_("Copied post url to clipboard")); + } + ); + } else { + Host.copy (status.formal.url ?? status.formal.account.url); + app.toast (_("Copied post url to clipboard")); + } } private void open_in_browser () {