123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class GroupsalmonAction extends SalmonAction
- {
- var $group = null;
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $id = $this->trimmed('id');
- if (!$id) {
-
- $this->clientError(_m('No ID.'));
- }
- $this->group = User_group::getKV('id', $id);
- if (!$this->group instanceof User_group) {
-
- $this->clientError(_m('No such group.'));
- }
- $this->target = $this->group;
- $remote_group = Ostatus_profile::getKV('group_id', $id);
- if ($remote_group instanceof Ostatus_profile) {
-
- $this->clientError(_m('Cannot accept remote posts for a remote group.'));
- }
- return true;
- }
-
- function handlePost()
- {
-
- switch ($this->activity->objects[0]->type) {
- case ActivityObject::ARTICLE:
- case ActivityObject::BLOGENTRY:
- case ActivityObject::NOTE:
- case ActivityObject::STATUS:
- case ActivityObject::COMMENT:
- break;
- default:
-
- throw new ClientException('Cannot handle that kind of post.');
- }
-
- if (empty($this->activity->context->attention)) {
-
- throw new ClientException("Not to the attention of anyone.");
- } else {
- $uri = common_local_url('groupbyid', array('id' => $this->group->id));
- if (!array_key_exists($uri, $this->activity->context->attention)) {
-
- throw new ClientException("Not to the attention of this group.");
- }
- }
- try {
- $this->saveNotice();
- } catch (AlreadyFulfilledException $e) {
- return;
- }
- }
-
-
- function handleFollow()
- {
- $this->handleJoin();
- }
-
- function handleUnfollow()
- {
- $this->handleLeave();
- }
-
- function handleJoin()
- {
- if ($this->oprofile->isGroup()) {
-
- $this->clientError(_m('Groups cannot join groups.'));
- }
- common_log(LOG_INFO, sprintf('Remote profile %s joining local group %s', $this->oprofile->getUri(), $this->group->getNickname()));
- if ($this->actor->isMember($this->group)) {
-
-
- return true;
- }
- if (Group_block::isBlocked($this->group, $this->actor)) {
-
- $this->clientError(_m('You have been blocked from that group by the admin.'), 403);
- }
- try {
- $this->actor->joinGroup($this->group);
- } catch (Exception $e) {
-
- $this->serverError(sprintf(_m('Could not join remote user %1$s to group %2$s.'),
- $this->oprofile->getUri(), $this->group->getNickname()));
- }
- }
-
- function handleLeave()
- {
- if ($this->oprofile->isGroup()) {
-
- throw new AlreadyFulfilledException(_m('Groups cannot be members of groups'));
- }
- common_log(LOG_INFO, sprintf('Remote profile %s leaving local group %s', $this->oprofile->getUri(), $this->group->getNickname()));
- try {
- $this->actor->leaveGroup($this->group);
- } catch (Exception $e) {
-
- $this->serverError(sprintf(_m('Could not remove remote user %1$s from group %2$s.'),
- $this->oprofile->getUri(), $this->group->getNickname()));
- }
- }
- }
|