summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-03-03 19:00:02 +0000
committerBrion Vibber <brion@pobox.com>2010-03-03 19:00:02 +0000
commit3bb42d117027ebf610481ca3b0733854e0127e56 (patch)
treed0e5aa1f5fb0407879f4ba155dbfe170165a6dd6
parente6fd387c94f858a7cc63b90b02ad2afb135b6aba (diff)
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.)
-rw-r--r--classes/Notice.php2
-rw-r--r--classes/Profile.php26
-rw-r--r--classes/User.php24
-rw-r--r--classes/User_group.php20
-rw-r--r--lib/util.php2
5 files changed, 47 insertions, 27 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index c1263c782..97cb3b8fb 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -877,7 +877,7 @@ class Notice extends Memcached_DataObject
foreach (array_unique($match[1]) as $nickname) {
/* XXX: remote groups. */
- $group = User_group::getForNickname($nickname);
+ $group = User_group::getForNickname($nickname, $profile);
if (empty($group)) {
continue;
diff --git a/classes/Profile.php b/classes/Profile.php
index 470ef3320..9c2fa7a0c 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -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)
{
$avatar = $this->getAvatar($size);
diff --git a/classes/User.php b/classes/User.php
index 57d76731b..aa9fbf948 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -612,28 +612,8 @@ class User 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;
+ $profile = $this->getProfile();
+ return $profile->getGroups($offset, $limit);
}
function getSubscriptions($offset=0, $limit=null)
diff --git a/classes/User_group.php b/classes/User_group.php
index 64fe024b3..1a5ddf253 100644
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -279,12 +279,26 @@ class User_group extends Memcached_DataObject
return true;
}
- static function getForNickname($nickname)
+ static function getForNickname($nickname, $profile=null)
{
$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)) {
- return $group;
+ return User_group::staticGet('id', $group->group_id);
}
$alias = Group_alias::staticGet('alias', $nickname);
if (!empty($alias)) {
diff --git a/lib/util.php b/lib/util.php
index add1b0ae6..46be920fa 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -853,7 +853,7 @@ function common_valid_profile_tag($str)
function common_group_link($sender_id, $nickname)
{
$sender = Profile::staticGet($sender_id);
- $group = User_group::getForNickname($nickname);
+ $group = User_group::getForNickname($nickname, $sender);
if ($sender && $group && $sender->isMember($group)) {
$attrs = array('href' => $group->permalink(),
'class' => 'url');