Fix #800 - Add settings to don't send message if there are no media description

This commit is contained in:
Thomas 2023-02-27 16:14:35 +01:00
parent 19348ce031
commit 5d5f2f9c9a
6 changed files with 51 additions and 12 deletions

View File

@ -213,7 +213,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
if (statusDraft == null) {
statusDraft = ComposeAdapter.prepareDraft(statusList, composeAdapter, account.instance, account.user_id);
}
if (canBeSent(statusDraft)) {
if (canBeSent(statusDraft) != 0) {
if (promptSaveDraft) {
AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(ComposeActivity.this);
alt_bld.setMessage(R.string.save_draft);
@ -394,8 +394,10 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
if (statusDraft == null) {
statusDraft = ComposeAdapter.prepareDraft(statusList, composeAdapter, account.instance, account.user_id);
}
if (canBeSent(statusDraft)) {
if (canBeSent(statusDraft) == 1) {
MediaHelper.scheduleMessage(ComposeActivity.this, date -> storeDraft(true, date));
} else if (canBeSent(statusDraft) == -1) {
Toasty.warning(ComposeActivity.this, getString(R.string.toot_error_no_media_description), Toasty.LENGTH_SHORT).show();
} else {
Toasty.info(ComposeActivity.this, getString(R.string.toot_error_no_content), Toasty.LENGTH_SHORT).show();
}
@ -829,7 +831,18 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
statusDraft.user_id = account.user_id;
}
if (!canBeSent(statusDraft)) {
if (canBeSent(statusDraft) != 1) {
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (canBeSent(statusDraft) == -1) {
Toasty.warning(ComposeActivity.this, getString(R.string.toot_error_no_media_description), Toasty.LENGTH_SHORT).show();
} else {
Toasty.info(ComposeActivity.this, getString(R.string.toot_error_no_content), Toasty.LENGTH_SHORT).show();
}
statusDrafts.get(statusDrafts.size() - 1).submitted = false;
composeAdapter.notifyItemChanged(statusList.size() - 1);
};
mainHandler.post(myRunnable);
return;
}
if (statusDraft.id > 0) {
@ -915,22 +928,35 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
}
private boolean canBeSent(StatusDraft statusDraft) {
private int canBeSent(StatusDraft statusDraft) {
if (statusDraft == null) {
return false;
return 0;
}
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean checkAlt = sharedpreferences.getBoolean(getString(R.string.SET_MANDATORY_ALT_TEXT), false);
if (checkAlt) {
for (Status status : statusDraft.statusDraftList) {
if (status.media_attachments != null && status.media_attachments.size() > 0) {
for (Attachment attachment : status.media_attachments) {
if (attachment.description == null || attachment.description.trim().isEmpty()) {
return -1;
}
}
}
}
}
List<Status> statuses = statusDraft.statusDraftList;
if (statuses == null || statuses.size() == 0) {
return false;
return 0;
}
Status statusCheck = statuses.get(0);
if (statusCheck == null) {
return false;
return 0;
}
return (statusCheck.text != null && statusCheck.text.trim().length() != 0)
|| (statusCheck.media_attachments != null && statusCheck.media_attachments.size() != 0)
|| statusCheck.poll != null
|| (statusCheck.spoiler_text != null && statusCheck.spoiler_text.trim().length() != 0);
|| (statusCheck.spoiler_text != null && statusCheck.spoiler_text.trim().length() != 0) ? 1 : 0;
}

View File

@ -16,7 +16,6 @@ package app.fedilab.android.mastodon.services;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import androidx.annotation.NonNull;
@ -24,7 +23,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.unifiedpush.android.connector.MessagingReceiver;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.NotificationsHelper;
import app.fedilab.android.mastodon.helper.PushNotifications;
@ -40,7 +38,6 @@ public class CustomReceiver extends MessagingReceiver {
@Override
public void onMessage(@NotNull Context context, @NotNull byte[] message, @NotNull String slug) {
// Called when a new message is received. The message contains the full POST body of the push message
Log.v(Helper.TAG, "onMessage: " + slug);
new Thread(() -> {
try {
/*Notification notification = ECDHFedilab.decryptNotification(context, slug, message);

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

View File

@ -868,13 +868,14 @@
<string name="SET_DISPLAY_EMOJI" translatable="false">SET_DISPLAY_EMOJI</string>
<string name="SET_AGGREGATE_NOTIFICATION" translatable="false">SET_AGGREGATE_NOTIFICATION</string>
<string name="SET_DISPLAY_MEDIA_NOTIFICATION" translatable="false">SET_DISPLAY_MEDIA_NOTIFICATION</string>
x
<string name="SET_DISPLAY_CARD" translatable="false">SET_DISPLAY_CARD</string>
<string name="SET_DISPLAY_VIDEO_PREVIEWS" translatable="false">SET_DISPLAY_VIDEO_PREVIEWS</string>
<string name="SET_NOTIFICATION_ACTION" translatable="false">SET_NOTIFICATION_ACTION</string>
<string name="SET_FEATURED_TAGS" translatable="false">SET_FEATURED_TAGS</string>
<string name="SET_FEATURED_TAG_ACTION" translatable="false">SET_FEATURED_TAG_ACTION</string>
<string name="SET_MANDATORY_ALT_TEXT" translatable="false">SET_MANDATORY_ALT_TEXT</string>
<string name="SET_RETRIEVE_METADATA_IF_URL_FROM_EXTERAL" translatable="false">SET_RETRIEVE_METADATA_IF_URL_FROM_EXTERAL</string>
<string name="SET_TRANSLATE_VALUES_RESET" translatable="false">SET_TRANSLATE_VALUES_RESET</string>
<string-array name="SET_TRANSLATE_ENTRIES" translatable="false">
@ -1905,4 +1906,8 @@
<string name="translator_domain">Translator domain</string>
<string name="chat_timeline_for_direct">Chat timeline for direct messages</string>
<string name="more_media">%1$s more media</string>
<string name="set_alt_text_mandatory">Mandatory media descriptions</string>
<string name="set_alt_text_mandatory_description">The message will not be sent if a description is missing with a media</string>
<string name="toot_error_no_media_description">There are missing media descriptions</string>
</resources>

View File

@ -61,6 +61,14 @@
app:summary="@string/set_watermark_indication"
app:title="@string/set_watermark" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="@string/SET_MANDATORY_ALT_TEXT"
app:singleLineTitle="false"
app:summary="@string/set_alt_text_mandatory_description"
app:title="@string/set_alt_text_mandatory" />
<EditTextPreference
app:dependency="@string/SET_WATERMARK"
app:key="@string/SET_WATERMARK_TEXT"

View File

@ -1,9 +1,11 @@
Added:
- Settings compose: don't send media if there are no description (default: disabled)
Changed:
- Align media with text (left margin enabled)
Fixed:
- Media previews remain the same when sharing
- Accessibility (larger fonts): profiles/DM/
- Cross replies: Wrong visibility with the selected account
- Several crashes