mirror of
https://github.com/tuskyapp/Tusky
synced 2025-02-08 00:08:43 +01:00
3820: Group android notifications and properly use the "group summary alert" (#3821)
Fixes #3820 This mainly corrects the "first of batch" logic. (Each group/batch has a list so the question "only one per this group?" can be answered.)
This commit is contained in:
parent
f9ef0d36c2
commit
8efe3a96b7
@ -90,23 +90,29 @@ class NotificationFetcher @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val notificationsByType = notifications.groupBy { it.type }
|
||||||
|
|
||||||
// Make and send the new notifications
|
// Make and send the new notifications
|
||||||
// TODO: Use the batch notification API available in NotificationManagerCompat
|
// TODO: Use the batch notification API available in NotificationManagerCompat
|
||||||
// 1.11 and up (https://developer.android.com/jetpack/androidx/releases/core#1.11.0-alpha01)
|
// 1.11 and up (https://developer.android.com/jetpack/androidx/releases/core#1.11.0-alpha01)
|
||||||
// when it is released.
|
// when it is released.
|
||||||
notifications.forEachIndexed { index, notification ->
|
|
||||||
val androidNotification = NotificationHelper.make(
|
notificationsByType.forEach { notificationsGroup ->
|
||||||
context,
|
notificationsGroup.value.forEach { notification ->
|
||||||
notificationManager,
|
val androidNotification = NotificationHelper.make(
|
||||||
notification,
|
context,
|
||||||
account,
|
notificationManager,
|
||||||
index == 0
|
notification,
|
||||||
)
|
account,
|
||||||
notificationManager.notify(notification.id, account.id.toInt(), androidNotification)
|
notificationsGroup.value.size == 1
|
||||||
// Android will rate limit / drop notifications if they're posted too
|
)
|
||||||
// quickly. There is no indication to the user that this happened.
|
notificationManager.notify(notification.id, account.id.toInt(), androidNotification)
|
||||||
// See https://github.com/tuskyapp/Tusky/pull/3626#discussion_r1192963664
|
|
||||||
delay(1000.milliseconds)
|
// Android will rate limit / drop notifications if they're posted too
|
||||||
|
// quickly. There is no indication to the user that this happened.
|
||||||
|
// See https://github.com/tuskyapp/Tusky/pull/3626#discussion_r1192963664
|
||||||
|
delay(1000.milliseconds)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationHelper.updateSummaryNotifications(
|
NotificationHelper.updateSummaryNotifications(
|
||||||
|
@ -149,7 +149,7 @@ public class NotificationHelper {
|
|||||||
* @return the new notification
|
* @return the new notification
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public static android.app.Notification make(final @NonNull Context context, @NonNull NotificationManager notificationManager, @NonNull Notification body, @NonNull AccountEntity account, boolean isFirstOfBatch) {
|
public static android.app.Notification make(final @NonNull Context context, @NonNull NotificationManager notificationManager, @NonNull Notification body, @NonNull AccountEntity account, boolean isOnlyOneInGroup) {
|
||||||
body = body.rewriteToStatusTypeIfNeeded(account.getAccountId());
|
body = body.rewriteToStatusTypeIfNeeded(account.getAccountId());
|
||||||
String mastodonNotificationId = body.getId();
|
String mastodonNotificationId = body.getId();
|
||||||
int accountId = (int) account.getId();
|
int accountId = (int) account.getId();
|
||||||
@ -241,7 +241,7 @@ public class NotificationHelper {
|
|||||||
builder.addExtras(extras);
|
builder.addExtras(extras);
|
||||||
|
|
||||||
// Only alert for the first notification of a batch to avoid multiple alerts at once
|
// Only alert for the first notification of a batch to avoid multiple alerts at once
|
||||||
if(!isFirstOfBatch) {
|
if(!isOnlyOneInGroup) {
|
||||||
builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
|
builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user