]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
More Favorite pluginification (favecount, cache, menus(favecount, cache, menus))
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 28 Jun 2014 11:11:03 +0000 (13:11 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 28 Jun 2014 12:03:30 +0000 (14:03 +0200)
29 files changed:
EVENTS.txt
actions/block.php
classes/Profile.php
classes/User.php
lib/apiaction.php
lib/personalgroupnav.php
lib/profileformaction.php
lib/publicgroupnav.php
lib/threadednoticelist.php
plugins/ActivitySpam/actions/train.php
plugins/AnonymousFave/actions/anondisfavor.php
plugins/AnonymousFave/actions/anonfavor.php
plugins/Bookmark/BookmarkPlugin.php
plugins/Favorite/FavoritePlugin.php
plugins/Favorite/actions/apifavoritecreate.php
plugins/Favorite/actions/apifavoritedestroy.php
plugins/Favorite/actions/apitimelinefavorites.php
plugins/Favorite/actions/atompubfavoritefeed.php
plugins/Favorite/actions/disfavor.php
plugins/Favorite/actions/favor.php
plugins/Favorite/actions/favoritesrss.php
plugins/Favorite/actions/showfavorites.php
plugins/Favorite/classes/Fave.php
plugins/Favorite/lib/favcommand.php
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/GNUsocialProfileExtensions/GNUsocialProfileExtensionsPlugin.php
plugins/TwitterBridge/TwitterBridgePlugin.php
plugins/YammerImport/lib/yammerimporter.php
tests/ActivityGenerationTests.php

index a9057e7f6a752f1cda64a8d97dc56d287f1d2871..d8763b05cc9b4dd154506bfbc0a16eb2af158a19 100644 (file)
@@ -216,7 +216,9 @@ EndShowBody: called after showing the <body> element (and </body>)
 - $action: action object being shown
 
 StartPersonalGroupNav: beginning of personal group nav menu
-- $action: action object being shown
+- $menu: Menu list object being shown
+- $target: Profile for whom it is shown
+- $scoped: Profile of currently logged in user (or null)
 
 EndPersonalGroupNav: end of personal group nav menu (good place to add a menu item)
 - $action: action object being shown
index 7458caa6ac73200ea50e2be58c3fd97c2f9ac839..53d8ae7ae0600c17a800cfc5e927a7efd40facfd 100644 (file)
@@ -74,8 +74,6 @@ class BlockAction extends ProfileFormAction
     /**
      * Handle request
      *
-     * Shows a page with list of favorite notices
-     *
      * @param array $args $_REQUEST args; handled in prepare()
      *
      * @return void
index 862e8ff11a4f34acecb8c982f116672b9a4b90d3..7e8e37d2edce81db264b1d147378d29b55d7030e 100644 (file)
@@ -760,39 +760,6 @@ class Profile extends Managed_DataObject
           $other->isSubscribed($this);
     }
 
-    function hasFave($notice)
-    {
-        $fave = Fave::pkeyGet(array('user_id' => $this->id,
-                                    'notice_id' => $notice->id));
-        return ((is_null($fave)) ? false : true);
-    }
-
-    function faveCount()
-    {
-        $c = Cache::instance();
-        if (!empty($c)) {
-            $cnt = $c->get(Cache::key('profile:fave_count:'.$this->id));
-            if (is_integer($cnt)) {
-                return (int) $cnt;
-            }
-        }
-
-        $faves = new Fave();
-        $faves->user_id = $this->id;
-        $cnt = (int) $faves->count('notice_id');
-
-        if (!empty($c)) {
-            $c->set(Cache::key('profile:fave_count:'.$this->id), $cnt);
-        }
-
-        return $cnt;
-    }
-
-    function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
-    {
-        return Fave::stream($this->id, $offset, $limit, $own, $since_id, $max_id);
-    }
-
     function noticeCount()
     {
         $c = Cache::instance();
@@ -815,20 +782,6 @@ class Profile extends Managed_DataObject
         return $cnt;
     }
 
-    function blowFavesCache()
-    {
-        $cache = Cache::instance();
-        if ($cache) {
-            // Faves don't happen chronologically, so we need to blow
-            // ;last cache, too
-            $cache->delete(Cache::key('fave:ids_by_user:'.$this->id));
-            $cache->delete(Cache::key('fave:ids_by_user:'.$this->id.';last'));
-            $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id));
-            $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id.';last'));
-        }
-        $this->blowFaveCount();
-    }
-
     function blowSubscriberCount()
     {
         $c = Cache::instance();
@@ -845,14 +798,6 @@ class Profile extends Managed_DataObject
         }
     }
 
-    function blowFaveCount()
-    {
-        $c = Cache::instance();
-        if (!empty($c)) {
-            $c->delete(Cache::key('profile:fave_count:'.$this->id));
-        }
-    }
-
     function blowNoticeCount()
     {
         $c = Cache::instance();
index 9b3ebed057156389062781bd4865547471d9cec1..c3ceb2646b166ca57a912c1d44aec2c31073a35a 100644 (file)
@@ -440,11 +440,6 @@ class User extends Managed_DataObject
         }
     }
 
-    function hasFave($notice)
-    {
-        return $this->getProfile()->hasFave($notice);
-    }
-
     function mutuallySubscribed(Profile $other)
     {
         return $this->getProfile()->mutuallySubscribed($other);
@@ -479,16 +474,6 @@ class User extends Managed_DataObject
         return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
     }
 
-    function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
-    {
-        return $this->getProfile()->favoriteNotices($own, $offset, $limit, $since_id, $max_id);
-    }
-
-    function blowFavesCache()
-    {
-        $this->getProfile()->blowFavesCache();
-    }
-
     function getSelfTags()
     {
         return Profile_tag::getTagsArray($this->id, $this->id, $this->id);
@@ -641,7 +626,7 @@ class User extends Managed_DataObject
             common_log(LOG_INFO, "User {$this->nickname} has no profile; continuing deletion.");
         }
 
-        $related = array('Fave',
+        $related = array(
                          'Confirm_address',
                          'Remember_me',
                          'Foreign_link',
index 6de9c0b63270c9c08f405be939511b3ab10f252a..d945d532d013969e139b73a40ff7bdf0d7700ff5 100644 (file)
@@ -243,8 +243,6 @@ class ApiAction extends Action
 
         $twitter_user['created_at'] = $this->dateTwitter($profile->created);
 
-        $twitter_user['favourites_count'] = $profile->faveCount(); // British spelling!
-
         $timezone = 'UTC';
 
         if (!empty($user) && $user->timezone) {
@@ -290,6 +288,9 @@ class ApiAction extends Action
 
         $twitter_user['statusnet_profile_url'] = $profile->profileurl;
 
+        // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array
+        Event::handle('TwitterUserArray', array($profile, &$twitter_user, $this->scoped, array()));
+
         return $twitter_user;
     }
 
index d379dcf5281d94885c08d287c5de3969a6067a62..8c413c6ab951e9c2943aa1796f17f687707c79ee 100644 (file)
@@ -50,24 +50,27 @@ class PersonalGroupNav extends Menu
      *
      * @return void
      */
-    function show()
+    public function show()
     {
-        $user         = common_current_user();
+        // FIXME: Legacy StatusNet behaviour was to do this, but really it should be the GroupNav
+        // of the targeted user! ($this->action->arg('nickname')
+        $target = Profile::current();
 
-        if (empty($user)) {
+        if (!$target instanceof Profile) {
             throw new ServerException('Cannot show personal group navigation without a current user.');
         }
 
-        $user_profile = $user->getProfile();
-        $nickname     = $user->nickname;
-        $name         = $user_profile->getBestName();
+        $nickname  = $target->getNickname();
+        $name      = $target->getBestName();
+
+        $scoped = Profile::current();
 
         $action = $this->actionName;
         $mine = ($this->action->arg('nickname') == $nickname); // @fixme kinda vague
 
         $this->out->elementStart('ul', array('class' => 'nav'));
 
-        if (Event::handle('StartPersonalGroupNav', array($this))) {
+        if (Event::handle('StartPersonalGroupNav', array($this, $target, $scoped))) {
             $this->out->menuItem(common_local_url('all', array('nickname' =>
                                                                $nickname)),
                                  // TRANS: Menu item in personal group navigation menu.
@@ -92,21 +95,9 @@ class PersonalGroupNav extends Menu
                                  // TRANS: %s is a username.
                                  sprintf(_('Replies to %s'), $name),
                                  $mine && $action =='replies', 'nav_timeline_replies');
-            $this->out->menuItem(common_local_url('showfavorites', array('nickname' =>
-                                                                         $nickname)),
-                                 // TRANS: Menu item in personal group navigation menu.
-                                 _m('MENU','Favorites'),
-                                 // @todo i18n FIXME: Need to make this two messages.
-                                 // TRANS: Menu item title in personal group navigation menu.
-                                 // TRANS: %s is a username.
-                                 sprintf(_('%s\'s favorite notices'),
-                                         // TRANS: Replaces %s in '%s\'s favorite notices'. (Yes, we know we need to fix this.)
-                                         ($user_profile) ? $name : _m('FIXME','User')),
-                                 $mine && $action =='showfavorites', 'nav_timeline_favorites');
 
-            $cur = common_current_user();
 
-            if ($cur && $cur->id == $user->id &&
+            if ($scoped instanceof Profile && $scoped->id == $target->id &&
                 !common_config('singleuser', 'enabled')) {
 
                 $this->out->menuItem(common_local_url('inbox', array('nickname' =>
@@ -118,7 +109,7 @@ class PersonalGroupNav extends Menu
                                      $mine && $action =='inbox');
             }
 
-            Event::handle('EndPersonalGroupNav', array($this));
+            Event::handle('EndPersonalGroupNav', array($this, $target, $scoped));
         }
         $this->out->elementEnd('ul');
     }
index bfc7a3c7dedf12d11388e346623afab435cd3df2..9ace6676c3b82fa16797c735f4b0630518dd429d 100644 (file)
@@ -92,8 +92,6 @@ class ProfileFormAction extends RedirectingAction
     /**
      * Handle request
      *
-     * Shows a page with list of favorite notices
-     *
      * @param array $args $_REQUEST args; handled in prepare()
      *
      * @return void
index 79190a11f05edb4c379e3419b1dc3dbffeb7b43d..e7c61000f382b1e513e8096c517736db60a68b1f 100644 (file)
@@ -88,13 +88,6 @@ class PublicGroupNav extends Menu
                     _('Featured users'), $this->actionName == 'featured', 'nav_featured');
             }
 
-            if (!common_config('singleuser', 'enabled')) {
-                // TRANS: Menu item in search group navigation panel.
-                $this->out->menuItem(common_local_url('favorited'), _m('MENU','Popular'),
-                                     // TRANS: Menu item title in search group navigation panel.
-                                     _('Popular notices'), $this->actionName == 'favorited', 'nav_timeline_favorited');
-            }
-
             Event::handle('EndPublicGroupNav', array($this));
         }
         $this->action->elementEnd('ul');
index 62099e91555ba8897f116972b79313379f253e4e..bf5329e33b74a60390f1e0095fd5ef291dc061de 100644 (file)
@@ -467,9 +467,9 @@ class ThreadedNoticeListRepeatsItem extends NoticeListActorsItem
                               $count - 3),
                            $count - 3);
         } else {
-            // TRANS: List message for favoured notices.
-            // TRANS: %%s is a list of users liking a notice.
-            // TRANS: Plural is based on the number of of users that have favoured a notice.
+            // TRANS: List message for repeated notices.
+            // TRANS: %%s is a list of users who have repeated a notice.
+            // TRANS: Plural is based on the number of of users that have repeated a notice.
             return sprintf(_m('%%s repeated this.',
                               '%%s repeated this.',
                               $count),
index c56f49fb51868297545d2820350a26e0d6adf089..0719c36550488e4f35bd371dfd14b339e5505aac 100644 (file)
@@ -141,8 +141,8 @@ class TrainAction extends Action
         if ($this->boolean('ajax')) {
             $this->startHTML('text/xml;charset=utf-8');
             $this->elementStart('head');
-            // TRANS: Page title for page on which favorite notices can be unfavourited.
-            $this->element('title', null, _('Disfavor favorite.'));
+            // TRANS: Page title for page on which we train the spam filter for ham or spam
+            $this->element('title', null, _('Train spam filter'));
             $this->elementEnd('head');
             $this->elementStart('body');
             $form->show();
index 15f1040b7c4a30fd94977335970eab91e540a620..6b0fae82c1584a58a621ab2cc831afa414f6f1db 100644 (file)
@@ -80,7 +80,7 @@ class AnonDisfavorAction extends RedirectingAction
             $this->serverError(_m('Could not delete favorite.'));
         }
 
-        $profile->blowFavesCache();
+        Fave::blowCacheForProfileId($profile->id);
 
         if ($this->boolean('ajax')) {
             $this->startHTML('text/xml;charset=utf-8');
index 6af874679fb4d7cb14376800a15f6b203c49b3be..c9282f15f68df3769399b865c216f83bdd097461 100644 (file)
@@ -68,12 +68,12 @@ class AnonFavorAction extends RedirectingAction
         }
         $fave = Fave::addNew($profile, $notice);
 
-        if (!$fave) {
+        if (!$fave instanceof Fave) {
             // TRANS: Server error.
             $this->serverError(_m('Could not create favorite.'));
         }
 
-        $profile->blowFavesCache();
+        Fave::blowCacheForProfileId($profile->id);
 
         if ($this->boolean('ajax')) {
             $this->startHTML('text/xml;charset=utf-8');
index 170fa578f99b2d25faa7e0109aed790a073570a4..fec1238e18a240cd7cae8c04f9ad2200a601d27c 100644 (file)
@@ -287,16 +287,9 @@ class BookmarkPlugin extends MicroAppPlugin
      *
      * @see Action
      */
-    function onEndPersonalGroupNav($action)
+    function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
     {
-        $this->user = common_current_user();
-
-        if (!$this->user) {
-            // TRANS: Client error displayed when trying to display bookmarks for a non-existing user.
-            $this->clientError(_('No such user.'));
-        }
-
-        $action->menuItem(common_local_url('bookmarks', array('nickname' => $this->user->nickname)),
+        $menu->menuItem(common_local_url('bookmarks', array('nickname' => $target->getNickname())),
                           // TRANS: Menu item in sample plugin.
                           _m('Bookmarks'),
                           // TRANS: Menu item title in sample plugin.
index 64b52ff75da5bee08f3e297a3ea79849b7b76dda..117f6cb46dc3f1ccca84b85b0eed77033cc5e66d 100644 (file)
@@ -162,6 +162,11 @@ class FavoritePlugin extends ActivityHandlerPlugin
         return true;
     }
 
+    public function onTwitterUserArray(Profile $profile, array &$userdata, Profile $scoped=null, array $args=array())
+    {
+        $userdata['favourites_count'] = Fave::countByProfile($profile);
+    }
+
     /**
      * Typically just used to fill out StatusNet specific data in API calls in the referenced $info array.
      */
@@ -180,10 +185,7 @@ class FavoritePlugin extends ActivityHandlerPlugin
 
         if ($fave->find()) {
             while ($fave->fetch()) {
-                Memcached_DataObject::blow('fave:ids_by_user_own:%d', $fave->user_id);
-                Memcached_DataObject::blow('fave:ids_by_user_own:%d;last', $fave->user_id);
-                Memcached_DataObject::blow('fave:ids_by_user:%d', $fave->user_id);
-                Memcached_DataObject::blow('fave:ids_by_user:%d;last', $fave->user_id);
+                Fave::blowCacheForProfileId($fave->user_id);
                 $fave->delete();
             }
         }
@@ -191,6 +193,16 @@ class FavoritePlugin extends ActivityHandlerPlugin
         $fave->free();
     }
 
+    public function onUserDeleteRelated(User $user, array &$related)
+    {
+        $fave = new Fave();
+        $fave->user_id = $user->id;
+        $fave->delete();    // Will perform a DELETE matching "user_id = {$user->id}"
+
+        Fave::blowCacheForProfileId($user->id);
+        return true;
+    }
+
     public function onStartNoticeListPrefill(array &$notices, array $notice_ids, Profile $scoped=null)
     {
         // prefill array of objects, before pluginfication it was Notice::fillFaves($notices)
@@ -301,6 +313,31 @@ class FavoritePlugin extends ActivityHandlerPlugin
         $supported = $supported || $cmd instanceof FavCommand;
     }
 
+    // Layout stuff
+
+    public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
+    {
+        $menu->out->menuItem(common_local_url('showfavorites', array('nickname' => $target->getNickname())),
+                             // TRANS: Menu item in personal group navigation menu.
+                             _m('MENU','Favorites'),
+                             // @todo i18n FIXME: Need to make this two messages.
+                             // TRANS: Menu item title in personal group navigation menu.
+                             // TRANS: %s is a username.
+                             sprintf(_('%s\'s favorite notices'), $target->getBestName()),
+                             $scoped instanceof Profile && $target->id === $scoped->id && $menu->actionName =='showfavorites',
+                            'nav_timeline_favorites');
+    }
+
+    public function onEndPublicGroupNav(Menu $menu)
+    {
+        if (!common_config('singleuser', 'enabled')) {
+            // TRANS: Menu item in search group navigation panel.
+            $menu->out->menuItem(common_local_url('favorited'), _m('MENU','Popular'),
+                                 // TRANS: Menu item title in search group navigation panel.
+                                 _('Popular notices'), $menu->actionName == 'favorited', 'nav_timeline_favorited');
+        }
+    }
+
     public function onPluginVersion(array &$versions)
     {
         $versions[] = array('name' => 'Favorite',
index dd4fbd27957468d391d23a4901c6218d18fb069c..00c1e21bbf7b169f81459edc8de264935017c7c9 100644 (file)
@@ -141,7 +141,7 @@ class ApiFavoriteCreateAction extends ApiAuthAction
         }
 
         $this->notify($fave, $this->notice, $this->user);
-        $this->user->blowFavesCache();
+        Fave::blowCacheForProfileId($this->user->id);
 
         if ($this->format == 'xml') {
             $this->showSingleXmlStatus($this->notice);
index 02f81cf4dfe25f9ea0b315d5bd2a929afc9ae44a..1c63ad26285c5da0b52214cf087f831c3baba8d9 100644 (file)
@@ -143,7 +143,7 @@ class ApiFavoriteDestroyAction extends ApiAuthAction
             return;
         }
 
-        $this->user->blowFavesCache();
+        Fave::blowCacheForProfileId($this->user->id);
 
         if ($this->format == 'xml') {
             $this->showSingleXmlStatus($this->notice);
index 13dc842447521641361cd64af454196a4dfd011e..366177078fd6b5ed98c6df1087010239a484340a 100644 (file)
@@ -181,23 +181,13 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
 
         common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
 
-        if (!empty($this->auth_user) && $this->auth_user->id == $this->target->id) {
-            $notice = $this->target->favoriteNotices(
-                true,
-                ($this->page-1) * $this->count,
-                $this->count,
-                $this->since_id,
-                $this->max_id
-            );
-        } else {
-            $notice = $this->target->favoriteNotices(
-                false,
-                ($this->page-1) * $this->count,
-                $this->count,
-                $this->since_id,
-                $this->max_id
-            );
-        }
+        $notice = Fave::stream($this->target->id,
+                               ($this->page-1) * $this->count,  // offset
+                               $this->count,                    // limit
+                               (!empty($this->auth_user) && $this->auth_user->id == $this->target->id),   // own feed?
+                               $this->since_id,
+                               $this->max_id
+                              );
 
         while ($notice->fetch()) {
             $notices[] = clone($notice);
index 837a9da3e96d7784ad3921c20560e6b38773e50f..69ae442a41cb6b60264008e0cf2cb112871a04c6 100644 (file)
@@ -269,8 +269,8 @@ class AtompubfavoritefeedAction extends ApiAuthAction
 
             $fave = Fave::addNew($profile, $notice);
 
-            if (!empty($fave)) {
-                $this->_profile->blowFavesCache();
+            if ($fave instanceof Fave) {
+                Fave::blowCacheForProfileId($this->_profile->id);
                 $this->notify($fave, $notice, $this->auth_user);
             }
 
index ef9ee1ee2bb57681132622b67f267fc5e24667f2..3ce7e74c79e7e3fda655048cb86aa503a6fd4107 100644 (file)
@@ -73,7 +73,7 @@ class DisfavorAction extends FormAction
             // TRANS: Server error displayed when removing a favorite from the database fails.
             $this->serverError(_('Could not delete favorite.'));
         }
-        $this->scoped->blowFavesCache();
+        Fave::blowCacheForProfileId($this->scoped->id);
         if (StatusNet::isAjax()) {
             $this->startHTML('text/xml;charset=utf-8');
             $this->elementStart('head');
index 0e0ff9383c04a2406e8d2816a755694e54204b33..8db8f9f013310d9851af3d7a9206bc199b35c02d 100644 (file)
@@ -65,7 +65,7 @@ class FavorAction extends FormAction
             $this->serverError(_('Could not create favorite.'));
         }
         $this->notify($notice, $this->scoped->getUser());
-        $this->scoped->blowFavesCache();
+        Fave::blowCacheForProfileId($this->scoped->id);
         if (StatusNet::isAjax()) {
             $this->startHTML('text/xml;charset=utf-8');
             $this->elementStart('head');
index de901b0b4643a3cfac992e52bb62bce7b3e46ad8..0cbebd723cf6ad430818134bb601119f3ce05af1 100644 (file)
@@ -85,8 +85,7 @@ class FavoritesrssAction extends Rss10Action
      */
     function getNotices($limit=0)
     {
-        $user    = $this->user;
-        $notice  = $user->favoriteNotices(false, 0, $limit);
+        $notice  = Fave::stream($this->user->id, 0, $limit, $false);
         $notices = array();
         while ($notice->fetch()) {
             $notices[] = clone($notice);
index 0e028416da2cfa1314237403bf0b44bdcb576b4d..cc355b1beff070bdc06a3b1ab2eb062b28463b63 100644 (file)
@@ -116,17 +116,13 @@ class ShowfavoritesAction extends Action
 
         $cur = common_current_user();
 
-        if (!empty($cur) && $cur->id == $this->user->id) {
-
-            // Show imported/gateway notices as well as local if
-            // the user is looking at their own favorites
-
-            $this->notice = $this->user->favoriteNotices(true, ($this->page-1)*NOTICES_PER_PAGE,
-                                                   NOTICES_PER_PAGE + 1);
-        } else {
-            $this->notice = $this->user->favoriteNotices(false, ($this->page-1)*NOTICES_PER_PAGE,
-                                                   NOTICES_PER_PAGE + 1);
-        }
+        // Show imported/gateway notices as well as local if
+        // the user is looking at their own favorites, otherwise not.
+        $this->notice = Fave::stream($this->user->id,
+                                     ($this->page-1)*NOTICES_PER_PAGE,  // offset
+                                     NOTICES_PER_PAGE + 1,              // limit
+                                     (!empty($cur) && $cur->id == $this->user->id)  // own feed?
+                                    );
 
         if (empty($this->notice)) {
             // TRANS: Server error displayed when favourite notices could not be retrieved from the database.
index 130cf6aa780ae9b18ff937091bc281d9ef84d659..777f3a362a12f00db5757b9624203f3ee822bc8b 100644 (file)
@@ -191,6 +191,27 @@ class Fave extends Managed_DataObject
         return $fav;
     }
 
+    static function countByProfile(Profile $profile)
+    {
+        $c = Cache::instance();
+        if (!empty($c)) {
+            $cnt = $c->get(Cache::key('fave:count_by_profile:'.$profile->id));
+            if (is_integer($cnt)) {
+                return $cnt;
+            }
+        }
+
+        $faves = new Fave();
+        $faves->user_id = $profile->id;
+        $cnt = (int) $faves->count('notice_id');
+
+        if (!empty($c)) {
+            $c->set(Cache::key('fave:count_by_profile:'.$profile->id), $cnt);
+        }
+
+        return $cnt;
+    }
+
     function getURI()
     {
         if (!empty($this->uri)) {
@@ -231,4 +252,18 @@ class Fave extends Managed_DataObject
         $faveMap = Fave::listGet('notice_id', $notice_ids);
         self::$_faves = array_replace(self::$_faves, $faveMap);
     }
+
+    static public function blowCacheForProfileId($profile_id)
+    {
+        $cache = Cache::instance();
+        if ($cache) {
+            // Faves don't happen chronologically, so we need to blow
+            // ;last cache, too
+            $cache->delete(Cache::key('fave:ids_by_user:'.$profile_id));
+            $cache->delete(Cache::key('fave:ids_by_user:'.$profile_id.';last'));
+            $cache->delete(Cache::key('fave:ids_by_user_own:'.$profile_id));
+            $cache->delete(Cache::key('fave:ids_by_user_own:'.$profile_id.';last'));
+            $cache->delete(Cache::key('fave:count_by_profile:'.$profile_id));
+        }
+    }
 }
index c38463f4cd87f98997c3a431a6c616c617d69e89..41fd0b0b883e2533b5652399ab9c5d584e62bb37 100644 (file)
@@ -44,7 +44,7 @@ class FavCommand extends Command
             } 
         } 
  
-        $this->user->blowFavesCache(); 
+        Fave::blowCacheForProfileId($this->user->id);
  
         // TRANS: Text shown when a notice has been marked as favourite successfully. 
         $channel->output($this->user, _('Notice marked as fave.')); 
index 235155192780191ff80e794cbb2546439882c248..c82efd0c5914b38c978f4d0ba13cfa6209028967 100644 (file)
@@ -149,7 +149,7 @@ class GNUsocialPhotosPlugin extends Plugin
                                      'title' => _('Upload a photo')));
     }
     */
-    function onEndPersonalGroupNav($nav)
+    function onEndPersonalGroupNav(Menu $nav, Profile $target, Profile $scoped=null)
     {
       
         $nav->out->menuItem(common_local_url('photos',
index bfdcf3e42db05315c2be9c9d8122db1703e2097f..6b3c757b1e68845a95a80acea90e61fb1dfb0305 100644 (file)
@@ -131,7 +131,7 @@ class GNUsocialProfileExtensionsPlugin extends Plugin
         return true;
     }
 
-    function onStartPersonalGroupNav($nav)
+    function onStartPersonalGroupNav(Menu $nav, Profile $target, Profile $scoped=null)
     { 
         $nav->out->menuItem(common_local_url('bio',
                            array('nickname' => $nav->action->trimmed('nickname'))), _('Bio'), 
index 8788a895a3acb6d0d2c5f8fa22a810ab6ee29b13..3284d10563310c2aea47d9aaa115e45d96566a7a 100644 (file)
@@ -37,6 +37,8 @@ require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
  *
  * This class allows users to link their Twitter accounts
  *
+ * Depends on Favorite plugin.
+ *
  * @category Plugin
  * @package  StatusNet
  * @author   Zach Copley <zach@status.net>
index affefb52b5aea510d93a4282f4516434c285ce7d..4cc5cb2d4a5d13f1d90415d3852ac38f13183370 100644 (file)
@@ -20,6 +20,8 @@
 /**
  * Basic client class for Yammer's OAuth/JSON API.
  *
+ * Depends on Favorite plugin
+ *
  * @package YammerImportPlugin
  * @author Brion Vibber <brion@status.net>
  */
index f02f1be2fc4f6d47d36ea74e8437e0851598c026..f5ea3ad442374f308ab6acff43ffd22cd9bfeb65 100644 (file)
@@ -443,7 +443,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase
         $this->assertEquals($notice->source, $noticeInfo->getAttribute('source'));
         $this->assertEquals('', $noticeInfo->getAttribute('repeat_of'));
         $this->assertEquals('', $noticeInfo->getAttribute('repeated'));
-        $this->assertEquals('', $noticeInfo->getAttribute('favorite'));
+//        $this->assertEquals('', $noticeInfo->getAttribute('favorite'));
         $this->assertEquals('', $noticeInfo->getAttribute('source_link'));
     }
 
@@ -485,7 +485,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase
         $this->assertEquals('false', $noticeInfo->getAttribute('repeated'));
     }
 
-    public function testNoticeInfoFave()
+/*    public function testNoticeInfoFave()
     {
         $notice = $this->_fakeNotice();
 
@@ -510,7 +510,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase
         $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
 
         $this->assertEquals('false', $noticeInfo->getAttribute('favorite'));
-    }
+    }*/
 
     public function testConversationLink()
     {