/** * Handle the request * * On POST, add the current user to the group * * @param array $args unused * * @return void */ function handle($args) { parent::handle($args); $cur = common_current_user(); try { if (Event::handle('StartLeaveGroup', array($this->group, $cur))) { Group_member::leave($this->group->id, $cur->id); Event::handle('EndLeaveGroup', array($this->group, $cur)); } } catch (Exception $e) { // TRANS: Server error displayed when leaving a group failed in the database. // TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed. $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'), $cur->nickname, $this->group->nickname)); return; } if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); // TRANS: Title for leave group page after leaving. $this->element('title', null, sprintf(_m('TITLE', '%1$s left group %2$s'), $cur->nickname, $this->group->nickname)); $this->elementEnd('head'); $this->elementStart('body'); $jf = new JoinForm($this, $this->group); $jf->show(); $this->elementEnd('body'); $this->elementEnd('html'); } else { common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname)), 303); } }
function handle($channel) { $group = $this->getGroup($this->other); $cur = $this->user; if (!$group) { $channel->error($cur, _('No such group.')); return; } if (!$cur->isMember($group)) { $channel->error($cur, _('You are not a member of that group.')); return; } try { if (Event::handle('StartLeaveGroup', array($group, $cur))) { Group_member::leave($group->id, $cur->id); Event::handle('EndLeaveGroup', array($group, $cur)); } } catch (Exception $e) { $channel->error($cur, sprintf(_('Could not remove user %s to group %s'), $cur->nickname, $group->nickname)); return; } $channel->output($cur, sprintf(_('%s left group %s'), $cur->nickname, $group->nickname)); }
/** * A remote user left our group. */ function handleLeave() { $oprofile = $this->ensureProfile(); if (!$oprofile) { $this->clientError(_m("Can't read profile to cancel group membership.")); } if ($oprofile->isGroup()) { $this->clientError(_m("Groups can't join groups.")); } common_log(LOG_INFO, "Remote profile {$oprofile->uri} leaving local group {$this->group->nickname}"); $profile = $oprofile->localProfile(); try { // @fixme event needs to be refactored as above //if (Event::handle('StartLeaveGroup', array($this->group, $profile))) { Group_member::leave($this->group->id, $profile->id); //Event::handle('EndLeaveGroup', array($this->group, $profile)); //} } catch (Exception $e) { // TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname. $this->serverError(sprintf(_m('Could not remove remote user %1$s from group %2$s.'), $oprofile->uri, $this->group->nickname)); return; } }
function handle($channel) { $group = $this->getGroup($this->other); $cur = $this->user; if (!$group) { // TRANS: Error text shown when trying to leave a group that does not exist. $channel->error($cur, _('No such group.')); return; } if (!$cur->isMember($group)) { // TRANS: Error text shown when trying to leave an existing group the user is not a member of. $channel->error($cur, _('You are not a member of that group.')); return; } try { if (Event::handle('StartLeaveGroup', array($group, $cur))) { Group_member::leave($group->id, $cur->id); Event::handle('EndLeaveGroup', array($group, $cur)); } } catch (Exception $e) { // TRANS: Message given having failed to remove a user from a group. // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group. $channel->error($cur, sprintf(_('Could not remove user %1$s from group %2$s.'), $cur->nickname, $group->nickname)); return; } // TRANS: Message given having removed a user from a group. // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group. $channel->output($cur, sprintf(_('%1$s left group %2$s.'), $cur->nickname, $group->nickname)); }
function moveActivity($act, $sink, $user, $remote) { if (empty($user)) { throw new Exception(sprintf(_("No such user %s."), $act->actor->id)); } switch ($act->verb) { case ActivityVerb::FAVORITE: $this->log(LOG_INFO, "Moving favorite of {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}."); // push it, then delete local $sink->postActivity($act); $notice = Notice::staticGet('uri', $act->objects[0]->id); if (!empty($notice)) { $fave = Fave::pkeyGet(array('user_id' => $user->id, 'notice_id' => $notice->id)); $fave->delete(); } break; case ActivityVerb::POST: $this->log(LOG_INFO, "Moving notice {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}."); // XXX: send a reshare, not a post $sink->postActivity($act); $notice = Notice::staticGet('uri', $act->objects[0]->id); if (!empty($notice)) { $notice->delete(); } break; case ActivityVerb::JOIN: $this->log(LOG_INFO, "Moving group join of {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}."); $sink->postActivity($act); $group = User_group::staticGet('uri', $act->objects[0]->id); if (!empty($group)) { Group_member::leave($group->id, $user->id); } break; case ActivityVerb::FOLLOW: if ($act->actor->id == $user->uri) { $this->log(LOG_INFO, "Moving subscription to {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}."); $sink->postActivity($act); $other = Profile::fromURI($act->objects[0]->id); if (!empty($other)) { Subscription::cancel($user->getProfile(), $other); } } else { $otherUser = User::staticGet('uri', $act->actor->id); if (!empty($otherUser)) { $this->log(LOG_INFO, "Changing sub to {$act->objects[0]->id}" . "by {$act->actor->id} to {$remote->nickname}."); $otherProfile = $otherUser->getProfile(); Subscription::start($otherProfile, $remote); Subscription::cancel($otherProfile, $user->getProfile()); } else { $this->log(LOG_NOTICE, "Not changing sub to {$act->objects[0]->id}" . "by remote {$act->actor->id} " . "to {$remote->nickname}."); } } break; } }
/** * Delete the membership (leave the group) * * @return void */ function deleteMembership() { if (empty($this->auth_user) || $this->auth_user->id != $this->_profile->id) { // TRANS: Client exception thrown when deleting someone else's membership. throw new ClientException(_("Cannot delete someone else's" . " membership."), 403); } if (Event::handle('StartLeaveGroup', array($this->_group, $this->auth_user))) { Group_member::leave($this->_group->id, $this->auth_user->id); Event::handle('EndLeaveGroup', array($this->_group, $this->auth_user)); } return; }
/** * Leave a group that this profile is a member of. * * @param User_group $group */ function leaveGroup(User_group $group) { if (Event::handle('StartLeaveGroup', array($group, $this))) { Group_member::leave($group->id, $this->id); self::blow('profile:groups:%d', $this->id); self::blow('group:member_ids:%d', $group->id); self::blow('group:member_count:%d', $group->id); Event::handle('EndLeaveGroup', array($group, $this)); } }
/** * Handle the request * * Save the new message * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (empty($this->user)) { // TRANS: Client error displayed when trying to have a non-existing user leave a group. $this->clientError(_('No such user.'), 404, $this->format); return; } if (empty($this->group)) { // TRANS: Client error displayed when trying to leave a group that does not exist. $this->clientError(_('Group not found.'), 404, $this->format); return false; } $member = new Group_member(); $member->group_id = $this->group->id; $member->profile_id = $this->auth_user->id; if (!$member->find(true)) { // TRANS: Server error displayed when trying to leave a group the user is not a member of. $this->serverError(_('You are not a member of this group.')); return; } try { if (Event::handle('StartLeaveGroup', array($this->group, $this->user))) { Group_member::leave($this->group->id, $this->user->id); Event::handle('EndLeaveGroup', array($this->group, $this->user)); } } catch (Exception $e) { // TRANS: Server error displayed when leaving a group failed in the database. // TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed. $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'), $cur->nickname, $this->group->nickname)); return; } switch ($this->format) { case 'xml': $this->showSingleXmlGroup($this->group); break; case 'json': $this->showSingleJsonGroup($this->group); break; default: $this->clientError(_('API method not found.'), 404, $this->format); break; } }
/** * Handle the request * * On POST, add the current user to the group * * @param array $args unused * * @return void */ function handle($args) { parent::handle($args); $cur = common_current_user(); try { if (Event::handle('StartLeaveGroup', array($this->group, $cur))) { Group_member::leave($this->group->id, $cur->id); Event::handle('EndLeaveGroup', array($this->group, $cur)); } } catch (Exception $e) { $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'), $cur->nickname, $this->group->nickname)); return; } if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); $this->element('title', null, sprintf(_('%1$s left group %2$s'), $cur->nickname, $this->group->nickname)); $this->elementEnd('head'); $this->elementStart('body'); $jf = new JoinForm($this, $this->group); $jf->show(); $this->elementEnd('body'); $this->elementEnd('html'); } else { common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname)), 303); } }