@@ -68,48 +68,48 @@ angular.module('mm.addons.mod_forum')
6868 } ) ;
6969 }
7070 } ) . then ( function ( ) {
71- return $mmGroups . getActivityGroupMode ( forum . cmid ) . then ( function ( mode ) {
72- usesGroups = mode === $mmGroups . SEPARATEGROUPS || mode === $mmGroups . VISIBLEGROUPS ;
73- } ) . finally ( function ( ) {
74- var promises = [ ] ;
75-
76- // Check if there are discussions stored in offline.
77- promises . push ( $mmaModForumOffline . hasNewDiscussions ( forum . id ) . then ( function ( hasOffline ) {
78- $scope . hasOffline = hasOffline ;
71+ // Check if the activity uses groups.
72+ if ( $mmGroups . canGetActivityGroupMode ( ) ) {
73+ return $mmGroups . getActivityGroupMode ( forum . cmid ) . then ( function ( mode ) {
74+ usesGroups = mode === $mmGroups . SEPARATEGROUPS || mode === $mmGroups . VISIBLEGROUPS ;
75+ } ) ;
76+ }
77+ } ) . then ( function ( ) {
78+ var promises = [ ] ;
79+
80+ // Get offline discussions if any.
81+ promises . push ( $mmaModForumOffline . getNewDiscussions ( forum . id ) . then ( function ( offlineDiscussions ) {
82+ $scope . hasOffline = ! ! offlineDiscussions . length ;
83+
84+ if ( $scope . hasOffline ) {
85+ var promise = usesGroups ?
86+ $mmaModForum . formatDiscussionsGroups ( forum . cmid , offlineDiscussions ) : $q . when ( offlineDiscussions ) ;
87+
88+ return promise . then ( function ( offlineDiscussions ) {
89+ // Fill user data for Offline discussions (should be already cached).
90+ var userPromises = [ ] ;
91+ angular . forEach ( offlineDiscussions , function ( discussion ) {
92+ if ( discussion . parent != 0 || forum . type != 'single' ) {
93+ // Do not show author for first post and type single.
94+ userPromises . push ( $mmUser . getProfile ( discussion . userid , courseid , true ) . then ( function ( user ) {
95+ discussion . userfullname = user . fullname ;
96+ discussion . userpictureurl = user . profileimageurl ;
97+ } ) ) ;
98+ }
99+ } ) ;
79100
80- if ( hasOffline ) {
81- // Get offline discussions.
82- return $mmaModForumOffline . getNewDiscussions ( forum . id ) . then ( function ( offlineDiscussions ) {
83- var promise = usesGroups ?
84- $mmaModForum . formatDiscussionsGroups ( forum . cmid , offlineDiscussions ) : $q . when ( offlineDiscussions ) ;
85-
86- return promise . then ( function ( offlineDiscussions ) {
87- // Fill user data for Offline discussions (should be already cached).
88- var userPromises = [ ] ;
89- angular . forEach ( offlineDiscussions , function ( discussion ) {
90- if ( discussion . parent != 0 || forum . type != 'single' ) {
91- // Do not show author for first post and type single.
92- userPromises . push ( $mmUser . getProfile ( discussion . userid , courseid , true ) . then ( function ( user ) {
93- discussion . userfullname = user . fullname ;
94- discussion . userpictureurl = user . profileimageurl ;
95- } ) ) ;
96- }
97- } ) ;
98-
99- return $q . all ( userPromises ) . then ( function ( ) {
100- $scope . offlineDiscussions = offlineDiscussions ;
101- } ) ;
102- } ) ;
101+ return $q . all ( userPromises ) . then ( function ( ) {
102+ $scope . offlineDiscussions = offlineDiscussions ;
103103 } ) ;
104- } else {
105- $scope . offlineDiscussions = [ ] ;
106- }
107- } ) ) ;
104+ } ) ;
105+ } else {
106+ $scope . offlineDiscussions = [ ] ;
107+ }
108+ } ) ) ;
108109
109- promises . push ( fetchDiscussions ( refresh ) ) ;
110+ promises . push ( fetchDiscussions ( refresh ) ) ;
110111
111- return $q . all ( promises ) ;
112- } ) ;
112+ return $q . all ( promises ) ;
113113 } ) . then ( function ( ) {
114114 // All data obtained, now fill the context menu.
115115 $mmCourseHelper . fillContextMenu ( $scope , module , courseid , refresh , mmaModForumComponent ) ;
0 commit comments