/**
  * Shared logic that works out whether a particular subscriber receives a
  * discussion or not.
  * @param forum $forum Forum
  * @param forum_discussion $discussion Discussion
  * @param object $subscriber Subscriber
  */
 function subscriber_receives_discussion($forum, $discussion, $subscriber)
 {
     // Did they subscribe specifically to this discussion?
     $explicitsubscribed = array_key_exists($discussion->get_id(), $subscriber->discussionids);
     // Did they subscribe to the group this discussion belongs to
     $explicitsubscribedtogroup = in_array($discussion->get_group_id(), $subscriber->groupids);
     $groupid = $discussion->get_group_id();
     $visiblegroups = $forum->get_group_mode() == VISIBLEGROUPS;
     // Conditions for each subscriber to get this discussion
     $result = ($subscriber->wholeforum || $explicitsubscribed || $explicitsubscribedtogroup) && (!$groupid || $subscriber->accessallgroups || $visiblegroups || array_key_exists($groupid, $subscriber->groups)) && $forum->get_type()->can_view_discussion($discussion, $subscriber->id);
     return $result;
 }