@@ -21,29 +21,11 @@ angular.module('mm.addons.mod_forum')
2121 * @ngdoc service
2222 * @name $mmaModForumHelper
2323 */
24- . factory ( '$mmaModForumHelper' , function ( $mmaModForumOffline , $mmSite , $mmFileUploader , $mmFS , mmaModForumComponent , $mmUser , $q ) {
24+ . factory ( '$mmaModForumHelper' , function ( $mmaModForumOffline , $mmSite , $mmFileUploader , $mmFS , mmaModForumComponent , $mmUser , $q ,
25+ $mmFileUploaderHelper ) {
2526
2627 var self = { } ;
2728
28- /**
29- * Clear temporary attachments because a new discussion or post was cancelled.
30- * Attachments already saved in an offline discussion or post will NOT be deleted.
31- *
32- * @module mm.addons.mod_forum
33- * @ngdoc method
34- * @name $mmaModForumHelper#clearTmpFiles
35- * @param {Object[] } files List of current files.
36- * @return {Void }
37- */
38- self . clearTmpFiles = function ( files ) {
39- // Delete the local files from the tmp folder.
40- files . forEach ( function ( file ) {
41- if ( ! file . offline && file . remove ) {
42- file . remove ( ) ;
43- }
44- } ) ;
45- } ;
46-
4729 /**
4830 * Convert offline reply to online format in order to be compatible with them.
4931 *
@@ -150,7 +132,7 @@ angular.module('mm.addons.mod_forum')
150132 */
151133 self . getNewDiscussionStoredFiles = function ( forumId , timecreated , siteId ) {
152134 return $mmaModForumOffline . getNewDiscussionFolder ( forumId , timecreated , siteId ) . then ( function ( folderPath ) {
153- return getStoredFiles ( folderPath ) ;
135+ return $mmFileUploaderHelper . getStoredFiles ( folderPath ) ;
154136 } ) ;
155137 } ;
156138
@@ -168,27 +150,10 @@ angular.module('mm.addons.mod_forum')
168150 */
169151 self . getReplyStoredFiles = function ( forumId , postId , siteId , userId ) {
170152 return $mmaModForumOffline . getReplyFolder ( forumId , postId , siteId , userId ) . then ( function ( folderPath ) {
171- return getStoredFiles ( folderPath ) ;
153+ return $mmFileUploaderHelper . getStoredFiles ( folderPath ) ;
172154 } ) ;
173155 } ;
174156
175- /**
176- * Get the files stored in a folder, marking them as offline.
177- *
178- * @param {String } folderPath Folder where to get the files.
179- * @return {Promise } Promise resolved with the list of files.
180- */
181- function getStoredFiles ( folderPath ) {
182- return $mmFS . getDirectoryContents ( folderPath ) . then ( function ( files ) {
183- // Mark the files as pending offline.
184- angular . forEach ( files , function ( file ) {
185- file . offline = true ;
186- file . filename = file . name ;
187- } ) ;
188- return files ;
189- } ) ;
190- }
191-
192157 /**
193158 * Check if the data of a post/discussion has changed.
194159 *
@@ -205,20 +170,11 @@ angular.module('mm.addons.mod_forum')
205170 return false ;
206171 }
207172
208- var postFiles = post . files || [ ] ,
209- originalFiles = original . files || [ ] ;
210-
211- if ( original . subject != post . subject || original . text != post . text || postFiles . length != originalFiles . length ) {
173+ if ( original . subject != post . subject || original . text != post . text ) {
212174 return true ;
213175 }
214176
215- for ( var i = 0 ; i < postFiles . length ; i ++ ) {
216- if ( postFiles [ i ] . name != originalFiles [ i ] . name ) {
217- return true ;
218- }
219- }
220-
221- return false ;
177+ return $mmFileUploaderHelper . areFileListDifferent ( post . files , original . files ) ;
222178 } ;
223179
224180 /**
0 commit comments