Refactor and centralize notice source link calculation

This commit is contained in:
Zach Copley
2010-05-06 00:20:10 -07:00
parent d9fddff539
commit c78f67aa73
4 changed files with 90 additions and 71 deletions

View File

@@ -703,7 +703,7 @@ class Notice extends Memcached_DataObject
/**
* Is this notice part of an active conversation?
*
*
* @return boolean true if other messages exist in the same
* conversation, false if this is the only one
*/
@@ -1809,4 +1809,41 @@ class Notice extends Memcached_DataObject
return $result;
}
/**
* Get the source of the notice
*
* @return Notice_source $ns A notice source object. 'code' is the only attribute
* guaranteed to be populated.
*/
function getSource()
{
$ns = new Notice_source();
if (!empty($this->source)) {
switch ($this->source) {
case 'web':
case 'xmpp':
case 'mail':
case 'omb':
case 'system':
case 'api':
$ns->code = $this->source;
break;
default:
$ns = Notice_source::staticGet($this->source);
if (!$ns) {
$ns = new Notice_source();
$ns->code = $this->source;
$app = Oauth_application::staticGet('name', $this->source);
if ($app) {
$ns->name = $app->name;
$ns->url = $app->source_url;
}
}
break;
}
}
return $ns;
}
}