Less redundant code.
This commit is contained in:
parent
01a4ab30dc
commit
cd23c78800
@ -74,7 +74,7 @@ class Memcached_DataObject extends Safe_DataObject
|
|||||||
{
|
{
|
||||||
$obj = new $cls;
|
$obj = new $cls;
|
||||||
|
|
||||||
// php-compatible, for settype(), datatype
|
// PHP compatible datatype for settype() below
|
||||||
$colType = $obj->columnType($keyCol);
|
$colType = $obj->columnType($keyCol);
|
||||||
|
|
||||||
if (!in_array($colType, array('integer', 'int'))) {
|
if (!in_array($colType, array('integer', 'int'))) {
|
||||||
|
@ -1656,32 +1656,22 @@ class Notice extends Managed_DataObject
|
|||||||
protected $_replies = array();
|
protected $_replies = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pull the complete list of @-reply targets for this notice.
|
* Pull the complete list of @-mentioned profile IDs for this notice.
|
||||||
*
|
*
|
||||||
* @return array of integer profile ids
|
* @return array of integer profile ids
|
||||||
*/
|
*/
|
||||||
function getReplies()
|
function getReplies()
|
||||||
{
|
{
|
||||||
if (isset($this->_replies[$this->id])) {
|
if (!isset($this->_replies[$this->getID()])) {
|
||||||
return $this->_replies[$this->id];
|
$mentions = Reply::multiGet('notice_id', array($this->getID()));
|
||||||
|
$this->_replies[$this->getID()] = $mentions->fetchAll('profile_id');
|
||||||
}
|
}
|
||||||
|
return $this->_replies[$this->getID()];
|
||||||
$replyMap = Reply::listGet('notice_id', array($this->id));
|
|
||||||
|
|
||||||
$ids = array();
|
|
||||||
|
|
||||||
foreach ($replyMap[$this->id] as $reply) {
|
|
||||||
$ids[] = $reply->profile_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_replies[$this->id] = $ids;
|
|
||||||
|
|
||||||
return $ids;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _setReplies($replies)
|
function _setReplies($replies)
|
||||||
{
|
{
|
||||||
$this->_replies[$this->id] = $replies;
|
$this->_replies[$this->getID()] = $replies;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
28
lib/util.php
28
lib/util.php
@ -710,25 +710,17 @@ function common_find_mentions($text, Notice $notice)
|
|||||||
|
|
||||||
// Is it a reply?
|
// Is it a reply?
|
||||||
|
|
||||||
if ($notice instanceof Notice) {
|
$origNotice = $notice->getParent();
|
||||||
|
$origAuthor = $origNotice->getProfile();
|
||||||
|
|
||||||
|
$ids = $origNotice->getReplies();
|
||||||
|
|
||||||
|
foreach ($ids as $id) {
|
||||||
try {
|
try {
|
||||||
$origNotice = $notice->getParent();
|
$repliedTo = Profile::getByID($id);
|
||||||
$origAuthor = $origNotice->getProfile();
|
$origMentions[$repliedTo->nickname] = $repliedTo;
|
||||||
|
} catch (NoResultException $e) {
|
||||||
$ids = $origNotice->getReplies();
|
// continue foreach
|
||||||
|
|
||||||
foreach ($ids as $id) {
|
|
||||||
$repliedTo = Profile::getKV('id', $id);
|
|
||||||
if ($repliedTo instanceof Profile) {
|
|
||||||
$origMentions[$repliedTo->nickname] = $repliedTo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NoProfileException $e) {
|
|
||||||
common_log(LOG_WARNING, sprintf('Notice %d author profile id %d does not exist', $origNotice->id, $origNotice->profile_id));
|
|
||||||
} catch (NoParentNoticeException $e) {
|
|
||||||
// This notice is not in reply to anything
|
|
||||||
} catch (Exception $e) {
|
|
||||||
common_log(LOG_WARNING, __METHOD__ . ' got exception ' . get_class($e) . ' : ' . $e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user