mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #1257 from deltachat/autodelete
autodelete messages from server
This commit is contained in:
@@ -605,6 +605,13 @@ JNIEXPORT jint Java_com_b44t_messenger_DcContext_getFreshMsgCount(JNIEnv *env, j
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint Java_com_b44t_messenger_DcContext_estimateDeletionCount(JNIEnv *env, jobject obj, jboolean from_server, jlong seconds)
|
||||
{
|
||||
return dc_estimate_deletion_cnt(get_dc_context(env, obj), from_server, seconds);
|
||||
}
|
||||
|
||||
|
||||
|
||||
JNIEXPORT jlong Java_com_b44t_messenger_DcContext_getMsgCPtr(JNIEnv *env, jobject obj, jint id)
|
||||
{
|
||||
return (jlong)dc_get_msg(get_dc_context(env, obj), id);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/i_understand"
|
||||
android:text="@string/autodel_confirm"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="8dp"
|
||||
/>
|
||||
|
||||
</FrameLayout>
|
||||
@@ -143,6 +143,39 @@
|
||||
<item>@string/mute_forever</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="autodel_device_durations">
|
||||
<item>@string/off</item>
|
||||
<item>@string/autodel_after_1_hour</item>
|
||||
<item>@string/autodel_after_1_day</item>
|
||||
<item>@string/autodel_after_1_week</item>
|
||||
<item>@string/autodel_after_4_weeks</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="autodel_device_values">
|
||||
<item>0</item>
|
||||
<item>3600</item>
|
||||
<item>86400</item>
|
||||
<item>604800</item>
|
||||
<item>2419200</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="autodel_server_durations">
|
||||
<item>@string/off</item>
|
||||
<item>@string/autodel_at_once</item>
|
||||
<item>@string/autodel_after_1_hour</item>
|
||||
<item>@string/autodel_after_1_day</item>
|
||||
<item>@string/autodel_after_1_week</item>
|
||||
<item>@string/autodel_after_4_weeks</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="autodel_server_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>3600</item>
|
||||
<item>86400</item>
|
||||
<item>604800</item>
|
||||
<item>2419200</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="share_location_durations">
|
||||
<item>@string/share_location_for_5_minutes</item>
|
||||
|
||||
+15
-7
@@ -367,13 +367,6 @@
|
||||
<string name="pref_using_default">Using default: %s</string>
|
||||
<string name="pref_profile_info_headline">Your profile info</string>
|
||||
<string name="pref_profile_photo">Profile picture</string>
|
||||
<string name="pref_trim_headline">Message trimming</string>
|
||||
<string name="pref_trim_option">Delete old messages</string>
|
||||
<string name="pref_trim_option_explain">Automatically delete older messages once a chat exceeds a specified length</string>
|
||||
<string name="pref_trim_length_limit">Chat length limit</string>
|
||||
<string name="pref_trim_length_limit_summary">%d messages per chat</string>
|
||||
<string name="pref_trim_now_button">Trim all chats now</string>
|
||||
<string name="pref_trim_now_ask">Delete all old messages now? This will immediately trim all chats to the %d most recent messages.</string>
|
||||
<string name="pref_blocked_contacts">Blocked contacts</string>
|
||||
<string name="pref_profile_photo_remove_ask">Remove profile photo?</string>
|
||||
<string name="pref_help_url">https://delta.chat/help</string>
|
||||
@@ -473,6 +466,21 @@
|
||||
<string name="pref_background_custom_image">Custom image</string>
|
||||
<string name="pref_background_custom_color">Custom color</string>
|
||||
|
||||
<!-- automatically delete message -->
|
||||
<string name="autodel_title">Auto-delete messages</string>
|
||||
<string name="autodel_title_short">Auto-delete</string>
|
||||
<string name="autodel_device_title">Delete messages from device</string>
|
||||
<string name="autodel_server_title">Delete messages from server</string>
|
||||
<!-- %1$d will be replaced by the number of messages, you can assume plural/lots here. %1$s will be replaced by a timespan in italics or so. -->
|
||||
<string name="autodel_device_ask">Do you want to delete %1$d messages now and all newly fetched messages %2$s in the future?\n\n• This includes all media\n\n• Message will be deleted whether they were seen or not\n\n• \"Saved messages\" will be skipped from local deletion</string>
|
||||
<string name="autodel_server_ask">Do you want to delete %1$d messages now and all newly fetched messages %2$s in the future?\n\n• This includes all media\n\n• This will also delete emails affected by the \"Show classic emails\" option\n\n• \"Saved messages\" will be deleted from the server as well</string>
|
||||
<string name="autodel_confirm">I understand, delete all these messages</string>
|
||||
<string name="autodel_at_once">At once</string>
|
||||
<string name="autodel_after_1_hour">After 1 hour</string>
|
||||
<string name="autodel_after_1_day">After 1 day</string>
|
||||
<string name="autodel_after_1_week">After 1 week</string>
|
||||
<string name="autodel_after_4_weeks">After 4 weeks</string>
|
||||
|
||||
<!-- autocrypt -->
|
||||
<string name="autocrypt">Autocrypt</string>
|
||||
<string name="autocrypt_explain">Autocrypt is a new and open specification for automatic end-to-end email encryption.\n\nYour end-to-end setup is created automatically as needed and you can transfer it between devices with Autocrypt Setup Messages.</string>
|
||||
|
||||
@@ -34,29 +34,23 @@
|
||||
android:entryValues="@array/pref_compression_values"
|
||||
android:defaultValue="0" />
|
||||
|
||||
<PreferenceCategory android:title="@string/autodel_title">
|
||||
<ListPreference
|
||||
android:key="autodel_device"
|
||||
android:title="@string/autodel_device_title"
|
||||
android:entries="@array/autodel_device_durations"
|
||||
android:entryValues="@array/autodel_device_values"/>
|
||||
|
||||
<ListPreference
|
||||
android:key="autodel_server"
|
||||
android:title="@string/autodel_server_title"
|
||||
android:entries="@array/autodel_server_durations"
|
||||
android:entryValues="@array/autodel_server_values" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_backup">
|
||||
<Preference android:key="pref_backup"
|
||||
android:title="@string/pref_backup_explain"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<!--
|
||||
<PreferenceCategory android:key="message_trimming" android:title="@string/pref_trim_headline">
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_trim_threads"
|
||||
android:summary="@string/pref_trim_option_explain"
|
||||
android:title="@string/pref_trim_option" />
|
||||
|
||||
<EditTextPreference android:defaultValue="500"
|
||||
android:key="pref_trim_length"
|
||||
android:title="@string/pref_trim_length_limit"
|
||||
android:inputType="number"
|
||||
android:dependency="pref_trim_threads" />
|
||||
|
||||
<Preference android:key="pref_trim_now"
|
||||
android:title="@string/pref_trim_now_button"
|
||||
android:dependency="pref_trim_threads" />
|
||||
</PreferenceCategory>
|
||||
-->
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -154,6 +154,7 @@ public class DcContext {
|
||||
public @NonNull DcMsg getMsg (int msg_id) { return new DcMsg(getMsgCPtr(msg_id)); }
|
||||
public native String getMsgInfo (int id);
|
||||
public native int getFreshMsgCount (int chat_id);
|
||||
public native int estimateDeletionCount(boolean from_server, long seconds);
|
||||
public native void deleteMsgs (int msg_ids[]);
|
||||
public native void forwardMsgs (int msg_ids[], int chat_id);
|
||||
public native int prepareMsg (int chat_id, DcMsg msg);
|
||||
|
||||
@@ -8,8 +8,14 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.CheckBoxPreference;
|
||||
import androidx.preference.EditTextPreference;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
@@ -30,10 +36,11 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
private static final String TAG = ChatsPreferenceFragment.class.getSimpleName();
|
||||
|
||||
|
||||
ListPreference showEmails;
|
||||
CheckBoxPreference readReceiptsCheckbox;
|
||||
private ListPreference showEmails;
|
||||
private CheckBoxPreference readReceiptsCheckbox;
|
||||
|
||||
// CheckBoxPreference trimEnabledCheckbox;
|
||||
private ListPreference autoDelDevice;
|
||||
private ListPreference autoDelServer;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle paramBundle) {
|
||||
@@ -57,13 +64,11 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
Preference backup = this.findPreference("pref_backup");
|
||||
backup.setOnPreferenceClickListener(new BackupListener());
|
||||
|
||||
// trimEnabledCheckbox = (CheckBoxPreference) findPreference("pref_trim_threads");
|
||||
// trimEnabledCheckbox.setOnPreferenceChangeListener(new TrimEnabledListener());
|
||||
//
|
||||
// findPreference("pref_trim_length")
|
||||
// .setOnPreferenceChangeListener(new TrimLengthValidationListener());
|
||||
// findPreference("pref_trim_now")
|
||||
// .setOnPreferenceClickListener(new TrimNowClickListener());
|
||||
autoDelDevice = findPreference("autodel_device");
|
||||
autoDelDevice.setOnPreferenceChangeListener(new AutodelChangeListener("delete_device_after"));
|
||||
|
||||
autoDelServer = findPreference("autodel_server");
|
||||
autoDelServer.setOnPreferenceChangeListener(new AutodelChangeListener("delete_server_after"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,9 +86,19 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
String value = Integer.toString(dcContext.getConfigInt("show_emails"));
|
||||
showEmails.setValue(value);
|
||||
updateListSummary(showEmails, value);
|
||||
readReceiptsCheckbox.setChecked(0 != dcContext.getConfigInt("mdns_enabled", DcContext.DC_PREF_DEFAULT_MDNS_ENABLED));
|
||||
readReceiptsCheckbox.setChecked(0 != dcContext.getConfigInt("mdns_enabled"));
|
||||
|
||||
// trimEnabledCheckbox.setChecked(0!=dcContext.getConfigInt("trim_enabled", DcContext.DC_PREF_DEFAULT_TRIM_ENABLED));
|
||||
initAutodelFromCore();
|
||||
}
|
||||
|
||||
private void initAutodelFromCore() {
|
||||
String value = Integer.toString(dcContext.getConfigInt("delete_server_after"));
|
||||
autoDelServer.setValue(value);
|
||||
updateListSummary(autoDelServer, value);
|
||||
|
||||
value = Integer.toString(dcContext.getConfigInt("delete_device_after"));
|
||||
autoDelDevice.setValue(value);
|
||||
updateListSummary(autoDelDevice, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,69 +116,14 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
}
|
||||
}
|
||||
|
||||
// private class TrimEnabledListener implements Preference.OnPreferenceChangeListener {
|
||||
// @Override
|
||||
// public boolean onPreferenceChange(final Preference preference, Object newValue) {
|
||||
// boolean enabled = (Boolean) newValue;
|
||||
// dcContext.setConfigInt("trim_enabled", enabled? 1 : 0);
|
||||
// Toast.makeText(getActivity(), "Not yet implemented.", Toast.LENGTH_LONG).show();
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class TrimLengthValidationListener implements Preference.OnPreferenceChangeListener {
|
||||
//
|
||||
// public TrimLengthValidationListener() {
|
||||
// EditTextPreference preference = (EditTextPreference)findPreference("pref_trim_length");
|
||||
// onPreferenceChange(preference, dcContext.getConfig("trim_length", ""+DcContext.DC_PREF_DEFAULT_TRIM_LENGTH));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
// if (newValue == null || ((String)newValue).trim().length() == 0) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// int value;
|
||||
// try {
|
||||
// value = Integer.parseInt((String)newValue);
|
||||
// } catch (NumberFormatException nfe) {
|
||||
// Log.w(TAG, nfe);
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (value < 1) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// dcContext.setConfigInt("trim_length", value);
|
||||
// preference.setSummary(getResources().getString(R.string.pref_trim_length_limit_summary, value));
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class TrimNowClickListener implements Preference.OnPreferenceClickListener {
|
||||
// @Override
|
||||
// public boolean onPreferenceClick(Preference preference) {
|
||||
// final int threadLengthLimit = dcContext.getConfigInt("trim_length", DcContext.DC_PREF_DEFAULT_TRIM_LENGTH);
|
||||
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
// builder.setMessage(getResources().getString(R.string.pref_trim_now_ask,
|
||||
// threadLengthLimit));
|
||||
// builder.setPositiveButton(R.string.ok,
|
||||
// (dialog, which) -> Toast.makeText(getActivity(), "Not yet implemented.", Toast.LENGTH_LONG).show());
|
||||
//
|
||||
// builder.setNegativeButton(android.R.string.cancel, null);
|
||||
// builder.show();
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
public static CharSequence getSummary(Context context) {
|
||||
DcContext dcContext = DcHelper.getContext(context);
|
||||
final String onRes = context.getString(R.string.on);
|
||||
final String offRes = context.getString(R.string.off);
|
||||
String readReceiptState = DcHelper.getContext(context).getConfigInt("mdns_enabled", DcContext.DC_PREF_DEFAULT_MDNS_ENABLED)!=0? onRes : offRes;
|
||||
return context.getString(R.string.pref_read_receipts) + " " + readReceiptState;
|
||||
String readReceiptState = dcContext.getConfigInt("mdns_enabled")!=0? onRes : offRes;
|
||||
String autodelState = (dcContext.getConfigInt("delete_device_after")!=0 || dcContext.getConfigInt("delete_server_after")!=0)? onRes : offRes;
|
||||
return context.getString(R.string.pref_read_receipts) + " " + readReceiptState +
|
||||
", " + context.getString(R.string.autodel_title_short) + " " + autodelState;
|
||||
}
|
||||
|
||||
private class BlockedContactsClickListener implements Preference.OnPreferenceClickListener {
|
||||
@@ -185,6 +145,49 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private class AutodelChangeListener implements Preference.OnPreferenceChangeListener {
|
||||
private String coreKey;
|
||||
|
||||
AutodelChangeListener(String coreKey) {
|
||||
this.coreKey = coreKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int timeout = Util.objectToInt(newValue);
|
||||
if (timeout>0) {
|
||||
Context context = preference.getContext();
|
||||
boolean fromServer = coreKey.equals("delete_server_after");
|
||||
int delCount = DcHelper.getContext(context).estimateDeletionCount(fromServer, timeout);
|
||||
|
||||
View gl = View.inflate(getActivity(), R.layout.autodel_confirm, null);
|
||||
CheckBox confirmCheckbox = gl.findViewById(R.id.i_understand);
|
||||
String msg = context.getString(fromServer?
|
||||
R.string.autodel_server_ask : R.string.autodel_device_ask,
|
||||
delCount, "<i>"+getSelectedSummary(preference, newValue)+"</i>");
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(preference.getTitle())
|
||||
.setMessage(Html.fromHtml(msg.replace("\n", "<br>")))
|
||||
.setView(gl)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, whichButton) -> {
|
||||
if (confirmCheckbox.isChecked()) {
|
||||
dcContext.setConfigInt(coreKey, timeout);
|
||||
initAutodelFromCore();
|
||||
} else {
|
||||
onPreferenceChange(preference, newValue);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, (dialog, whichButton) -> initAutodelFromCore())
|
||||
.show();
|
||||
} else {
|
||||
updateListSummary(preference, newValue);
|
||||
dcContext.setConfigInt(coreKey, timeout);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************************************
|
||||
* Backup
|
||||
**********************************************************************************************/
|
||||
|
||||
@@ -44,13 +44,17 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateListSummary(Preference preference, Object value) {
|
||||
protected String getSelectedSummary(Preference preference, Object value) {
|
||||
ListPreference listPref = (ListPreference) preference;
|
||||
int entryIndex = Arrays.asList(listPref.getEntryValues()).indexOf(value);
|
||||
return entryIndex >= 0 && entryIndex < listPref.getEntries().length
|
||||
? listPref.getEntries()[entryIndex].toString()
|
||||
: getString(R.string.unknown);
|
||||
}
|
||||
|
||||
listPref.setSummary(entryIndex >= 0 && entryIndex < listPref.getEntries().length
|
||||
? listPref.getEntries()[entryIndex]
|
||||
: getString(R.string.unknown));
|
||||
protected void updateListSummary(Preference preference, Object value) {
|
||||
ListPreference listPref = (ListPreference) preference;
|
||||
listPref.setSummary(getSelectedSummary(preference, value));
|
||||
}
|
||||
|
||||
protected void initializeListSummary(ListPreference pref) {
|
||||
|
||||
Reference in New Issue
Block a user