From 1cc0f838293c9f8fd4438ded6efb61c499fbdeab Mon Sep 17 00:00:00 2001 From: bsitu Date: Tue, 12 Aug 2014 13:37:04 -0700 Subject: [PATCH] Move 'notification count refresh' logic out of mapper Change-Id: I4c10b66e537dea5f9c5bc7ccba8f558cafd103d7 --- includes/mapper/NotificationMapper.php | 3 --- model/Notification.php | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/mapper/NotificationMapper.php b/includes/mapper/NotificationMapper.php index 306fe6001..fe4efaaaf 100644 --- a/includes/mapper/NotificationMapper.php +++ b/includes/mapper/NotificationMapper.php @@ -41,9 +41,6 @@ class EchoNotificationMapper extends EchoAbstractMapper { $dbw->endAtomic( $fname ); if ( $res ) { - // @Todo - move the reset notification count logic to a listener - $user = User::newFromId( $row['notification_user'] ); - MWEchoNotifUser::newFromUser( $user )->resetNotificationCount( DB_MASTER ); foreach ( $listeners as $listener ) { call_user_func( $listener ); } diff --git a/model/Notification.php b/model/Notification.php index 81b3cf2db..d8d754c74 100644 --- a/model/Notification.php +++ b/model/Notification.php @@ -144,6 +144,13 @@ class EchoNotification extends EchoAbstractEntity { } ); } + // Add listener to refresh notification count upon insert + $notifMapper->attachListener( 'insert', 'refresh-notif-count', + function() use ( $user ) { + MWEchoNotifUser::newFromUser( $user )->resetNotificationCount( DB_MASTER ); + } + ); + $notifMapper->insert( $this ); // Clear applicable section status from cache upon new notification creation