2010-02-21 01:12:43 +09:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2010, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-05-06 02:25:39 +09:00
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
2010-02-21 01:12:43 +09:00
|
|
|
|
2010-09-19 22:17:36 +09:00
|
|
|
/**
|
|
|
|
* @package OStatusPlugin
|
|
|
|
* @author James Walker <james@status.net>
|
|
|
|
*/
|
2010-02-21 01:12:43 +09:00
|
|
|
class GroupsalmonAction extends SalmonAction
|
|
|
|
{
|
|
|
|
var $group = null;
|
|
|
|
|
2014-05-06 02:25:39 +09:00
|
|
|
protected function prepare(array $args=array())
|
2010-02-21 01:12:43 +09:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
$id = $this->trimmed('id');
|
|
|
|
|
|
|
|
if (!$id) {
|
2010-09-19 22:17:36 +09:00
|
|
|
// TRANS: Client error.
|
|
|
|
$this->clientError(_m('No ID.'));
|
2010-02-21 01:12:43 +09:00
|
|
|
}
|
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$this->group = User_group::getKV('id', $id);
|
2010-02-21 01:12:43 +09:00
|
|
|
|
2014-05-06 02:25:39 +09:00
|
|
|
if (!$this->group instanceof User_group) {
|
2010-09-19 22:17:36 +09:00
|
|
|
// TRANS: Client error.
|
|
|
|
$this->clientError(_m('No such group.'));
|
2010-02-21 01:12:43 +09:00
|
|
|
}
|
|
|
|
|
2010-12-28 03:51:59 +09:00
|
|
|
|
|
|
|
$this->target = $this->group;
|
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
$remote_group = Ostatus_profile::getKV('group_id', $id);
|
|
|
|
if ($remote_group instanceof Ostatus_profile) {
|
2010-09-19 22:17:36 +09:00
|
|
|
// TRANS: Client error.
|
2011-04-11 07:39:27 +09:00
|
|
|
$this->clientError(_m('Cannot accept remote posts for a remote group.'));
|
2010-02-24 11:19:13 +09:00
|
|
|
}
|
|
|
|
|
2010-02-21 01:12:43 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We've gotten a post event on the Salmon backchannel, probably a reply.
|
|
|
|
*/
|
|
|
|
function handlePost()
|
|
|
|
{
|
2010-03-23 10:53:09 +09:00
|
|
|
// @fixme process all objects?
|
2010-08-14 06:18:54 +09:00
|
|
|
switch ($this->activity->objects[0]->type) {
|
2010-02-21 01:12:43 +09:00
|
|
|
case ActivityObject::ARTICLE:
|
|
|
|
case ActivityObject::BLOGENTRY:
|
|
|
|
case ActivityObject::NOTE:
|
|
|
|
case ActivityObject::STATUS:
|
|
|
|
case ActivityObject::COMMENT:
|
|
|
|
break;
|
|
|
|
default:
|
2010-09-19 22:17:36 +09:00
|
|
|
// TRANS: Client exception.
|
2011-04-11 07:39:27 +09:00
|
|
|
throw new ClientException('Cannot handle that kind of post.');
|
2010-02-21 01:12:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notice must be to the attention of this group
|
2013-10-29 06:21:14 +09:00
|
|
|
if (empty($this->activity->context->attention)) {
|
2010-09-19 22:17:36 +09:00
|
|
|
// TRANS: Client exception.
|
2010-02-21 01:12:43 +09:00
|
|
|
throw new ClientException("Not to the attention of anyone.");
|
|
|
|
} else {
|
|
|
|
$uri = common_local_url('groupbyid', array('id' => $this->group->id));
|
2013-10-29 06:21:14 +09:00
|
|
|
|
|
|
|
if (!array_key_exists($uri, $this->activity->context->attention)) {
|
2010-09-19 22:17:36 +09:00
|
|
|
// TRANS: Client exception.
|
2010-02-21 01:12:43 +09:00
|
|
|
throw new ClientException("Not to the attention of this group.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-24 11:19:13 +09:00
|
|
|
$this->saveNotice();
|
2010-02-21 01:12:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We've gotten a follow/subscribe notification from a remote user.
|
|
|
|
* Save a subscription relationship for them.
|
|
|
|
*/
|
|
|
|
|
2010-02-23 02:43:27 +09:00
|
|
|
/**
|
|
|
|
* Postel's law: consider a "follow" notification as a "join".
|
|
|
|
*/
|
2010-02-21 01:12:43 +09:00
|
|
|
function handleFollow()
|
|
|
|
{
|
2010-02-23 02:43:27 +09:00
|
|
|
$this->handleJoin();
|
2010-02-21 01:12:43 +09:00
|
|
|
}
|
|
|
|
|
2010-02-23 02:43:27 +09:00
|
|
|
/**
|
|
|
|
* Postel's law: consider an "unfollow" notification as a "leave".
|
|
|
|
*/
|
2010-02-21 01:12:43 +09:00
|
|
|
function handleUnfollow()
|
|
|
|
{
|
2010-02-23 02:43:27 +09:00
|
|
|
$this->handleLeave();
|
2010-02-21 01:12:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A remote user joined our group.
|
2010-02-23 02:43:27 +09:00
|
|
|
* @fixme move permission checks and event call into common code,
|
|
|
|
* currently we're doing the main logic in joingroup action
|
|
|
|
* and so have to repeat it here.
|
2010-02-21 01:12:43 +09:00
|
|
|
*/
|
|
|
|
function handleJoin()
|
|
|
|
{
|
2014-06-29 03:33:09 +09:00
|
|
|
if ($this->oprofile->isGroup()) {
|
2010-09-19 22:17:36 +09:00
|
|
|
// TRANS: Client error.
|
2011-04-11 07:39:27 +09:00
|
|
|
$this->clientError(_m('Groups cannot join groups.'));
|
2010-02-23 02:43:27 +09:00
|
|
|
}
|
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
common_log(LOG_INFO, sprintf('Remote profile %s joining local group %s', $this->oprofile->getUri(), $this->group->getNickname()));
|
2010-02-23 02:43:27 +09:00
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
if ($this->actor->isMember($this->group)) {
|
2010-02-23 02:43:27 +09:00
|
|
|
// Already a member; we'll take it silently to aid in resolving
|
|
|
|
// inconsistencies on the other side.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
if (Group_block::isBlocked($this->group, $this->actor)) {
|
2011-04-30 01:59:47 +09:00
|
|
|
// TRANS: Client error displayed when trying to join a group the user is blocked from by a group admin.
|
2010-09-19 22:17:36 +09:00
|
|
|
$this->clientError(_m('You have been blocked from that group by the admin.'), 403);
|
2010-02-23 02:43:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2014-06-29 03:33:09 +09:00
|
|
|
$this->actor->joinGroup($this->group);
|
2010-02-23 02:43:27 +09:00
|
|
|
} catch (Exception $e) {
|
2010-09-19 22:17:36 +09:00
|
|
|
// TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname.
|
2010-02-23 02:43:27 +09:00
|
|
|
$this->serverError(sprintf(_m('Could not join remote user %1$s to group %2$s.'),
|
2014-06-29 03:33:09 +09:00
|
|
|
$this->oprofile->getUri(), $this->group->getNickname()));
|
2010-02-23 02:43:27 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A remote user left our group.
|
|
|
|
*/
|
|
|
|
function handleLeave()
|
|
|
|
{
|
2014-06-29 03:33:09 +09:00
|
|
|
if ($this->oprofile->isGroup()) {
|
2011-04-30 01:59:47 +09:00
|
|
|
// TRANS: Client error displayed when trying to have a group join another group.
|
2014-06-29 03:33:09 +09:00
|
|
|
throw new AlreadyFulfilledException(_m('Groups cannot be members of groups'));
|
2010-02-23 02:43:27 +09:00
|
|
|
}
|
|
|
|
|
2014-06-29 03:33:09 +09:00
|
|
|
common_log(LOG_INFO, sprintf('Remote profile %s leaving local group %s', $this->oprofile->getUri(), $this->group->getNickname()));
|
2010-02-23 02:43:27 +09:00
|
|
|
|
|
|
|
try {
|
2014-06-29 03:33:09 +09:00
|
|
|
$this->actor->leaveGroup($this->group);
|
2010-02-23 02:43:27 +09:00
|
|
|
} catch (Exception $e) {
|
2010-09-19 22:17:36 +09:00
|
|
|
// TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname.
|
2010-02-23 02:43:27 +09:00
|
|
|
$this->serverError(sprintf(_m('Could not remove remote user %1$s from group %2$s.'),
|
2014-06-29 03:33:09 +09:00
|
|
|
$this->oprofile->getUri(), $this->group->getNickname()));
|
2010-02-23 02:43:27 +09:00
|
|
|
}
|
2010-02-21 01:12:43 +09:00
|
|
|
}
|
|
|
|
}
|