- parent::handle($args);
-
- $cur = common_current_user();
-
- $member = new Group_member();
-
- $member->group_id = $this->group->id;
- $member->profile_id = $cur->id;
-
- if (!$member->find(true)) {
- $this->serverError(_('Could not find membership record.'));
+ parent::handle();
+
+ try {
+ $this->scoped->leaveGroup($this->group);
+ } catch (Exception $e) {
+ common_log(LOG_ERR, "Error when {$this->scoped->nickname} tried to leave {$this->group->nickname}: " . $e->getMessage());
+ // 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.'),
+ $this->scoped->nickname, $this->group->nickname));