]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User_group.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / classes / User_group.php
index f24bef7647ec2b3bd62c1f047f2eec3ddaa6b5a7..7be55163a30186c0199f1ffc36dc82692b370089 100644 (file)
@@ -91,7 +91,7 @@ class User_group extends Memcached_DataObject
         return Notice::getStreamByIds($ids);
     }
 
-    function _streamDirect($offset, $limit, $since_id, $max_id, $since)
+    function _streamDirect($offset, $limit, $since_id, $max_id)
     {
         $inbox = new Group_inbox();
 
@@ -108,10 +108,6 @@ class User_group extends Memcached_DataObject
             $inbox->whereAdd('notice_id <= ' . $max_id);
         }
 
-        if (!is_null($since)) {
-            $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
-        }
-
         $inbox->orderBy('notice_id DESC');
 
         if (!is_null($offset)) {
@@ -283,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)) {
@@ -399,25 +409,41 @@ class User_group extends Memcached_DataObject
         return $xs->getString();
     }
 
+    /**
+     * Returns an XML string fragment with group information as an
+     * Activity Streams <activity:subject> element.
+     *
+     * Assumes that 'activity' namespace has been previously defined.
+     *
+     * @return string
+     */
     function asActivitySubject()
     {
-        $xs = new XMLStringer(true);
+        return $this->asActivityNoun('subject');
+    }
 
-        $xs->elementStart('activity:subject');
-        $xs->element('activity:object', null, 'http://activitystrea.ms/schema/1.0/group');
-        $xs->element('id', null, $this->permalink());
-        $xs->element('title', null, $this->getBestName());
-        $xs->element(
-            'link', array(
-                'rel'  => 'avatar',
-                'href' =>  empty($this->homepage_logo)
-                    ? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
-                    : $this->homepage_logo
-            )
-        );
-        $xs->elementEnd('activity:subject');
+    /**
+     * Returns an XML string fragment with group information as an
+     * Activity Streams noun object with the given element type.
+     *
+     * Assumes that 'activity', 'georss', and 'poco' namespace has been
+     * previously defined.
+     *
+     * @param string $element one of 'actor', 'subject', 'object', 'target'
+     *
+     * @return string
+     */
+    function asActivityNoun($element)
+    {
+        $noun = ActivityObject::fromGroup($this);
+        return $noun->asString('activity:' . $element);
+    }
 
-        return $xs->getString();
+    function getAvatar()
+    {
+        return empty($this->homepage_logo)
+            ? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
+            : $this->homepage_logo;
     }
 
     static function register($fields) {
@@ -429,6 +455,11 @@ class User_group extends Memcached_DataObject
         $group = new User_group();
 
         $group->query('BEGIN');
+        
+        if (empty($uri)) {
+            // fill in later...
+            $uri = null;
+        }
 
         $group->nickname    = $nickname;
         $group->fullname    = $fullname;
@@ -452,7 +483,7 @@ class User_group extends Memcached_DataObject
             $result = $group->update($orig);
             if (!$result) {
                 common_log_db_error($group, 'UPDATE', __FILE__);
-                throw new ServerException(_('Could not set group uri.'));
+                throw new ServerException(_('Could not set group URI.'));
             }
         }