summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-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
4 files changed, 46 insertions, 26 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)) {