From d92e2407f3f692fd7d6c5ea6fc506c27f6601fc2 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 25 Oct 2023 14:44:20 +0200 Subject: [PATCH 1/2] Remove garbage alt text from images attached via Gboard See also: https://github.com/tuskyapp/Tusky/pull/4068 ---- Steps to reproduce: 1. install Gboard (https://play.google.com/store/apps/details?id=com.google.android.inputmethod.latin) 2. open a direct link to any image in Firefox 3. long-press the image to get a "Copy Image" dialogue (and copy the image) 4. compose a new post in Tusky 5. Gboard will suggest to paste the image from clipboard 6. paste image, see that when opening alt text editor, it is filled out with this garbage string Why is this bad? It's not when I just fix the alt text. But it breaks every mechanism that is supposed to remind me of adding alt text. It's hard to argue that this is within scope of this app but I also don't see it getting fixed in Gboard, so here we go. --- .../ComposeMediaViewController.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java b/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java index 7eba1cd7f..95ab1f3a2 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java @@ -125,8 +125,26 @@ public class ComposeMediaViewController{ updateMediaAttachmentsLayout(); } } + + private String sanitizeMediaDescription(String description){ + if(description == null){ + return null; + } + + // The Gboard android keyboard attaches this text whenever the user + // pastes something from the keyboard's suggestion bar. + // Due to different end user locales, the exact text may vary, but at + // least in version 13.4.08, all of the translations contained the + // string "Gboard". + if (description.contains("Gboard")){ + return null; + } + + return description; + } public boolean addMediaAttachment(Uri uri, String description){ + description = sanitizeMediaDescription(description); if(getMediaAttachmentsCount()==MAX_ATTACHMENTS){ showMediaAttachmentError(fragment.getResources().getQuantityString(R.plurals.cant_add_more_than_x_attachments, MAX_ATTACHMENTS, MAX_ATTACHMENTS)); return false; From 015e63ba6643183353e662f147bb2631df524782 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 25 Oct 2023 21:50:10 +0200 Subject: [PATCH 2/2] apply review feedback --- .../android/fragments/ComposeFragment.java | 18 ++++++++++++++++++ .../ComposeMediaViewController.java | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index 7aaa337ab..8322d042d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -1012,8 +1012,26 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr return new String[]{"image/jpeg", "image/gif", "image/png", "video/mp4"}; } + private String sanitizeMediaDescription(String description){ + if(description == null){ + return null; + } + + // The Gboard android keyboard attaches this text whenever the user + // pastes something from the keyboard's suggestion bar. + // Due to different end user locales, the exact text may vary, but at + // least in version 13.4.08, all of the translations contained the + // string "Gboard". + if (description.contains("Gboard")){ + return null; + } + + return description; + } + @Override public boolean onAddMediaAttachmentFromEditText(Uri uri, String description){ + description = sanitizeMediaDescription(description); return mediaViewController.addMediaAttachment(uri, description); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java b/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java index 95ab1f3a2..94170fd62 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ComposeMediaViewController.java @@ -126,25 +126,7 @@ public class ComposeMediaViewController{ } } - private String sanitizeMediaDescription(String description){ - if(description == null){ - return null; - } - - // The Gboard android keyboard attaches this text whenever the user - // pastes something from the keyboard's suggestion bar. - // Due to different end user locales, the exact text may vary, but at - // least in version 13.4.08, all of the translations contained the - // string "Gboard". - if (description.contains("Gboard")){ - return null; - } - - return description; - } - public boolean addMediaAttachment(Uri uri, String description){ - description = sanitizeMediaDescription(description); if(getMediaAttachmentsCount()==MAX_ATTACHMENTS){ showMediaAttachmentError(fragment.getResources().getQuantityString(R.plurals.cant_add_more_than_x_attachments, MAX_ATTACHMENTS, MAX_ATTACHMENTS)); return false;