Switch things from calling Group_member::join & leave & calling events manually to running through Profile::joinGroup() && Profile::leaveGroup(), with the events encapsulated.

This commit is contained in:
Brion Vibber
2011-03-21 14:35:29 -07:00
parent 0bec9cfdbc
commit 541dfa04fe
17 changed files with 81 additions and 70 deletions

View File

@@ -675,7 +675,7 @@ class OStatusPlugin extends Plugin
* it'll be left with a stray membership record.
*
* @param User_group $group
* @param User $user
* @param Profile $user
*
* @return mixed hook return value
*/

View File

@@ -149,14 +149,7 @@ class GroupsalmonAction extends SalmonAction
}
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.'),
@@ -181,11 +174,7 @@ class GroupsalmonAction extends SalmonAction
$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.'),

View File

@@ -141,18 +141,12 @@ class OStatusGroupAction extends OStatusSubAction
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;
}
}