Use poster's subscribed groups to disambiguate group linking when a remote group and a local group exist with the same name. (If you're a member of two groups with the same name though, there's not a defined winner.)

This commit is contained in:
Brion Vibber 2010-03-03 19:00:02 +00:00
parent e6fd387c94
commit 3bb42d1170
5 changed files with 47 additions and 27 deletions

View File

@ -877,7 +877,7 @@ 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::getForNickname($nickname); $group = User_group::getForNickname($nickname, $profile);
if (empty($group)) { if (empty($group)) {
continue; continue;

View File

@ -282,6 +282,32 @@ class Profile extends Memcached_DataObject
} }
} }
function getGroups($offset=0, $limit=null)
{
$qry =
'SELECT user_group.* ' .
'FROM user_group JOIN group_member '.
'ON user_group.id = group_member.group_id ' .
'WHERE group_member.profile_id = %d ' .
'ORDER BY group_member.created DESC ';
if ($offset>0 && !is_null($limit)) {
if ($offset) {
if (common_config('db','type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
}
}
$groups = new User_group();
$cnt = $groups->query(sprintf($qry, $this->id));
return $groups;
}
function avatarUrl($size=AVATAR_PROFILE_SIZE) function avatarUrl($size=AVATAR_PROFILE_SIZE)
{ {
$avatar = $this->getAvatar($size); $avatar = $this->getAvatar($size);

View File

@ -612,28 +612,8 @@ class User extends Memcached_DataObject
function getGroups($offset=0, $limit=null) function getGroups($offset=0, $limit=null)
{ {
$qry = $profile = $this->getProfile();
'SELECT user_group.* ' . return $profile->getGroups($offset, $limit);
'FROM user_group JOIN group_member '.
'ON user_group.id = group_member.group_id ' .
'WHERE group_member.profile_id = %d ' .
'ORDER BY group_member.created DESC ';
if ($offset>0 && !is_null($limit)) {
if ($offset) {
if (common_config('db','type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
}
}
$groups = new User_group();
$cnt = $groups->query(sprintf($qry, $this->id));
return $groups;
} }
function getSubscriptions($offset=0, $limit=null) function getSubscriptions($offset=0, $limit=null)

View File

@ -279,12 +279,26 @@ class User_group extends Memcached_DataObject
return true; return true;
} }
static function getForNickname($nickname) static function getForNickname($nickname, $profile=null)
{ {
$nickname = common_canonical_nickname($nickname); $nickname = common_canonical_nickname($nickname);
$group = User_group::staticGet('nickname', $nickname);
// Are there any matching remote groups this profile's in?
if ($profile) {
$group = $profile->getGroups();
while ($group->fetch()) {
if ($group->nickname == $nickname) {
// @fixme is this the best way?
return clone($group);
}
}
}
// If not, check local groups.
$group = Local_group::staticGet('nickname', $nickname);
if (!empty($group)) { if (!empty($group)) {
return $group; return User_group::staticGet('id', $group->group_id);
} }
$alias = Group_alias::staticGet('alias', $nickname); $alias = Group_alias::staticGet('alias', $nickname);
if (!empty($alias)) { if (!empty($alias)) {

View File

@ -853,7 +853,7 @@ function common_valid_profile_tag($str)
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::getForNickname($nickname); $group = User_group::getForNickname($nickname, $sender);
if ($sender && $group && $sender->isMember($group)) { if ($sender && $group && $sender->isMember($group)) {
$attrs = array('href' => $group->permalink(), $attrs = array('href' => $group->permalink(),
'class' => 'url'); 'class' => 'url');