Use new TalkPageNotificationManager

Bug: T239640
Change-Id: Iba015bf246250fc144022d92b88eb00882dd1d3a
This commit is contained in:
Clara Andrew-Wani 2020-05-15 12:58:14 -04:00
parent f54bfb63d3
commit 6dd0f21968
3 changed files with 16 additions and 6 deletions

View file

@ -1168,7 +1168,9 @@ class EchoHooks {
// * User actually has new messages
// * User is not viewing their user talk page, as user_newtalk
// will not have been cleared yet. (bug T107655).
if ( $user->getNewtalk() && !$user->getTalkPage()->equals( $title ) ) {
$userHasNewMessages = MediaWikiServices::getInstance()
->getTalkPageNotificationManager()->userHasNewMessages( $user );
if ( $userHasNewMessages && !$user->getTalkPage()->equals( $title ) ) {
if ( Hooks::run( 'BeforeDisplayOrangeAlert', [ $user, $title ] ) ) {
$personal_urls['mytalk']['text'] = $sk->msg( 'echo-new-messages' )->text();
$personal_urls['mytalk']['class'] = [ 'mw-echo-alert' ];

View file

@ -254,13 +254,15 @@ class MWEchoNotifUser {
// After this 'mark read', is there any unread edit-user-talk
// remaining? If not, we should clear the newtalk flag.
if ( $this->mUser->getNewtalk() ) {
$talkPageNotificationManager = MediaWikiServices::getInstance()
->getTalkPageNotificationManager();
if ( $talkPageNotificationManager->userHasNewMessages( $this->mUser ) ) {
$attributeManager = EchoAttributeManager::newFromGlobalVars();
$categoryMap = $attributeManager->getEventsByCategory();
$usertalkTypes = $categoryMap['edit-user-talk'];
$unreadEditUserTalk = $this->notifMapper->fetchUnreadByUser( $this->mUser, 1, null, $usertalkTypes, null, DB_MASTER );
if ( $unreadEditUserTalk === [] ) {
$this->mUser->setNewtalk( false );
$talkPageNotificationManager->removeUserHasNewMessages( $this->mUser );
}
}
}
@ -287,13 +289,15 @@ class MWEchoNotifUser {
// After this 'mark unread', is there any unread edit-user-talk?
// If so, we should add the edit-user-talk flag
if ( !$this->mUser->getNewtalk() ) {
$talkPageNotificationManager = MediaWikiServices::getInstance()
->getTalkPageNotificationManager();
if ( !$talkPageNotificationManager->userHasNewMessages( $this->mUser ) ) {
$attributeManager = EchoAttributeManager::newFromGlobalVars();
$categoryMap = $attributeManager->getEventsByCategory();
$usertalkTypes = $categoryMap['edit-user-talk'];
$unreadEditUserTalk = $this->notifMapper->fetchUnreadByUser( $this->mUser, 1, null, $usertalkTypes, null, DB_MASTER );
if ( $unreadEditUserTalk !== [] ) {
$this->mUser->setNewtalk( true );
$talkPageNotificationManager->setUserHasNewMessages( $this->mUser );
}
}
}

View file

@ -1,5 +1,7 @@
<?php
use MediaWiki\MediaWikiServices;
class EchoNotification extends EchoAbstractEntity implements Bundleable {
/**
@ -120,7 +122,9 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
$notifMapper->insert( $this );
if ( $this->event->getCategory() === 'edit-user-talk' ) {
$this->user->setNewtalk( true );
MediaWikiServices::getInstance()
->getTalkPageNotificationManager()
->setUserHasNewMessages( $this->user );
}
Hooks::run( 'EchoCreateNotificationComplete', [ $this ] );
}