diff --git a/classes/Profile.php b/classes/Profile.php index c93ba07c29..76b2ac28d0 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -192,6 +192,20 @@ class Profile extends Managed_DataObject return ($this->fullname) ? $this->fullname : $this->nickname; } + /** + * Takes the currently scoped profile into account to give a name + * to list in notice streams. Preferences may differ between profiles. + */ + function getStreamName() + { + $user = common_current_user(); + if ($user instanceof User && $user->streamNicknames()) { + return $this->nickname; + } + + return $this->getBestName(); + } + /** * Gets the full name (if filled) with nickname as a parenthetical, or the nickname alone * if no fullname is provided. diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index 734342819d..6aef97a1a4 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -222,14 +222,7 @@ class NoticeListItem extends Widget $this->out->elementStart('a', $attrs); $this->showAvatar(); $this->out->text(' '); - $user = common_current_user(); - if (!empty($user) && $user->streamNicknames()) { - $this->out->element('span',array('class' => 'fn'), - $this->profile->nickname); - } else { - $this->out->element('span',array('class' => 'fn'), - $this->profile->getBestName()); - } + $this->out->element('span',array('class' => 'fn'), $this->profile->getStreamName()); $this->out->elementEnd('a'); $this->out->elementEnd('span'); @@ -268,16 +261,12 @@ class NoticeListItem extends Widget $attentions = $this->getReplyProfiles(); - $user = common_current_user(); - - $streamNicknames = !empty($user) && $user->streamNicknames(); - foreach ($attentions as $attn) { $class = $attn->isGroup() ? 'group' : 'account'; $pa[] = array('href' => $attn->profileurl, 'title' => $attn->nickname, 'class' => "addressee {$class}", - 'text' => ($streamNicknames) ? $attn->nickname : $attn->getBestName()); + 'text' => $attn->getStreamName()); } return $pa;