]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
authorEvan Prodromou <evan@status.net>
Fri, 19 Feb 2010 21:55:24 +0000 (16:55 -0500)
committerEvan Prodromou <evan@status.net>
Fri, 19 Feb 2010 21:55:24 +0000 (16:55 -0500)
Conflicts:
plugins/OStatus/actions/salmon.php

1  2 
plugins/OStatus/actions/salmon.php

index 7356c489a603ee435433b38e32fdfa77e80bc5db,1ed322ed28f89cf4142e371f6cb058382777ab87..7a4474ff6160cecd8729d4fa728e133a1ac53d09
@@@ -141,83 -130,43 +147,90 @@@ class SalmonAction extends Actio
      }
  
      /**
-      * @fixme probably call Ostatus_profile::processFeed
+      * We've gotten a follow/subscribe notification from a remote user.
+      * Save a subscription relationship for them.
       */
 +
      function handleFollow()
      {
-         $object = $this->act->object;
-         if ($object->id != $this->user->uri) {
-             throw new ClientException("Subscription notice not for this user.");
-         }
-         $profile = $this->ensureProfile();
-         $sub = Subscription::pkeyGet(array('subscriber' => $profile->id,
-                                            'subscribed' => $this->user->id));
-         if (!empty($sub)) {
-             throw new ClientException("Already subscribed.");
+         $oprofile = $this->ensureProfile();
+         if ($oprofile) {
+             common_log(LOG_INFO, "Setting up subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
+             $oprofile->subscribeRemoteToLocal($this->user);
+         } else {
+             common_log(LOG_INFO, "Can't set up subscription from remote; missing profile.");
          }
+     }
  
-         if ($this->user->hasBlocked($profile)) {
-             throw new ClientException("Already subscribed.");
+     /**
+      * We've gotten an unfollow/unsubscribe notification from a remote user.
+      * Check if we have a subscription relationship for them and kill it.
+      *
+      * @fixme probably catch exceptions on fail?
+      */
+     function handleUnfollow()
+     {
+         $oprofile = $this->ensureProfile();
+         if ($oprofile) {
+             common_log(LOG_INFO, "Canceling subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
+             Subscription::cancel($oprofile->localProfile(), $this->user->getProfile());
+         } else {
+             common_log(LOG_ERR, "Can't cancel subscription from remote, didn't find the profile");
          }
      }
  
      /**
-      * @fixme probably call Ostatus_profile::processFeed
+      * Remote user likes one of our posts.
+      * Confirm the post is ours, and save a local favorite event.
       */
 +
      function handleFavorite()
      {
 +        // WORST VARIABLE NAME EVER
 +        $object = $this->act->object;
 +
 +        switch ($this->act->object->type) {
 +        case ActivityObject::ARTICLE:
 +        case ActivityObject::BLOGENTRY:
 +        case ActivityObject::NOTE:
 +        case ActivityObject::STATUS:
 +        case ActivityObject::COMMENT:
 +            break;
 +        default:
 +            throw new ClientException("Can't handle that kind of object for liking/faving.");
 +        }
 +
 +        $notice = Notice::staticGet('uri', $object->id);
 +
 +        if (empty($notice)) {
 +            throw new ClientException("Notice with ID $object->id unknown.");
 +        }
 +
 +        if ($notice->profile_id != $this->user->id) {
 +            throw new ClientException("Notice with ID $object->id not posted by $this->user->id.");
 +        }
 +
 +        $profile = $this->ensureProfile();
 +
 +        $old = Fave::pkeyGet(array('user_id' => $profile->id,
 +                                   'notice_id' => $notice->id));
 +
 +        if (!empty($old)) {
 +            throw new ClientException("We already know that's a fave!");
 +        }
 +
 +        $fave = new Fave();
 +
 +        // @fixme need to change this attribute name, maybe references
 +        $fave->user_id   = $profile->id;
 +        $fave->notice_id = $notice->id;
 +
 +        $result = $fave->insert();
 +
 +        if (!$result) {
 +            common_log_db_error($fave, 'INSERT', __FILE__);
 +            throw new ServerException('Could not save new favorite.');
 +        }
      }
  
      /**