Link and distribute notices tagged for a group alias

Correctly link and distribute notices tagged for a group alias. Added
a helper function, getForNickname(), to User_group, to make it easier
to get a group by its nickname or aliases.
This commit is contained in:
Evan Prodromou 2009-06-14 23:43:47 -07:00
parent ecbd7718d5
commit 1b6b00a6d0
3 changed files with 18 additions and 4 deletions

View File

@ -752,9 +752,9 @@ class Notice extends Memcached_DataObject
foreach (array_unique($match[1]) as $nickname) { foreach (array_unique($match[1]) as $nickname) {
/* XXX: remote groups. */ /* XXX: remote groups. */
$group = User_group::staticGet('nickname', $nickname); $group = User_group::getForNickname($nickname);
if (!$group) { if (empty($group)) {
continue; continue;
} }

View File

@ -225,4 +225,18 @@ class User_group extends Memcached_DataObject
return true; return true;
} }
static function getForNickname($nickname)
{
$nickname = common_canonical_nickname($nickname);
$group = User_group::staticGet('nickname', $nickname);
if (!empty($group)) {
return $group;
}
$alias = Group_alias::staticGet('alias', $nickname);
if (!empty($alias)) {
return User_group::staticGet('id', $alias->group_id);
}
return null;
}
} }

View File

@ -591,7 +591,7 @@ function common_at_link($sender_id, $nickname)
function common_group_link($sender_id, $nickname) function common_group_link($sender_id, $nickname)
{ {
$sender = Profile::staticGet($sender_id); $sender = Profile::staticGet($sender_id);
$group = User_group::staticGet('nickname', common_canonical_nickname($nickname)); $group = User_group::getForNickname($nickname);
if ($group && $sender->isMember($group)) { if ($group && $sender->isMember($group)) {
$attrs = array('href' => $group->permalink(), $attrs = array('href' => $group->permalink(),
'class' => 'url'); 'class' => 'url');