StartJoinGroup: when a user is joining a group
- $group: the group being joined
-- $user: the user joining
+- $profile: the local or remote user joining
EndJoinGroup: when a user finishes joining a group
- $group: the group being joined
-- $user: the user joining
+- $profile: the local or remote user joining
StartLeaveGroup: when a user is leaving a group
- $group: the group being left
-- $user: the user leaving
+- $profile: the local or remote user leaving
EndLeaveGroup: when a user has left a group
- $group: the group being left
-- $user: the user leaving
+- $profile: the local or remote user leaving
StartShowContentLicense: Showing the default license for content
- $action: the current action
}
try {
- if (Event::handle('StartJoinGroup', array($this->group, $this->user))) {
- Group_member::join($this->group->id, $this->user->id);
- Event::handle('EndJoinGroup', array($this->group, $this->user));
- }
+ $this->user->joinGroup($this->group);
} catch (Exception $e) {
// TRANS: Server error displayed when joining a group failed in the database.
// TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed.
}
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));
- }
+ $this->user->leaveGroup($this->group);
} 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.
throw new ClientException(_('Blocked by admin.'));
}
- if (Event::handle('StartJoinGroup', array($group, $this->auth_user))) {
- $membership = Group_member::join($group->id, $this->auth_user->id);
- Event::handle('EndJoinGroup', array($group, $this->auth_user));
- }
+ $this->auth_user->joinGroup($group);
Event::handle('EndAtomPubNewActivity', array($activity, $membership));
}
" 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));
- }
+ $this->auth_user->leaveGroup($this->_group);
return;
}
$cur = common_current_user();
try {
- if (Event::handle('StartJoinGroup', array($this->group, $cur))) {
- Group_member::join($this->group->id, $cur->id);
- Event::handle('EndJoinGroup', array($this->group, $cur));
- }
+ $cur->joinGroup($this->group);
} catch (Exception $e) {
// TRANS: Server error displayed when joining a group failed in the database.
// TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed.
$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));
- }
+ $cur->leaveGroup($this->group);
} 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.
/**
* Method to add a user to a group.
+ * In most cases, you should call Profile->joinGroup() instead.
*
* @param integer $group_id Group to add to
* @param integer $profile_id Profile being added
return $groups;
}
+ /**
+ * Request to join the given group.
+ * May throw exceptions on failure.
+ *
+ * @param User_group $group
+ * @return Group_member
+ */
+ function joinGroup(User_group $group)
+ {
+ $ok = null;
+ if (Event::handle('StartJoinGroup', array($group, $this))) {
+ $ok = Group_member::join($group->id, $this->id);
+ Event::handle('EndJoinGroup', array($group, $this));
+ }
+ return $ok;
+ }
+
+ /**
+ * Leave a group that this profile is a member of.
+ *
+ * @param User_group $group
+ */
+ function leaveGroup(User_group $group)
+ {
+ if (Event::handle('StartLeaveGroup', array($this->group, $this))) {
+ Group_member::leave($this->group->id, $this->id);
+ Event::handle('EndLeaveGroup', array($this->group, $this));
+ }
+ }
+
function avatarUrl($size=AVATAR_PROFILE_SIZE)
{
$avatar = $this->getAvatar($size);
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ /**
+ * @return Profile
+ */
function getProfile()
{
$profile = Profile::staticGet('id', $this->id);
return $profile->getGroups($offset, $limit);
}
+ /**
+ * Request to join the given group.
+ * May throw exceptions on failure.
+ *
+ * @param User_group $group
+ * @return Group_member
+ */
+ function joinGroup(User_group $group)
+ {
+ $profile = $this->getProfile();
+ return $profile->joinGroup($group);
+ }
+
+ /**
+ * Leave a group that this user is a member of.
+ *
+ * @param User_group $group
+ */
+ function leaveGroup(User_group $group)
+ {
+ $profile = $this->getProfile();
+ return $profile->leaveGroup($group);
+ }
+
function getSubscriptions($offset=0, $limit=null)
{
$profile = $this->getProfile();
throw new ClientException(_("User is already a member of this group."));
}
- if (Event::handle('StartJoinGroup', array($group, $user))) {
- Group_member::join($group->id, $user->id);
- Event::handle('EndJoinGroup', array($group, $user));
- }
+ $user->joinGroup($group);
}
// XXX: largely cadged from Ostatus_profile::processNote()
$sink->postActivity($act);
$group = User_group::staticGet('uri', $act->objects[0]->id);
if (!empty($group)) {
- Group_member::leave($group->id, $user->id);
+ $user->leaveGroup($group);
}
break;
case ActivityVerb::FOLLOW:
}
try {
- if (Event::handle('StartJoinGroup', array($group, $cur))) {
- Group_member::join($group->id, $cur->id);
- Event::handle('EndJoinGroup', array($group, $cur));
- }
+ $cur->joinGroup($group);
} catch (Exception $e) {
// TRANS: Message given having failed to add a user to a group.
// TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group.
}
try {
- if (Event::handle('StartLeaveGroup', array($group, $cur))) {
- Group_member::leave($group->id, $cur->id);
- Event::handle('EndLeaveGroup', array($group, $cur));
- }
+ $cur->leaveGroup($group);
} 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.
$group = User_group::getForNickname($nickname);
if ($group && !$profile->isMember($group)) {
try {
- if (Event::handle('StartJoinGroup', array($group, $user))) {
- Group_member::join($group->id, $user->id);
- Event::handle('EndJoinGroup', array($group, $user));
- }
+ $profile->joinGroup($group);
} catch (Exception $e) {
// TRANS: Server exception.
// TRANS: %1$s is a user nickname, %2$s is a group nickname.
* it'll be left with a stray membership record.
*
* @param User_group $group
- * @param User $user
+ * @param Profile $user
*
* @return mixed hook return value
*/
}
try {
- // @fixme that event currently passes a user from main UI
- // Event should probably move into Group_member::join
- // and take a Profile object.
- //
- //if (Event::handle('StartJoinGroup', array($this->group, $profile))) {
- Group_member::join($this->group->id, $profile->id);
- //Event::handle('EndJoinGroup', array($this->group, $profile));
- //}
+ $profile->joinGroup($this->group);
} catch (Exception $e) {
// TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname.
$this->serverError(sprintf(_m('Could not join remote user %1$s to group %2$s.'),
$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));
- //}
+ $profile->leaveGroup($this->group);
} 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.'),
return;
}
- if (Event::handle('StartJoinGroup', array($group, $user))) {
- $ok = Group_member::join($this->oprofile->group_id, $user->id);
- if ($ok) {
- Event::handle('EndJoinGroup', array($group, $user));
- $this->success();
- } else {
- // TRANS: OStatus remote group subscription dialog error.
- $this->showForm(_m('Remote group join failed!'));
- }
- } else {
+ try {
+ $user->joinGroup($group);
+ } catch (Exception $e) {
// TRANS: OStatus remote group subscription dialog error.
- $this->showForm(_m('Remote group join aborted!'));
+ $this->showForm(_m('Remote group join failed!'));
+ return;
}
}