]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
OStatus: fix remote groups to work with new user_groups/local_groups split.
authorBrion Vibber <brion@pobox.com>
Thu, 25 Feb 2010 21:02:08 +0000 (13:02 -0800)
committerBrion Vibber <brion@pobox.com>
Thu, 25 Feb 2010 21:02:08 +0000 (13:02 -0800)
- fix <activity:subject> generation so we get the profile info (what's available so far)
- use id instead of nickname for group join/leave forms so we can join/leave remote groups
  while the rest of the groups UI remains limited to local groups
  (plugins are responsible for making sure remote notifications and permission checks are done)
- fix remote notification when joining group through OStatus's remote subscribe form

actions/joingroup.php
actions/leavegroup.php
classes/User_group.php
lib/activity.php
lib/joinform.php
lib/leaveform.php
lib/router.php
plugins/OStatus/actions/ostatussub.php
plugins/OStatus/classes/Ostatus_profile.php

index ba642f71293b13743b8f86df5511cb7d5e26c770..f87e5dae294a281480fbd626026ce0a1a9f75f93 100644 (file)
@@ -62,30 +62,33 @@ class JoingroupAction extends Action
         }
 
         $nickname_arg = $this->trimmed('nickname');
-        $nickname = common_canonical_nickname($nickname_arg);
-
-        // Permanent redirect on non-canonical nickname
+        $id = intval($this->arg('id'));
+        if ($id) {
+            $this->group = User_group::staticGet('id', $id);
+        } else if ($nickname_arg) {
+            $nickname = common_canonical_nickname($nickname_arg);
+
+            // Permanent redirect on non-canonical nickname
+
+            if ($nickname_arg != $nickname) {
+                $args = array('nickname' => $nickname);
+                common_redirect(common_local_url('leavegroup', $args), 301);
+                return false;
+            }
 
-        if ($nickname_arg != $nickname) {
-            $args = array('nickname' => $nickname);
-            common_redirect(common_local_url('joingroup', $args), 301);
-            return false;
-        }
+            $local = Local_group::staticGet('nickname', $nickname);
 
-        if (!$nickname) {
-            $this->clientError(_('No nickname.'), 404);
-            return false;
-        }
-
-        $local = Local_group::staticGet('nickname', $nickname);
+            if (!$local) {
+                $this->clientError(_('No such group.'), 404);
+                return false;
+            }
 
-        if (!$local) {
-            $this->clientError(_('No such group.'), 404);
+            $this->group = User_group::staticGet('id', $local->group_id);
+        } else {
+            $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
 
-        $this->group = User_group::staticGet('id', $local->group_id);
-
         if (!$this->group) {
             $this->clientError(_('No such group.'), 404);
             return false;
index 222d4c1b438a9b844e6efe3e1bb1398678937816..329b5aafe1e87a306b515c889b52d906155b2aec 100644 (file)
@@ -62,30 +62,33 @@ class LeavegroupAction extends Action
         }
 
         $nickname_arg = $this->trimmed('nickname');
-        $nickname = common_canonical_nickname($nickname_arg);
-
-        // Permanent redirect on non-canonical nickname
+        $id = intval($this->arg('id'));
+        if ($id) {
+            $this->group = User_group::staticGet('id', $id);
+        } else if ($nickname_arg) {
+            $nickname = common_canonical_nickname($nickname_arg);
+
+            // Permanent redirect on non-canonical nickname
+
+            if ($nickname_arg != $nickname) {
+                $args = array('nickname' => $nickname);
+                common_redirect(common_local_url('leavegroup', $args), 301);
+                return false;
+            }
 
-        if ($nickname_arg != $nickname) {
-            $args = array('nickname' => $nickname);
-            common_redirect(common_local_url('leavegroup', $args), 301);
-            return false;
-        }
+            $local = Local_group::staticGet('nickname', $nickname);
 
-        if (!$nickname) {
-            $this->clientError(_('No nickname.'), 404);
-            return false;
-        }
-
-        $local = Local_group::staticGet('nickname', $nickname);
+            if (!$local) {
+                $this->clientError(_('No such group.'), 404);
+                return false;
+            }
 
-        if (!$local) {
-            $this->clientError(_('No such group.'), 404);
+            $this->group = User_group::staticGet('id', $local->group_id);
+        } else {
+            $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
 
-        $this->group = User_group::staticGet('id', $local->group_id);
-
         if (!$this->group) {
             $this->clientError(_('No such group.'), 404);
             return false;
index f24bef7647ec2b3bd62c1f047f2eec3ddaa6b5a7..2a58d889599d665bf4362c5a4f4efeebf4684851 100644 (file)
@@ -404,7 +404,7 @@ class User_group extends Memcached_DataObject
         $xs = new XMLStringer(true);
 
         $xs->elementStart('activity:subject');
-        $xs->element('activity:object', null, 'http://activitystrea.ms/schema/1.0/group');
+        $xs->element('activity:object-type', null, 'http://activitystrea.ms/schema/1.0/group');
         $xs->element('id', null, $this->permalink());
         $xs->element('title', null, $this->getBestName());
         $xs->element(
index e592aad6ffe3f73ae4137cb6f9d02335d420d090..4e7ff5336e2864f7ca5b96319068e311f5cc9dcf 100644 (file)
@@ -610,7 +610,10 @@ class ActivityObject
         $object->id     = $profile->getUri();
         $object->title  = $profile->getBestName();
         $object->link   = $profile->profileurl;
-        $object->avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+        $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+        if ($avatar) {
+            $object->avatar = $avatar->displayUrl();
+        }
 
         if (isset($profile->lat) && isset($profile->lon)) {
             $object->geopoint = (float)$profile->lat . ' ' . (float)$profile->lon;
@@ -664,7 +667,7 @@ class ActivityObject
                     'rel'  => 'avatar',
                     'href' => empty($this->avatar)
                     ? Avatar::defaultImage(AVATAR_PROFILE_SIZE)
-                    : $this->avatar->displayUrl()
+                    : $this->avatar
                 ),
                 null
             );
index aefb553aac928b311ace9b44aa65f324adab002c..aa8bc20e24511c5078b55c6ffc63c9e10bef2c9a 100644 (file)
@@ -100,7 +100,7 @@ class JoinForm extends Form
     function action()
     {
         return common_local_url('joingroup',
-                                array('nickname' => $this->group->nickname));
+                                array('id' => $this->group->id));
     }
 
     /**
index e63d96ee8080148a183d855dce49c84344d86a39..5469b5704c0afcad57095b5b9bf52f38a786e6d6 100644 (file)
@@ -100,7 +100,7 @@ class LeaveForm extends Form
     function action()
     {
         return common_local_url('leavegroup',
-                                array('nickname' => $this->group->nickname));
+                                array('id' => $this->group->id));
     }
 
     /**
index 987d0152e462e266a8ddc40d169e66882a990c79..0e15d83b9a246cc68084a7dd50f8c972d0f6627d 100644 (file)
@@ -247,6 +247,9 @@ class Router
                 $m->connect('group/:nickname/'.$v,
                             array('action' => $v.'group'),
                             array('nickname' => '[a-zA-Z0-9]+'));
+                $m->connect('group/:id/id/'.$v,
+                            array('action' => $v.'group'),
+                            array('id' => '[0-9]+'));
             }
 
             foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
index 12832cdcfb2fab8b2a0e4a8298ef42ecd99bd68e..aae22f868a315582098b70df06c7f99e8b09521c 100644 (file)
@@ -333,10 +333,18 @@ class OStatusSubAction extends Action
             $group = $this->oprofile->localGroup();
             if ($user->isMember($group)) {
                 $this->showForm(_m('Already a member!'));
-            } elseif (Group_member::join($this->oprofile->group_id, $user->id)) {
-                $this->successGroup();
+                return;
+            }
+            if (Event::handle('StartJoinGroup', array($group, $user))) {
+                $ok = Group_member::join($this->oprofile->group_id, $user->id);
+                if ($ok) {
+                    Event::handle('EndJoinGroup', array($group, $user));
+                    $this->successGroup();
+                } else {
+                    $this->showForm(_m('Remote group join failed!'));
+                }
             } else {
-                $this->showForm(_m('Remote group join failed!'));
+                $this->showForm(_m('Remote group join aborted!'));
             }
         } else {
             $local = $this->oprofile->localProfile();
index d66939399a3c29115c8150a781f7995cb1572ffe..f2301707764f14c970c13302dfde69a7e8a0594d 100644 (file)
@@ -162,7 +162,7 @@ class Ostatus_profile extends Memcached_DataObject
                              'jpg' => 'image/jpeg',
                              'jpeg' => 'image/jpeg',
                              'gif' => 'image/gif');
-                $extension = pathinfo(parse_url($avatarHref, PHP_URL_PATH), PATHINFO_EXTENSION);
+                $extension = pathinfo(parse_url($object->avatar, PHP_URL_PATH), PATHINFO_EXTENSION);
                 if (isset($map[$extension])) {
                     // @fixme this ain't used/saved yet
                     $object->avatarType = $map[$extension];
@@ -332,6 +332,9 @@ class Ostatus_profile extends Memcached_DataObject
      */
     public function unsubscribe() {
         $feedsub = FeedSub::staticGet('uri', $this->feeduri);
+        if (!$feedsub) {
+            return true;
+        }
         if ($feedsub->sub_state == 'active') {
             return $feedsub->unsubscribe();
         } else if ($feedsub->sub_state == '' || $feedsub->sub_state == 'inactive' || $feedsub->sub_state == 'unsubscribe') {
@@ -356,7 +359,7 @@ class Ostatus_profile extends Memcached_DataObject
             $count = $this->localProfile()->subscriberCount();
         }
         if ($count == 0) {
-            common_log(LOG_INFO, "Unsubscribing from now-unused remote feed $oprofile->feeduri");
+            common_log(LOG_INFO, "Unsubscribing from now-unused remote feed $this->feeduri");
             $this->unsubscribe();
             return true;
         } else {
@@ -1095,8 +1098,8 @@ class Ostatus_profile extends Memcached_DataObject
 
         if ($object->type == ActivityObject::PERSON) {
             $profile = new Profile();
+            $profile->created = common_sql_now();
             self::updateProfile($profile, $object, $hints);
-            $profile->created  = common_sql_now();
 
             $oprofile->profile_id = $profile->insert();
             if (!$oprofile->profile_id) {
@@ -1104,6 +1107,7 @@ class Ostatus_profile extends Memcached_DataObject
             }
         } else {
             $group = new User_group();
+            $group->uri = $homeuri;
             $group->created = common_sql_now();
             self::updateGroup($group, $object, $hints);
 
@@ -1183,19 +1187,19 @@ class Ostatus_profile extends Memcached_DataObject
     {
         $orig = clone($group);
 
-        // @fixme need to make nick unique etc *hack hack*
         $group->nickname = self::getActivityObjectNickname($object, $hints);
         $group->fullname = $object->title;
 
-        // @fixme no canonical profileurl; using homepage instead for now
-        $group->homepage = $object->id;
+        if (!empty($object->link)) {
+            $group->mainpage = $object->link;
+        } else if (array_key_exists('profileurl', $hints)) {
+            $group->mainpage = $hints['profileurl'];
+        }
 
-        // @fixme homepage
-        // @fixme bio
-        // @fixme tags/categories
-        // @fixme location?
         // @todo tags from categories
-        // @todo lat/lon/location?
+        $group->description = self::getActivityObjectBio($object, $hints);
+        $group->location = self::getActivityObjectLocation($object, $hints);
+        $group->homepage = self::getActivityObjectHomepage($object, $hints);
 
         if ($group->id) {
             common_log(LOG_DEBUG, "Updating OStatus group $group->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));