2010-02-20 16:12:43 +00: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-05 18:25:39 +01:00
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
2010-02-20 16:12:43 +00:00
|
|
|
|
2010-09-19 14:17:36 +01:00
|
|
|
/**
|
|
|
|
* @package OStatusPlugin
|
|
|
|
* @author James Walker <james@status.net>
|
|
|
|
*/
|
2010-02-20 16:12:43 +00:00
|
|
|
class GroupsalmonAction extends SalmonAction
|
|
|
|
{
|
|
|
|
var $group = null;
|
|
|
|
|
2014-05-05 18:25:39 +01:00
|
|
|
protected function prepare(array $args=array())
|
2010-02-20 16:12:43 +00:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
$id = $this->trimmed('id');
|
|
|
|
|
|
|
|
if (!$id) {
|
2010-09-19 14:17:36 +01:00
|
|
|
// TRANS: Client error.
|
|
|
|
$this->clientError(_m('No ID.'));
|
2010-02-20 16:12:43 +00:00
|
|
|
}
|
|
|
|
|
2013-08-18 12:04:58 +01:00
|
|
|
$this->group = User_group::getKV('id', $id);
|
2010-02-20 16:12:43 +00:00
|
|
|
|
2014-05-05 18:25:39 +01:00
|
|
|
if (!$this->group instanceof User_group) {
|
2010-09-19 14:17:36 +01:00
|
|
|
// TRANS: Client error.
|
|
|
|
$this->clientError(_m('No such group.'));
|
2010-02-20 16:12:43 +00:00
|
|
|
}
|
|
|
|
|
2010-12-27 18:51:59 +00:00
|
|
|
|
|
|
|
$this->target = $this->group;
|
|
|
|
|
2014-06-28 19:33:09 +01:00
|
|
|
$remote_group = Ostatus_profile::getKV('group_id', $id);
|
|
|
|
if ($remote_group instanceof Ostatus_profile) {
|
2010-09-19 14:17:36 +01:00
|
|
|
// TRANS: Client error.
|
2011-04-10 23:39:27 +01:00
|
|
|
$this->clientError(_m('Cannot accept remote posts for a remote group.'));
|
2010-02-24 02:19:13 +00:00
|
|
|
}
|
|
|
|
|
2010-02-20 16:12:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We've gotten a post event on the Salmon backchannel, probably a reply.
|
|
|
|
*/
|
|
|
|
function handlePost()
|
|
|
|
{
|
2010-03-23 01:53:09 +00:00
|
|
|
// @fixme process all objects?
|
2010-08-13 22:18:54 +01:00
|
|
|
switch ($this->activity->objects[0]->type) {
|
2010-02-20 16:12:43 +00:00
|
|
|
case ActivityObject::ARTICLE:
|
|
|
|
case ActivityObject::BLOGENTRY:
|
|
|
|
case ActivityObject::NOTE:
|
|
|
|
case ActivityObject::STATUS:
|
|
|
|
case ActivityObject::COMMENT:
|
|
|
|
break;
|
|
|
|
default:
|
2010-09-19 14:17:36 +01:00
|
|
|
// TRANS: Client exception.
|
2011-04-10 23:39:27 +01:00
|
|
|
throw new ClientException('Cannot handle that kind of post.');
|
2010-02-20 16:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notice must be to the attention of this group
|
2013-10-28 21:21:14 +00:00
|
|
|
if (empty($this->activity->context->attention)) {
|
2010-09-19 14:17:36 +01:00
|
|
|
// TRANS: Client exception.
|
2010-02-20 16:12:43 +00:00
|
|
|
throw new ClientException("Not to the attention of anyone.");
|
|
|
|
} else {
|
|
|
|
$uri = common_local_url('groupbyid', array('id' => $this->group->id));
|
2013-10-28 21:21:14 +00:00
|
|
|
|
|
|
|
if (!array_key_exists($uri, $this->activity->context->attention)) {
|
2010-09-19 14:17:36 +01:00
|
|
|
// TRANS: Client exception.
|
2010-02-20 16:12:43 +00:00
|
|
|
throw new ClientException("Not to the attention of this group.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-27 00:40:00 +00:00
|
|
|
try {
|
|
|
|
$this->saveNotice();
|
|
|
|
} catch AlreadyFulfilledException($e) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-20 16:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We've gotten a follow/subscribe notification from a remote user.
|
|
|
|
* Save a subscription relationship for them.
|
|
|
|
*/
|
|
|
|
|
2010-02-22 17:43:27 +00:00
|
|
|
/**
|
|
|
|
* Postel's law: consider a "follow" notification as a "join".
|
|
|
|
*/
|
2010-02-20 16:12:43 +00:00
|
|
|
function handleFollow()
|
|
|
|
{
|
2010-02-22 17:43:27 +00:00
|
|
|
$this->handleJoin();
|
2010-02-20 16:12:43 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 17:43:27 +00:00
|
|
|
/**
|
|
|
|
* Postel's law: consider an "unfollow" notification as a "leave".
|
|
|
|
*/
|
2010-02-20 16:12:43 +00:00
|
|
|
function handleUnfollow()
|
|
|
|
{
|
2010-02-22 17:43:27 +00:00
|
|
|
$this->handleLeave();
|
2010-02-20 16:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A remote user joined our group.
|
2010-02-22 17:43:27 +00: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-20 16:12:43 +00:00
|
|
|
*/
|
|
|
|
function handleJoin()
|
|
|
|
{
|
2014-06-28 19:33:09 +01:00
|
|
|
if ($this->oprofile->isGroup()) {
|
2010-09-19 14:17:36 +01:00
|
|
|
// TRANS: Client error.
|
2011-04-10 23:39:27 +01:00
|
|
|
$this->clientError(_m('Groups cannot join groups.'));
|
2010-02-22 17:43:27 +00:00
|
|
|
}
|
|
|
|
|
2014-06-28 19:33:09 +01:00
|
|
|
common_log(LOG_INFO, sprintf('Remote profile %s joining local group %s', $this->oprofile->getUri(), $this->group->getNickname()));
|
2010-02-22 17:43:27 +00:00
|
|
|
|
2014-06-28 19:33:09 +01:00
|
|
|
if ($this->actor->isMember($this->group)) {
|
2010-02-22 17:43:27 +00:00
|
|
|
// Already a member; we'll take it silently to aid in resolving
|
|
|
|
// inconsistencies on the other side.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-28 19:33:09 +01:00
|
|
|
if (Group_block::isBlocked($this->group, $this->actor)) {
|
2011-04-29 17:59:47 +01:00
|
|
|
// TRANS: Client error displayed when trying to join a group the user is blocked from by a group admin.
|
2010-09-19 14:17:36 +01:00
|
|
|
$this->clientError(_m('You have been blocked from that group by the admin.'), 403);
|
2010-02-22 17:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2014-06-28 19:33:09 +01:00
|
|
|
$this->actor->joinGroup($this->group);
|
2010-02-22 17:43:27 +00:00
|
|
|
} catch (Exception $e) {
|
2010-09-19 14:17:36 +01:00
|
|
|
// TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname.
|
2010-02-22 17:43:27 +00:00
|
|
|
$this->serverError(sprintf(_m('Could not join remote user %1$s to group %2$s.'),
|
2014-06-28 19:33:09 +01:00
|
|
|
$this->oprofile->getUri(), $this->group->getNickname()));
|
2010-02-22 17:43:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A remote user left our group.
|
|
|
|
*/
|
|
|
|
function handleLeave()
|
|
|
|
{
|
2014-06-28 19:33:09 +01:00
|
|
|
if ($this->oprofile->isGroup()) {
|
2011-04-29 17:59:47 +01:00
|
|
|
// TRANS: Client error displayed when trying to have a group join another group.
|
2014-06-28 19:33:09 +01:00
|
|
|
throw new AlreadyFulfilledException(_m('Groups cannot be members of groups'));
|
2010-02-22 17:43:27 +00:00
|
|
|
}
|
|
|
|
|
2014-06-28 19:33:09 +01:00
|
|
|
common_log(LOG_INFO, sprintf('Remote profile %s leaving local group %s', $this->oprofile->getUri(), $this->group->getNickname()));
|
2010-02-22 17:43:27 +00:00
|
|
|
|
|
|
|
try {
|
2014-06-28 19:33:09 +01:00
|
|
|
$this->actor->leaveGroup($this->group);
|
2010-02-22 17:43:27 +00:00
|
|
|
} catch (Exception $e) {
|
2010-09-19 14:17:36 +01:00
|
|
|
// TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname.
|
2010-02-22 17:43:27 +00:00
|
|
|
$this->serverError(sprintf(_m('Could not remove remote user %1$s from group %2$s.'),
|
2014-06-28 19:33:09 +01:00
|
|
|
$this->oprofile->getUri(), $this->group->getNickname()));
|
2010-02-22 17:43:27 +00:00
|
|
|
}
|
2010-02-20 16:12:43 +00:00
|
|
|
}
|
|
|
|
}
|