forked from GNUsocial/gnu-social
pluginified most of hasFave, getFaves and related calls
The code is now more event-driven when it comes to rendering notices and their related HTML elements, since we can't have direct calls from core to a plugin. lib/activitymover.php has a function to move a Favorite activity which will not happen now. The move must be pluginified and performed as an event which plugins can catch on to.
This commit is contained in:
@@ -157,6 +157,12 @@ class Fave extends Managed_DataObject
|
||||
return $act;
|
||||
}
|
||||
|
||||
static function existsForProfile($notice, Profile $scoped) {
|
||||
$fave = self::pkeyGet(array('user_id'=>$scoped->id, 'notice_id'=>$notice->id));
|
||||
|
||||
return ($fave instanceof Fave);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a stream of favorites by profile
|
||||
*
|
||||
@@ -201,4 +207,28 @@ class Fave extends Managed_DataObject
|
||||
$notice_id,
|
||||
common_date_iso8601($modified));
|
||||
}
|
||||
|
||||
|
||||
static protected $_faves = array();
|
||||
|
||||
/**
|
||||
* All faves of this notice
|
||||
*
|
||||
* @param Notice $notice A notice we wish to get faves for (may still be ArrayWrapper)
|
||||
*
|
||||
* @return array Array of Fave objects
|
||||
*/
|
||||
static public function byNotice($notice)
|
||||
{
|
||||
if (!isset(self::$_faves[$notice->id])) {
|
||||
self::fillFaves(array($notice->id));
|
||||
}
|
||||
return self::$_faves[$notice->id];
|
||||
}
|
||||
|
||||
static public function fillFaves(array $notice_ids)
|
||||
{
|
||||
$faveMap = Fave::listGet('notice_id', $notice_ids);
|
||||
self::$_faves = array_replace(self::$_faves, $faveMap);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user