protected $_profile = array();
+ /**
+ * Will always return a profile, if anything fails it will
+ * (through _setProfile) throw a NoProfileException.
+ */
public function getProfile()
{
if (!isset($this->_profile[$this->profile_id])) {
$this->clearReplies();
$this->clearRepeats();
- $this->clearFaves();
$this->clearTags();
$this->clearGroupInboxes();
$this->clearFiles();
return common_local_url('shownotice', array('notice' => $this->id), null, null, false);
}
+ public function getTitle()
+ {
+ $title = null;
+ if (Event::handle('GetNoticeTitle', array($this, &$title))) {
+ // TRANS: Title of a notice posted without a title value.
+ // TRANS: %1$s is a user name, %2$s is the notice creation date/time.
+ $title = sprintf(_('%1$s\'s status on %2$s'),
+ $this->getProfile()->getFancyName(),
+ common_exact_date($this->created));
+ }
+ return $title;
+ }
+
/*
* Get the original representation URL of this notice.
*/
$profile->nickname, $reply->id), 403);
}
- $notice->reply_to = $reply->id;
+ // If it's a repeat, the reply_to should be to the original
+ if (!empty($reply->repeat_of)) {
+ $notice->reply_to = $reply->repeat_of;
+ } else {
+ $notice->reply_to = $reply->id;
+ }
+ // But the conversation ought to be the same :)
$notice->conversation = $reply->conversation;
// If the original is private to a group, and notice has
return true;
}
- protected $_attachments = -1;
+ protected $_attachments = array();
function attachments() {
-
- if ($this->_attachments != -1) {
- return $this->_attachments;
+ if (isset($this->_attachments[$this->id])) {
+ return $this->_attachments[$this->id];
}
$f2ps = File_to_post::listGet('post_id', array($this->id));
$files = File::multiGet('id', $ids);
- $this->_attachments = $files->fetchAll();
+ $this->_attachments[$this->id] = $files->fetchAll();
- return $this->_attachments;
+ return $this->_attachments[$this->id];
}
function _setAttachments($attachments)
{
- $this->_attachments = $attachments;
+ $this->_attachments[$this->id] = $attachments;
}
function publicStream($offset=0, $limit=20, $since_id=0, $max_id=0)
return array();
}
- $sender = Profile::getKV($this->profile_id);
+ $sender = $this->getProfile();
$replied = array();
// If it's a reply, save for the replied-to author
try {
$parent = $this->getParent();
- $author = $parent->getProfile();
- if ($author instanceof Profile) {
- $this->saveReply($author->id);
- $replied[$author->id] = 1;
- self::blow('reply:stream:%d', $author->id);
- }
+ $parentauthor = $parent->getProfile();
+ $this->saveReply($parentauthor->id);
+ $replied[$parentauthor->id] = 1;
+ self::blow('reply:stream:%d', $parentauthor->id);
} catch (Exception $e) {
// Not a reply, since it has no parent!
}
return $reply;
}
- protected $_replies = -1;
+ protected $_replies = array();
/**
* Pull the complete list of @-reply targets for this notice.
*/
function getReplies()
{
- if ($this->_replies != -1) {
- return $this->_replies;
+ if (isset($this->_replies[$this->id])) {
+ return $this->_replies[$this->id];
}
$replyMap = Reply::listGet('notice_id', array($this->id));
$ids[] = $reply->profile_id;
}
- $this->_replies = $ids;
+ $this->_replies[$this->id] = $ids;
return $ids;
}
function _setReplies($replies)
{
- $this->_replies = $replies;
+ $this->_replies[$this->id] = $replies;
}
/**
* @return array of Group objects
*/
- protected $_groups = -1;
+ protected $_groups = array();
function getGroups()
{
return array();
}
- if ($this->_groups != -1)
- {
- return $this->_groups;
+ if (isset($this->_groups[$this->id])) {
+ return $this->_groups[$this->id];
}
$gis = Group_inbox::listGet('notice_id', array($this->id));
$groups = User_group::multiGet('id', $ids);
- $this->_groups = $groups->fetchAll();
+ $this->_groups[$this->id] = $groups->fetchAll();
- return $this->_groups;
+ return $this->_groups[$this->id];
}
function _setGroups($groups)
{
- $this->_groups = $groups;
+ $this->_groups[$this->id] = $groups;
}
/**
// favorite and repeated
+ $scoped = null;
if (!empty($cur)) {
- $cp = $cur->getProfile();
- $noticeInfoAttr['favorite'] = ($cp->hasFave($this)) ? "true" : "false";
- $noticeInfoAttr['repeated'] = ($cp->hasRepeated($this)) ? "true" : "false";
+ $scoped = $cur->getProfile();
+ $noticeInfoAttr['repeated'] = ($scoped->hasRepeated($this)) ? "true" : "false";
}
if (!empty($this->repeat_of)) {
$noticeInfoAttr['repeat_of'] = $this->repeat_of;
}
+ Event::handle('StatusNetApiNoticeInfo', array($this, &$noticeInfoAttr, $scoped));
+
return array('statusnet:notice_info', $noticeInfoAttr, null);
}
}
}
- function clearFaves()
- {
- $fave = new Fave();
- $fave->notice_id = $this->id;
-
- if ($fave->find()) {
- while ($fave->fetch()) {
- self::blow('fave:ids_by_user_own:%d', $fave->user_id);
- self::blow('fave:ids_by_user_own:%d;last', $fave->user_id);
- self::blow('fave:ids_by_user:%d', $fave->user_id);
- self::blow('fave:ids_by_user:%d;last', $fave->user_id);
- $fave->delete();
- }
- }
-
- $fave->free();
- }
-
function clearTags()
{
$tag = new Notice_tag();
}
}
- static function _idsOf(&$notices)
+ static function _idsOf(array &$notices)
{
$ids = array();
foreach ($notices as $notice) {
- $ids[] = $notice->id;
+ $ids[$notice->id] = true;
}
- $ids = array_unique($ids);
- return $ids;
+ return array_keys($ids);
}
static function fillAttachments(&$notices)
}
}
- protected $_faves;
-
- /**
- * All faves of this notice
- *
- * @return array Array of Fave objects
- */
-
- function getFaves()
- {
- if (isset($this->_faves) && is_array($this->_faves)) {
- return $this->_faves;
- }
- $faveMap = Fave::listGet('notice_id', array($this->id));
- $this->_faves = $faveMap[$this->id];
- return $this->_faves;
- }
-
- function _setFaves($faves)
- {
- $this->_faves = $faves;
- }
-
- static function fillFaves(&$notices)
- {
- $ids = self::_idsOf($notices);
- $faveMap = Fave::listGet('notice_id', $ids);
- $cnt = 0;
- $faved = array();
- foreach ($faveMap as $id => $faves) {
- $cnt += count($faves);
- if (count($faves) > 0) {
- $faved[] = $id;
- }
- }
- foreach ($notices as $notice) {
- $faves = $faveMap[$notice->id];
- $notice->_setFaves($faves);
- }
- }
-
static function fillReplies(&$notices)
{
$ids = self::_idsOf($notices);
}
}
- protected $_repeats;
+ protected $_repeats = array();
function getRepeats()
{
- if (isset($this->_repeats) && is_array($this->_repeats)) {
- return $this->_repeats;
+ if (isset($this->_repeats[$this->id])) {
+ return $this->_repeats[$this->id];
}
$repeatMap = Notice::listGet('repeat_of', array($this->id));
- $this->_repeats = $repeatMap[$this->id];
- return $this->_repeats;
+ $this->_repeats[$this->id] = $repeatMap[$this->id];
+ return $this->_repeats[$this->id];
}
function _setRepeats($repeats)
{
- $this->_repeats = $repeats;
+ $this->_repeats[$this->id] = $repeats;
}
static function fillRepeats(&$notices)