Always show the messages flyout icon

Bug: T127731
Bug: T124372
Change-Id: Ie97229b7ef34cd807f16c76ceae0682c425c53b4
This commit is contained in:
Kunal Mehta 2016-02-23 01:20:24 -08:00
parent 6b36375ded
commit 7fbec72803
3 changed files with 7 additions and 130 deletions

View file

@ -778,9 +778,6 @@ class EchoHooks {
'notifications-alert' => $alertLink,
);
// hasMessages() checks if the user has ever had (local) messages, or if they
// have any currently unread message at all (including on foreign wikis)
if ( $notifUser->hasMessages() ) {
$msgLink = array(
'href' => $url,
'text' => $msgText,
@ -789,7 +786,6 @@ class EchoHooks {
);
$insertUrls['notifications-message'] = $msgLink;
}
$personal_urls = wfArrayInsertAfter( $personal_urls, $insertUrls, 'userpage' );

View file

@ -176,122 +176,6 @@ class MWEchoNotifUser {
return $count;
}
/**
* Get the memcache key for 'has ever had messages' value
* @return string
*/
private function getHasMessagesKey() {
global $wgEchoConfig;
$lookup = CentralIdLookup::factory();
$id = $lookup->centralIdFromLocalUser( $this->mUser, CentralIdLookup::AUDIENCE_RAW );
if ( !$id ) {
// local user
return wfMemcKey( 'echo', 'user', 'had', 'messages', $this->mUser->getId(), $wgEchoConfig['version'] );
} else {
// central user: we don't want a per-wiki cache key: as soon as the user
// gets a message on another wiki, this cache key should be altered
return wfGlobalCacheKey( 'echo', 'user', 'had', 'messages', $id, $wgEchoConfig['version'] );
}
}
/**
* Check whether the user has ever had messages.
*
* @return boolean User has received messages
*/
public function hasMessages() {
$section = EchoAttributeManager::MESSAGE;
/*
* This is a temp "hack" for as long as cross-wiki is in beta. The "real
* data" stored to cache should be global, so a change in a wiki where
* cross-wiki is disabled is still visible in wikis where it is enabled.
* So if cross-wiki is disabled, we can't trust/use the result that is
* in getHasMessagesKey.
*/
if ( !$this->mUser->getOption( 'echo-cross-wiki-notifications' ) ) {
global $wgEchoConfig;
// key is the same as getHasMessagesKey's single-user case, which is
// ok (if there's no centralized user, there'll only be local data
// anyway - same as when cross-wiki is disabled)
$memcKey = wfMemcKey( 'echo', 'user', 'had', 'messages', $this->mUser->getId(), $wgEchoConfig['version'] );
$data = $this->cache->get( $memcKey );
if ( $data !== false && $data !== null ) {
return $data;
}
$result = $this->hasLocal( $section );
$this->cache->set( $memcKey, $result, 86400 );
return $result;
}
$memcKey = $this->getHasMessagesKey();
$data = $this->cache->get( $memcKey );
if ( $data !== false && $data !== null ) {
return (bool) $data;
}
$result = $this->hasGlobal( $section );
$this->cache->set( $memcKey, $result, 86400 );
return $result;
}
/**
* Check if user has ever had alerts/messages on this local wiki.
*
* @param string $section
* @return bool
*/
protected function hasLocal( $section ) {
$attributeManager = EchoAttributeManager::newFromGlobalVars();
$eventTypesToLoad = $attributeManager->getUserEnabledEventsbySections( $this->mUser, 'web', array( $section ) );
$count = count( $this->notifMapper->fetchByUser( $this->mUser, 1, 0, $eventTypesToLoad ) );
return $count > 0;
}
/**
* Check if user has ever had alerts/messages on any wiki (local & foreign).
*
* @param string $section
* @return bool
*/
protected function hasGlobal( $section ) {
$uw = EchoUnreadWikis::newFromUser( $this->mUser );
if ( $uw === false ) {
// there is no centralized user, fall back to checking local wiki
return $this->hasLocal( $section );
}
$counts = $uw->getUnreadCounts();
foreach ( $counts as $wiki => $data ) {
if ( $data[$section]['count'] > 0 ) {
// currently has unread notifications
return true;
}
if ( $data[$section]['ts'] !== EchoUnreadWikis::DEFAULT_TS ) {
// a timestamp at which notifications were read was recorded,
// which means the user must've had messages somewhere, at some point
return true;
}
}
return false;
}
/**
* Cache the fact that the user has messages.
* This is used after the user receives a message, making the system skip the actual test
* of whether they have messages against the database at all.
*/
public function cacheHasMessages() {
$this->cache->set( $this->getHasMessagesKey(), 1, 86400 );
}
/**
* Retrieves number of unread notifications that a user has, would return
* $wgEchoMaxNotificationCount + 1 at most

View file

@ -159,9 +159,6 @@ class EchoNotification extends EchoAbstractEntity {
$notifMapper->attachListener( 'insert', 'refresh-notif-count',
function () use ( $notifUser, $section ) {
$notifUser->resetNotificationCount( DB_MASTER );
if ( $section === EchoAttributeManager::MESSAGE && !$notifUser->hasMessages() ) {
$notifUser->cacheHasMessages();
}
}
);