per contact notifications throttling settings

This commit is contained in:
kosyak 2024-05-22 21:29:23 +02:00
parent 0494569a29
commit 7b8a61e068
7 changed files with 70 additions and 26 deletions

View file

@ -154,6 +154,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public static final String NEXT_COUNTERPART = "next_counterpart";
public static final String ATTRIBUTE_MUTED_TILL = "muted_till";
public static final String ATTRIBUTE_NOTIFICATIONS_THROTTLING_PERIOD = "notifications_throlttling_period";
public static final String ATTRIBUTE_ALWAYS_NOTIFY = "always_notify";
public static final String ATTRIBUTE_LAST_CLEAR_HISTORY = "last_clear_history";
public static final String ATTRIBUTE_FORMERLY_PRIVATE_NON_ANONYMOUS = "formerly_private_non_anonymous";
@ -1108,6 +1110,14 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return System.currentTimeMillis() < this.getLongAttribute(ATTRIBUTE_MUTED_TILL, 0);
}
public void setNotificationThrottlingPeriod(long value) {
this.setAttribute(ATTRIBUTE_NOTIFICATIONS_THROTTLING_PERIOD, String.valueOf(value));
}
public long getNotificationThrottlingPeriod() {
return this.getLongAttribute(ATTRIBUTE_NOTIFICATIONS_THROTTLING_PERIOD, -1);
}
public boolean alwaysNotify() {
return mode == MODE_SINGLE || getBooleanAttribute(ATTRIBUTE_ALWAYS_NOTIFY, Config.ALWAYS_NOTIFY_BY_DEFAULT || isPrivateAndNonAnonymous());
}

View file

@ -961,7 +961,13 @@ public class NotificationService {
return false;
}
long throttlingPeriod = mXmppConnectionService.getLongPreference("notification_throttling_period", R.integer.default_notification_throttling_period);
Conversation c = mXmppConnectionService.findConversationByUuid(conversationUuid);
if (c == null) {
return false;
}
long throttlingPeriod = c.getNotificationThrottlingPeriod();
if (throttlingPeriod <= 0) {
return false;

View file

@ -2023,6 +2023,9 @@ public class ConversationFragment extends XmppFragment
case R.id.action_unmute:
unMuteConversation(conversation);
break;
case R.id.action_throttle:
throttleNoisyNoftificationsDialog(conversation);
break;
case R.id.action_block:
case R.id.action_unblock:
final Activity activity = getActivity();
@ -2513,6 +2516,37 @@ public class ConversationFragment extends XmppFragment
builder.create().show();
}
protected void throttleNoisyNoftificationsDialog(final Conversation conversation) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.pref_noisy_notifications_throttling);
final int[] durations = activity.getResources().getIntArray(R.array.notification_throttling_periods_values);
final CharSequence[] labels = new CharSequence[durations.length];
int checkedIndex = -1;
long period = conversation.getNotificationThrottlingPeriod();
for (int i = 0; i < durations.length; ++i) {
if (period == durations[i]) {
checkedIndex = i;
}
if (durations[i] == -1) {
labels[i] = activity.getString(R.string.never);
} else {
labels[i] = TimeFrameUtils.resolve(activity, durations[i]);
}
}
builder.setSingleChoiceItems(
labels,
checkedIndex,
(dialog, which) -> {
conversation.setNotificationThrottlingPeriod(durations[which]);
activity.xmppConnectionService.updateConversation(conversation);
activity.onConversationsListItemUpdated();
refresh();
activity.invalidateOptionsMenu();
});
builder.create().show();
}
private boolean hasPermissions(int requestCode, List<String> permissions) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final List<String> missingPermissions = new ArrayList<>();

View file

@ -11,11 +11,19 @@
android:orderInCategory="20"
android:title="@string/disable_notifications"
app:showAsAction="never" />
<item
android:id="@+id/action_unmute"
android:orderInCategory="21"
android:title="@string/enable_notifications"
app:showAsAction="never" />
<item
android:id="@+id/action_throttle"
android:orderInCategory="25"
android:title="@string/pref_noisy_notifications_throttling"
app:showAsAction="never" />
<item
android:id="@+id/action_ongoing_call"
android:icon="?attr/icon_ongoing_call"

View file

@ -131,14 +131,20 @@
app:showAsAction="never" />
<item
android:id="@+id/action_toggle_pinned"
android:id="@+id/action_throttle"
android:orderInCategory="73"
android:title="@string/pref_noisy_notifications_throttling"
app:showAsAction="never" />
<item
android:id="@+id/action_toggle_pinned"
android:orderInCategory="74"
android:title="@string/add_to_favorites"
app:showAsAction="never" />
<item
android:id="@+id/action_refresh_feature_discovery"
android:orderInCategory="74"
android:orderInCategory="75"
android:title="@string/refresh_feature_discovery"
app:showAsAction="never" />
</menu>

View file

@ -26,8 +26,8 @@
<item>-1</item>
</integer-array>
<string-array name="notification_throttling_periods_values">
<item>0</item>
<integer-array name="notification_throttling_periods_values">
<item>-1</item>
<item>5000</item>
<item>15000</item>
<item>30000</item>
@ -38,20 +38,7 @@
<item>600000</item>
<item>900000</item>
<item>1800000</item>
</string-array>
<string-array name="notification_throttling_periods">
<item>@string/never</item>
<item>5 sec</item>
<item>15 sec</item>
<item>30 sec</item>
<item>1 min</item>
<item>2 min</item>
<item>3 min</item>
<item>5 min</item>
<item>10 min</item>
<item>15 min</item>
<item>30 min</item>
</string-array>
</integer-array>
<string-array name="quick_actions">
<item>@string/none</item>

View file

@ -79,13 +79,6 @@
android:key="grace_period_length"
android:summary="@string/pref_notification_grace_period_summary"
android:title="@string/pref_notification_grace_period" />
<ListPreference
android:defaultValue="@integer/default_notification_throttling_period"
android:entries="@array/notification_throttling_periods"
android:entryValues="@array/notification_throttling_periods_values"
android:key="notification_throttling_period"
android:summary="@string/pref_noisy_notifications_throttling_summary"
android:title="@string/pref_noisy_notifications_throttling" />
<PreferenceScreen
android:key="quiet_hours"
android:summary="@string/pref_quiet_hours_summary"