Merge "Use new TalkPageNotificationManager"
This commit is contained in:
commit
fedbf6ba82
6 changed files with 33 additions and 17 deletions
|
|
@ -1550,11 +1550,13 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
|
|||
// TODO: replace legacy hook! Use a listener on PageEventEmitter instead!
|
||||
if ( Hooks::run( 'ArticleEditUpdateNewTalk', [ &$wikiPage, $recipient ] ) ) {
|
||||
$revRecord = $legacyRevision->getRevisionRecord();
|
||||
$talkPageNotificationManager = MediaWikiServices::getInstance()
|
||||
->getTalkPageNotificationManager();
|
||||
if ( User::isIP( $shortTitle ) ) {
|
||||
// An anonymous user
|
||||
$recipient->setNewtalk( true, $revRecord );
|
||||
$talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord );
|
||||
} elseif ( $recipient->isLoggedIn() ) {
|
||||
$recipient->setNewtalk( true, $revRecord );
|
||||
$talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord );
|
||||
} else {
|
||||
wfDebug( __METHOD__ . ": don't need to notify a nonexistent user\n" );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,8 @@ class ApiQueryUserInfo extends ApiQueryBase {
|
|||
}
|
||||
|
||||
if ( isset( $this->prop['hasmsg'] ) ) {
|
||||
$vals['messages'] = $user->getNewtalk();
|
||||
$vals['messages'] = MediaWikiServices::getInstance()
|
||||
->getTalkPageNotificationManager()->userHasNewMessages( $user );
|
||||
}
|
||||
|
||||
if ( isset( $this->prop['groups'] ) ) {
|
||||
|
|
|
|||
4
includes/cache/HTMLFileCache.php
vendored
4
includes/cache/HTMLFileCache.php
vendored
|
|
@ -124,7 +124,9 @@ class HTMLFileCache extends FileCacheBase {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( ( $mode === self::MODE_NORMAL ) && $user->getNewtalk() ) {
|
||||
$userHasNewMessages = MediaWikiServices::getInstance()
|
||||
->getTalkPageNotificationManager()->userHasNewMessages( $user );
|
||||
if ( ( $mode === self::MODE_NORMAL ) && $userHasNewMessages ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3547,7 +3547,9 @@ class WikiPage implements Page, IDBAccessObject {
|
|||
if ( $title->getNamespace() == NS_USER_TALK ) {
|
||||
$user = User::newFromName( $title->getText(), false );
|
||||
if ( $user ) {
|
||||
$user->setNewtalk( false );
|
||||
MediaWikiServices::getInstance()
|
||||
->getTalkPageNotificationManager()
|
||||
->removeUserHasNewMessages( $user );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2265,17 +2265,18 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
return $talks;
|
||||
}
|
||||
|
||||
if ( !$this->getNewtalk() ) {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$userHasNewMessages = $services->getTalkPageNotificationManager()
|
||||
->userHasNewMessages( $this );
|
||||
if ( !$userHasNewMessages ) {
|
||||
return [];
|
||||
}
|
||||
$utp = $this->getTalkPage();
|
||||
$timestamp = MediaWikiServices::getInstance()
|
||||
->getTalkPageNotificationManager()
|
||||
$timestamp = $services->getTalkPageNotificationManager()
|
||||
->getLatestSeenMessageTimestamp( $this );
|
||||
$rev = null;
|
||||
if ( $timestamp ) {
|
||||
$revRecord = MediaWikiServices::getInstance()
|
||||
->getRevisionLookup()
|
||||
$revRecord = $services->getRevisionLookup()
|
||||
->getRevisionByTimestamp( $utp, $timestamp );
|
||||
if ( $revRecord ) {
|
||||
$rev = new Revision( $revRecord );
|
||||
|
|
@ -3469,12 +3470,14 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
|
||||
// Try to update the DB post-send and only if needed...
|
||||
DeferredUpdates::addCallableUpdate( function () use ( $oldid ) {
|
||||
if ( !$this->getNewtalk() ) {
|
||||
$talkPageNotificationManager = MediaWikiServices::getInstance()
|
||||
->getTalkPageNotificationManager();
|
||||
if ( !$talkPageNotificationManager->userHasNewMessages( $this ) ) {
|
||||
return; // no notifications to clear
|
||||
}
|
||||
|
||||
// Delete the last notifications (they stack up)
|
||||
$this->setNewtalk( false );
|
||||
$talkPageNotificationManager->removeUserHasNewMessages( $this );
|
||||
|
||||
// If there is a new, unseen, revision, use its timestamp
|
||||
if ( $oldid ) {
|
||||
|
|
@ -3483,7 +3486,7 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
if ( $oldRev ) {
|
||||
$newRev = $rl->getNextRevision( $oldRev );
|
||||
if ( $newRev ) {
|
||||
$this->setNewtalk( true, $newRev );
|
||||
$talkPageNotificationManager->setUserHasNewMessages( $this, $newRev );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3526,7 +3529,9 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
}
|
||||
|
||||
if ( !$wgUseEnotif && !$wgShowUpdatedMarker ) {
|
||||
$this->setNewtalk( false );
|
||||
MediaWikiServices::getInstance()
|
||||
->getTalkPageNotificationManager()
|
||||
->removeUserHasNewMessages( $this );
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* @group API
|
||||
* @group medium
|
||||
|
|
@ -12,13 +14,15 @@ class ApiClearHasMsgTest extends ApiTestCase {
|
|||
*/
|
||||
public function testClearFlag() {
|
||||
$user = self::$users['sysop']->getUser();
|
||||
$user->setNewtalk( true );
|
||||
$this->assertTrue( $user->getNewtalk(), 'sanity check' );
|
||||
$talkPageNotificationManager = MediaWikiServices::getInstance()
|
||||
->getTalkPageNotificationManager();
|
||||
$talkPageNotificationManager->setUserHasNewMessages( $user );
|
||||
$this->assertTrue( $talkPageNotificationManager->userHasNewMessages( $user ), 'sanity check' );
|
||||
|
||||
$data = $this->doApiRequest( [ 'action' => 'clearhasmsg' ], [] );
|
||||
|
||||
$this->assertEquals( 'success', $data[0]['clearhasmsg'] );
|
||||
$this->assertFalse( $user->getNewtalk() );
|
||||
$this->assertFalse( $talkPageNotificationManager->userHasNewMessages( $user ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue