@@ -165,6 +165,7 @@ public void restoreState (TdApi.UpdateActiveNotifications update) {
165165 rebuild ();
166166 }
167167 }
168+ retainIcons ();
168169 }
169170
170171 private boolean haveRebuilt ;
@@ -478,6 +479,7 @@ public void onHideAll (int category) {
478479 if (group .matchesCategory (category ))
479480 group .markAsHidden (TdlibNotificationGroup .HIDE_REASON_GLOBAL );
480481 }
482+ retainIcons ();
481483 }
482484
483485 public void onHide (TdlibNotificationExtras extras ) {
@@ -487,6 +489,7 @@ public void onHide (TdlibNotificationExtras extras) {
487489 } else {
488490 tdlib .settings ().setNotificationGroupData (extras .notificationGroupId , extras .maxNotificationId , 0 );
489491 }
492+ retainIcons ();
490493 }
491494
492495 public void onDropNotificationData (boolean hideAll ) {
@@ -508,6 +511,7 @@ public void onDropNotificationData (boolean hideAll) {
508511 if (!hideAll && update ) {
509512 rebuild ();
510513 }
514+ retainIcons ();
511515 }
512516
513517 public long findSingleChatId () {
@@ -558,6 +562,7 @@ private void displayNotificationGroup (@NonNull TdlibNotificationGroup group, bo
558562 TdlibNotificationSettings settings = needNotification && !group .isHidden () ? new TdlibNotificationSettings (tdlib , notificationSettingsChatId , group ) : null ;
559563 style .displayNotificationGroup (context , this , badgeCount , allowPreview , group , settings );
560564 tdlib .context ().setHavePendingNotifications (tdlib .id (), true );
565+ retainIcons ();
561566 }
562567
563568 private void hideNotificationGroup (@ NonNull TdlibNotificationGroup group ) {
@@ -566,6 +571,7 @@ private void hideNotificationGroup (@NonNull TdlibNotificationGroup group) {
566571 boolean allowPreview = allowNotificationPreview ();
567572 style .hideNotificationGroup (context , this , badgeCount , allowPreview , group );
568573 tdlib .context ().setHavePendingNotifications (tdlib .id (), !isEmpty ());
574+ retainIcons ();
569575 }
570576
571577 private void rebuild (@ Nullable TdApi .NotificationSettingsScope scope , long specificChatId , int specificGroupId ) {
@@ -577,6 +583,7 @@ private void rebuild (@Nullable TdApi.NotificationSettingsScope scope, long spec
577583 style .rebuildNotificationsSilently (context , this , badgeCount , allowPreview , scope , specificChatId , specificGroupId );
578584 }
579585 tdlib .context ().setHavePendingNotifications (tdlib .id (), haveNotifications );
586+ retainIcons ();
580587 }
581588
582589 public void rebuild () {
@@ -595,6 +602,28 @@ public void rebuildGroup (int groupId) {
595602 rebuild (null , 0 , groupId );
596603 }
597604
605+ private void retainIcons () {
606+ // Muted groups keep their icons while mentions or pinned messages can still come there
607+ if (!Config .REUSE_NOTIFICATION_ICONS ) {
608+ return ;
609+ }
610+ final Set <Long > chatIds = new HashSet <>();
611+ for (TdlibNotificationGroup group : this ) {
612+ final long chatId = group .getChatId ();
613+ if (canNotify (chatId )) {
614+ chatIds .add (chatId );
615+ }
616+ }
617+ tdlib .context ().notificationIcons ().retainChats (tdlib .id (), chatIds );
618+ }
619+
620+ private boolean canNotify (long chatId ) {
621+ final TdlibNotificationManager notifications = tdlib .notifications ();
622+ return tdlib .chatNotificationsEnabled (chatId ) || (tdlib .isMultiChat (chatId ) && !(
623+ notifications .areMentionsDisabled (chatId ) && notifications .arePinnedMessagesDisabled (chatId )
624+ ));
625+ }
626+
598627 public void onChatOpened (long chatId ) {
599628 if (ChatId .isSecret (chatId )) {
600629 for (TdlibNotificationGroup group : groups .values ()) {
0 commit comments