Skip to content

Commit

Permalink
feat(Status): warn before copying link to a private post (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Nov 28, 2024
1 parent 44fa80f commit 68d272d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions data/dev.geopjr.Tuba.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
<key name="reply-to-old-post-reminder" type="b">
<default>true</default>
</key>
<key name="copy-private-link-reminder" type="b">
<default>true</default>
</key>
<key name="spellchecker-enabled" type="b">
<default>true</default>
</key>
Expand Down
5 changes: 5 additions & 0 deletions data/ui/dialogs/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@
<property name="title" translatable="yes">Warn before replying to an old post</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="copy_private_link_reminder">
<property name="title" translatable="yes">Warn before copying a link to a private post</property>
</object>
</child>
<child>
<object class="AdwEntryRow" id="proxy_entry">
<property name="show-apply-button">0</property>
Expand Down
2 changes: 2 additions & 0 deletions src/Dialogs/Preferences.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Services/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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",
Expand Down
34 changes: 32 additions & 2 deletions src/Widgets/Status.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 68d272d

Please sign in to comment.