+ return $lists;
+ }
+
+ /**
+ * Request to join the given group.
+ * May throw exceptions on failure.
+ *
+ * @param User_group $group
+ * @return mixed: Group_member on success, Group_join_queue if pending approval, null on some cancels?
+ */
+ function joinGroup(User_group $group)
+ {
+ $join = null;
+ if ($group->join_policy == User_group::JOIN_POLICY_MODERATE) {
+ $join = Group_join_queue::saveNew($this, $group);
+ } else {
+ if (Event::handle('StartJoinGroup', array($group, $this))) {
+ $join = Group_member::join($group->id, $this->id);
+ self::blow('profile:groups:%d', $this->id);
+ Event::handle('EndJoinGroup', array($group, $this));
+ }
+ }
+ if ($join) {
+ // Send any applicable notifications...
+ $join->notify();
+ }
+ return $join;
+ }
+
+ /**
+ * 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);
+ Event::handle('EndLeaveGroup', array($group, $this));
+ }