@@ -33,6 +33,8 @@ export class AppComponent implements OnInit, OnDestroy {
3333 private readonly natsUrl : string | undefined ;
3434 private unreadMessagesCountSubscription : Subscription | undefined ;
3535 private liveMessageSubscription : Subscription | undefined ;
36+ private hasShownInitialNotificationToast = false ;
37+ private suppressLiveToastUntil = 0 ;
3638 headerVariant : string = AppShellConfig . headerVariant ;
3739 applicationLogo : string = AppShellConfig . applicationLogo ;
3840 applicationName : string = AppShellConfig . applicationName ;
@@ -334,16 +336,20 @@ export class AppComponent implements OnInit, OnDestroy {
334336 // validBucketRe = regexp.MustCompile(^[a-zA-Z0-9_-]+$)
335337 // validKeyRe = regexp.MustCompile(^[-/_=.a-zA-Z0-9]+$)
336338 const natsUser = user . username . split ( '@' ) [ 0 ] . replaceAll ( / [ ^ a - z A - Z 0 - 9 _ - ] / g, '_' )
339+ this . hasShownInitialNotificationToast = false ;
340+ this . suppressLiveToastUntil = 0 ;
337341 this . natsService . initializeUser ( natsUser , user . projects ) . then ( ( ) => {
338342 setTimeout ( ( ) => {
339- if ( this . appShellNotificationsCount > 0 ) {
343+ if ( this . appShellNotificationsCount > 0 && ! this . hasShownInitialNotificationToast ) {
340344 const notification = {
341345 id : Date . now ( ) . toString ( ) + '-logged' ,
342346 title : `You have ${ this . appShellNotificationsCount } unread notifications` ,
343347 read : false ,
344348 subject : 'only-toast'
345349 } as AppShellNotification ;
346350 this . toastService . showToast ( notification , 8000 ) ;
351+ this . hasShownInitialNotificationToast = true ;
352+ this . suppressLiveToastUntil = Date . now ( ) + 5000 ;
347353 }
348354 } , 1000 ) ;
349355 } ) ;
@@ -358,6 +364,9 @@ export class AppComponent implements OnInit, OnDestroy {
358364 if ( ! message ?. data ) {
359365 return ;
360366 }
367+ if ( Date . now ( ) < this . suppressLiveToastUntil ) {
368+ return ;
369+ }
361370 try {
362371 if ( this . natsService . isValidMessage ( message . data ) ) {
363372 console . log ( 'Received valid message:' , message ) ;
@@ -371,6 +380,7 @@ export class AppComponent implements OnInit, OnDestroy {
371380 } ;
372381 // If you want to show the actual notification, you can show message.data instead of notification
373382 this . toastService . showToast ( notification , 8000 ) ;
383+ this . hasShownInitialNotificationToast = true ;
374384 } else {
375385 console . log ( 'Invalid message format:' , message ) ;
376386 }
0 commit comments