@@ -59,8 +59,8 @@ angular.module('mm.addons.mod_forum')
5959 // We need to check which of the returned groups the user can post to.
6060 promise = validateVisibleGroups ( forumgroups , refresh ) ;
6161 } else {
62- // WS already filters groups, no need to do it ourselves.
63- promise = $q . when ( forumgroups ) ;
62+ // WS already filters groups, no need to do it ourselves. Add "All participants" if needed.
63+ promise = addAllParticipantsOption ( forumgroups , true ) ;
6464 }
6565
6666 return promise . then ( function ( forumgroups ) {
@@ -135,8 +135,8 @@ angular.module('mm.addons.mod_forum')
135135 return false ;
136136 } ) . then ( function ( canAdd ) {
137137 if ( canAdd ) {
138- // The user can post to all groups, return them all.
139- return forumgroups ;
138+ // The user can post to all groups, add the "All participants" option and return them all.
139+ return addAllParticipantsOption ( forumgroups ) ;
140140 } else {
141141 // The user can't post to all groups, let's check which groups he can post to.
142142 var promises = [ ] ,
@@ -189,6 +189,37 @@ angular.module('mm.addons.mod_forum')
189189 return filtered ;
190190 }
191191
192+ // Add the "All participants" option to a list of groups if the user can add a discussion to all participants.
193+ function addAllParticipantsOption ( groups , check ) {
194+ var promise ;
195+
196+ if ( ! $mmaModForum . isAllParticipantsFixed ( ) ) {
197+ // All participants has a bug, don't add it.
198+ return $q . when ( groups ) ;
199+ } else if ( check ) {
200+ // We need to check if the user can add a discussion to all participants.
201+ promise = $mmaModForum . canAddDiscussionToAll ( forumId ) . catch ( function ( ) {
202+ // The call failed, let's assume he can't.
203+ return false ;
204+ } ) ;
205+ } else {
206+ // No need to check, assume the user can.
207+ promise = $q . when ( true ) ;
208+ }
209+
210+ return promise . then ( function ( canAdd ) {
211+ if ( canAdd ) {
212+ groups . unshift ( {
213+ courseid : courseId ,
214+ id : - 1 ,
215+ name : $translate . instant ( 'mm.core.allparticipants' )
216+ } ) ;
217+ }
218+
219+ return groups ;
220+ } ) ;
221+ }
222+
192223 fetchDiscussionData ( ) . finally ( function ( ) {
193224 $scope . groupsLoaded = true ;
194225 } ) ;
0 commit comments