OStatus: handle update-profile Salmon pings

This commit is contained in:
Brion Vibber 2010-02-24 23:28:01 +00:00
parent ec4899e617
commit 93507a1927
2 changed files with 31 additions and 28 deletions

View File

@ -971,7 +971,7 @@ class Ostatus_profile extends Memcached_DataObject
* @param Activity $activity * @param Activity $activity
* @return mixed matching Ostatus_profile or false if none known * @return mixed matching Ostatus_profile or false if none known
*/ */
protected static function getActorProfile($activity) public static function getActorProfile($activity)
{ {
return self::getActivityObjectProfile($activity->actor); return self::getActivityObjectProfile($activity->actor);
} }
@ -1109,7 +1109,7 @@ class Ostatus_profile extends Memcached_DataObject
* @param ActivityObject $object * @param ActivityObject $object
* @param array $hints * @param array $hints
*/ */
protected function updateFromActivityObject($object, $hints=array()) public function updateFromActivityObject($object, $hints=array())
{ {
if ($this->isGroup()) { if ($this->isGroup()) {
$group = $this->localGroup(); $group = $this->localGroup();

View File

@ -38,11 +38,11 @@ class SalmonAction extends Action
parent::prepare($args); parent::prepare($args);
if ($_SERVER['REQUEST_METHOD'] != 'POST') { if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(_('This method requires a POST.')); $this->clientError(_m('This method requires a POST.'));
} }
if (empty($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/atom+xml') { if (empty($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/atom+xml') {
$this->clientError(_('Salmon requires application/atom+xml')); $this->clientError(_m('Salmon requires application/atom+xml'));
} }
$xml = file_get_contents('php://input'); $xml = file_get_contents('php://input');
@ -76,8 +76,7 @@ class SalmonAction extends Action
{ {
StatusNet::setApi(true); // Send smaller error pages StatusNet::setApi(true); // Send smaller error pages
// TODO : Insert new $xml -> notice code common_log(LOG_DEBUG, "Got a " . $this->act->verb);
if (Event::handle('StartHandleSalmon', array($this->activity))) { if (Event::handle('StartHandleSalmon', array($this->activity))) {
switch ($this->act->verb) switch ($this->act->verb)
{ {
@ -106,8 +105,11 @@ class SalmonAction extends Action
case ActivityVerb::LEAVE: case ActivityVerb::LEAVE:
$this->handleLeave(); $this->handleLeave();
break; break;
case ActivityVerb::UPDATE_PROFILE:
$this->handleUpdateProfile();
break;
default: default:
throw new ClientException(_("Unimplemented.")); throw new ClientException(_m("Unrecognized activity type."));
} }
Event::handle('EndHandleSalmon', array($this->activity)); Event::handle('EndHandleSalmon', array($this->activity));
} }
@ -115,56 +117,57 @@ class SalmonAction extends Action
function handlePost() function handlePost()
{ {
throw new ClientException(_("Unimplemented!")); throw new ClientException(_m("This target doesn't understand posts."));
} }
function handleFollow() function handleFollow()
{ {
throw new ClientException(_("Unimplemented!")); throw new ClientException(_m("This target doesn't understand follows."));
} }
function handleUnfollow() function handleUnfollow()
{ {
throw new ClientException(_("Unimplemented!")); throw new ClientException(_m("This target doesn't understand unfollows."));
} }
function handleFavorite() function handleFavorite()
{ {
throw new ClientException(_("Unimplemented!")); throw new ClientException(_m("This target doesn't understand favorites."));
} }
/**
* Remote user doesn't like one of our posts after all!
* Confirm the post is ours, and delete a local favorite event.
*/
function handleUnfavorite() function handleUnfavorite()
{ {
throw new ClientException(_("Unimplemented!")); throw new ClientException(_m("This target doesn't understand unfavorites."));
} }
/**
* Hmmmm
*/
function handleShare() function handleShare()
{ {
throw new ClientException(_("Unimplemented!")); throw new ClientException(_m("This target doesn't understand share events."));
} }
/**
* Hmmmm
*/
function handleJoin() function handleJoin()
{ {
throw new ClientException(_("Unimplemented!")); throw new ClientException(_m("This target doesn't understand joins."));
}
function handleLeave()
{
throw new ClientException(_m("This target doesn't understand leave events."));
} }
/** /**
* Hmmmm * Remote user sent us an update to their profile.
* If we already know them, accept the updates.
*/ */
function handleLeave() function handleUpdateProfile()
{ {
throw new ClientException(_("Unimplemented!")); $oprofile = Ostatus_profile::getActorProfile($this->act);
if ($oprofile) {
common_log(LOG_INFO, "Got a profile-update ping from $oprofile->uri");
$oprofile->updateFromActivityObject($this->act->actor);
} else {
common_log(LOG_INFO, "Ignoring profile-update ping from unknown " . $this->act->actor->id);
}
} }
/** /**