From: Evan Prodromou Date: Fri, 19 Feb 2010 21:55:24 +0000 (-0500) Subject: Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d69f6dff6a0b62ddab929f6ba0801533a9031162;p=quix0rs-gnu-social.git Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing Conflicts: plugins/OStatus/actions/salmon.php --- d69f6dff6a0b62ddab929f6ba0801533a9031162 diff --cc plugins/OStatus/actions/salmon.php index 7356c489a6,1ed322ed28..7a4474ff61 --- a/plugins/OStatus/actions/salmon.php +++ b/plugins/OStatus/actions/salmon.php @@@ -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.'); + } } /**