diff options
author | Zach Copley <zach@status.net> | 2010-05-06 00:20:10 -0700 |
---|---|---|
committer | Zach Copley <zach@status.net> | 2010-05-06 21:48:11 +0000 |
commit | 22fde00defe79a153ed77ddf6a4e63dd7fef6743 (patch) | |
tree | 2d17dd355e6a931c600115c0f9e6d37a7b2b108e /classes | |
parent | b547079b280b9fa2f8877aab7ad5cd3761f500b9 (diff) |
Refactor and centralize notice source link calculation
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Notice.php | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/classes/Notice.php b/classes/Notice.php index e82a82526..cd27376a4 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -704,7 +704,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 */ @@ -1812,4 +1812,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; + } + } |