From 7ea188af49390f193b7c91dfec6f31985eb38b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 15 Nov 2024 12:59:47 +0100 Subject: [PATCH] MOBILE-4653 utils: Move promise related utils functions --- .../badges/pages/badge-class/badge-class.ts | 4 +- .../badges/pages/issued-badge/issued-badge.ts | 6 +- .../badges/pages/user-badges/user-badges.ts | 6 +- .../badges/services/handlers/push-click.ts | 3 +- .../components/myoverview/myoverview.ts | 6 +- .../recentlyaccessedcourses.ts | 5 +- .../starredcourses/starredcourses.ts | 5 +- .../timeline/components/timeline/timeline.ts | 4 +- .../blog/pages/edit-entry/edit-entry.ts | 3 +- src/addons/blog/pages/index/index.ts | 12 +- src/addons/blog/services/blog-offline.ts | 4 +- src/addons/blog/services/blog.ts | 7 +- .../calendar/pages/edit-event/edit-event.ts | 3 +- src/addons/calendar/pages/event/event.ts | 4 +- .../calendar/services/calendar-helper.ts | 7 +- src/addons/calendar/services/calendar-sync.ts | 9 +- src/addons/calendar/services/calendar.ts | 13 +- .../calendar/services/database/calendar.ts | 4 +- .../competency-course-competencies-source.ts | 4 +- .../competency-plan-competencies-source.ts | 4 +- .../pages/competency/competency.page.ts | 10 +- .../competencysummary.page.ts | 4 +- src/addons/competency/services/competency.ts | 4 +- .../services/handlers/push-click.ts | 9 +- .../services/handlers/mathjaxloader.ts | 6 +- .../airnotifier/pages/devices/devices.ts | 6 +- .../messages/pages/discussion/discussion.ts | 4 +- .../pages/discussions-35/discussions.ts | 3 +- src/addons/messages/services/messages.ts | 11 +- .../mod/assign/classes/submissions-source.ts | 4 +- .../edit-feedback-modal.ts | 4 +- .../mod/assign/components/index/index.ts | 10 +- .../components/submission/submission.ts | 11 +- .../feedback/comments/component/comments.ts | 4 +- .../feedback/comments/services/handler.ts | 4 +- src/addons/mod/assign/pages/edit/edit.ts | 3 +- .../mod/assign/services/assign-helper.ts | 9 +- src/addons/mod/assign/services/assign-sync.ts | 17 +- .../mod/assign/services/handlers/prefetch.ts | 6 +- .../assign/services/handlers/push-click.ts | 3 +- .../assign/submission/file/component/file.ts | 6 +- .../submission/file/services/handler.ts | 7 +- .../onlinetext/component/onlinetext.ts | 4 +- .../submission/onlinetext/services/handler.ts | 4 +- .../bigbluebuttonbn/components/index/index.ts | 3 +- src/addons/mod/book/components/index/index.ts | 4 +- .../mod/book/pages/contents/contents.ts | 8 +- src/addons/mod/book/services/book.ts | 4 +- .../mod/book/services/handlers/prefetch.ts | 6 +- .../mod/chat/classes/chat-sessions-source.ts | 6 +- src/addons/mod/chat/pages/chat/chat.ts | 6 +- .../session-messages/session-messages.ts | 8 +- .../mod/chat/pages/sessions/sessions.ts | 4 +- .../chat/services/handlers/prefetch-lazy.ts | 6 +- src/addons/mod/choice/services/choice-sync.ts | 5 +- src/addons/mod/choice/services/choice.ts | 5 +- .../mod/choice/services/handlers/prefetch.ts | 4 +- src/addons/mod/data/components/index/index.ts | 3 +- src/addons/mod/data/pages/entry/entry.ts | 3 +- src/addons/mod/data/services/data-helper.ts | 4 +- src/addons/mod/data/services/data-offline.ts | 6 +- src/addons/mod/data/services/data-sync.ts | 13 +- src/addons/mod/data/services/data.ts | 3 +- .../data/services/handlers/prefetch-lazy.ts | 5 +- .../mod/feedback/components/index/index.ts | 4 +- .../mod/feedback/pages/attempts/attempts.ts | 4 +- src/addons/mod/feedback/pages/form/form.ts | 3 +- .../pages/nonrespondents/nonrespondents.ts | 4 +- .../mod/feedback/services/feedback-sync.ts | 13 +- src/addons/mod/feedback/services/feedback.ts | 9 +- .../feedback/services/handlers/prefetch.ts | 4 +- .../mod/folder/components/index/index.ts | 4 +- src/addons/mod/folder/services/folder.ts | 4 +- .../forum/classes/forum-discussions-source.ts | 3 +- src/addons/mod/forum/components/post/post.ts | 3 +- .../mod/forum/pages/discussion/discussion.ts | 7 +- .../pages/new-discussion/new-discussion.ts | 5 +- src/addons/mod/forum/pages/search/search.ts | 3 +- src/addons/mod/forum/services/forum-helper.ts | 7 +- src/addons/mod/forum/services/forum-sync.ts | 23 +- src/addons/mod/forum/services/forum.ts | 9 +- .../mod/forum/services/handlers/prefetch.ts | 10 +- .../mod/forum/services/handlers/push-click.ts | 3 +- src/addons/mod/glossary/pages/entry/entry.ts | 24 +-- .../mod/glossary/services/glossary-helper.ts | 4 +- .../mod/glossary/services/glossary-sync.ts | 13 +- src/addons/mod/glossary/services/glossary.ts | 11 +- .../glossary/services/handlers/prefetch.ts | 4 +- .../mod/h5pactivity/components/index/index.ts | 4 +- .../pages/attempt-results/attempt-results.ts | 6 +- .../pages/user-attempts/user-attempts.ts | 6 +- .../pages/users-attempts/users-attempts.ts | 6 +- .../h5pactivity/services/h5pactivity-sync.ts | 5 +- .../h5pactivity/services/handlers/prefetch.ts | 4 +- .../services/handlers/report-link.ts | 4 +- .../mod/imscp/components/index/index.ts | 4 +- src/addons/mod/imscp/pages/view/view.ts | 6 +- .../mod/imscp/services/handlers/prefetch.ts | 4 +- src/addons/mod/imscp/services/imscp.ts | 4 +- .../mod/label/services/handlers/prefetch.ts | 4 +- src/addons/mod/label/services/label.ts | 4 +- .../mod/lesson/components/index/index.ts | 10 +- src/addons/mod/lesson/pages/player/player.ts | 3 +- .../lesson/pages/user-retake/user-retake.ts | 5 +- .../lesson/services/handlers/index-link.ts | 4 +- .../mod/lesson/services/handlers/prefetch.ts | 8 +- .../mod/lesson/services/lesson-offline.ts | 9 +- src/addons/mod/lesson/services/lesson-sync.ts | 19 +- src/addons/mod/lesson/services/lesson.ts | 11 +- src/addons/mod/page/components/index/index.ts | 3 +- .../mod/page/services/handlers/prefetch.ts | 4 +- src/addons/mod/page/services/page.ts | 4 +- .../password/services/handlers/password.ts | 4 +- src/addons/mod/quiz/components/index/index.ts | 8 +- src/addons/mod/quiz/pages/player/player.ts | 8 +- src/addons/mod/quiz/pages/review/review.ts | 6 +- .../quiz/services/access-rules-delegate.ts | 18 +- .../mod/quiz/services/handlers/prefetch.ts | 10 +- .../mod/quiz/services/handlers/push-click.ts | 3 +- src/addons/mod/quiz/services/quiz-helper.ts | 3 +- src/addons/mod/quiz/services/quiz-offline.ts | 8 +- src/addons/mod/quiz/services/quiz-sync.ts | 10 +- .../mod/resource/components/index/index.ts | 3 +- .../mod/resource/services/handlers/module.ts | 6 +- src/addons/mod/resource/services/resource.ts | 4 +- .../mod/scorm/components/index/index.ts | 9 +- src/addons/mod/scorm/pages/player/player.ts | 8 +- .../mod/scorm/services/handlers/prefetch.ts | 12 +- src/addons/mod/scorm/services/scorm-helper.ts | 7 +- .../mod/scorm/services/scorm-offline.ts | 3 +- src/addons/mod/scorm/services/scorm-sync.ts | 22 +- src/addons/mod/scorm/services/scorm.ts | 5 +- .../mod/survey/components/index/index.ts | 4 +- .../survey/services/handlers/prefetch-lazy.ts | 4 +- src/addons/mod/survey/services/survey-sync.ts | 7 +- src/addons/mod/survey/services/survey.ts | 3 +- .../mod/url/services/handlers/module.ts | 4 +- src/addons/mod/url/services/url.ts | 4 +- src/addons/mod/wiki/components/index/index.ts | 6 +- src/addons/mod/wiki/pages/edit/edit.ts | 8 +- .../wiki/services/handlers/prefetch-lazy.ts | 4 +- src/addons/mod/wiki/services/wiki-sync.ts | 11 +- src/addons/mod/wiki/services/wiki.ts | 3 +- .../assessment-strategy.ts | 3 +- .../mod/workshop/components/index/index.ts | 3 +- .../services/handlers/prefetch-lazy.ts | 3 +- .../mod/workshop/services/workshop-helper.ts | 9 +- .../mod/workshop/services/workshop-sync.ts | 17 +- src/addons/notes/pages/list/list.ts | 4 +- src/addons/notes/services/notes-sync.ts | 7 +- src/addons/notes/services/notes.ts | 9 +- src/addons/notifications/pages/list/list.ts | 7 +- .../notifications/pages/settings/settings.ts | 8 +- .../services/handlers/push-click.ts | 5 +- .../services/notifications-helper.ts | 5 +- src/addons/privatefiles/pages/index/index.ts | 4 +- src/addons/qtype/ddmarker/classes/ddmarker.ts | 4 +- .../services/remotethemes-handler.ts | 4 +- .../items-management/list-items-manager.ts | 3 +- src/core/classes/page-load-watcher.ts | 4 +- src/core/classes/sites/authenticated-site.ts | 5 +- src/core/classes/sites/site.ts | 11 +- .../components/attachments/attachments.ts | 4 +- src/core/components/file/file.ts | 3 +- .../components/show-password/show-password.ts | 4 +- .../components/site-picker/site-picker.ts | 4 +- src/core/directives/external-content.ts | 6 +- src/core/directives/format-text.ts | 7 +- src/core/directives/tests/format-text.test.ts | 4 +- .../components/side-blocks/side-blocks.ts | 4 +- .../comments/components/comments/comments.ts | 4 +- .../features/comments/pages/viewer/viewer.ts | 8 +- .../comments/services/comments-sync.ts | 5 +- .../features/comments/services/comments.ts | 7 +- .../components/compile-html/compile-html.ts | 4 +- .../services/contentlinks-delegate.ts | 5 +- .../course/classes/main-activity-component.ts | 6 +- .../course/classes/main-resource-component.ts | 11 +- .../components/course-format/course-format.ts | 6 +- .../module-navigation/module-navigation.ts | 4 +- .../module-summary/module-summary.ts | 3 +- .../course/pages/contents/contents.ts | 27 +-- .../course-summary/course-summary.page.ts | 8 +- src/core/features/course/pages/index/index.ts | 4 +- .../pages/list-mod-type/list-mod-type.ts | 4 +- .../features/course/services/course-helper.ts | 19 +- .../services/course-options-delegate.ts | 4 +- src/core/features/course/services/course.ts | 9 +- .../services/handlers/default-format.ts | 4 +- .../features/course/services/log-helper.ts | 3 +- .../services/module-prefetch-delegate.ts | 15 +- src/core/features/course/services/sync.ts | 5 +- .../courses/pages/dashboard/dashboard.ts | 4 +- src/core/features/courses/pages/my/my.ts | 6 +- .../services/handlers/base-link-handler.ts | 6 +- .../services/handlers/dashboard-home.ts | 4 +- .../services/handlers/request-push-click.ts | 3 +- .../courses/services/handlers/section-link.ts | 6 +- .../components/contactdpo/contactdpo.ts | 4 +- .../features/dataprivacy/pages/main/main.ts | 6 +- .../fileuploader/services/fileuploader.ts | 3 +- .../features/filter/services/filter-helper.ts | 4 +- .../grades/pages/course/course.page.ts | 8 +- .../features/grades/pages/courses/courses.ts | 6 +- .../features/grades/services/grades-helper.ts | 5 +- .../features/grades/services/handlers/user.ts | 6 +- src/core/features/h5p/classes/file-storage.ts | 6 +- src/core/features/h5p/classes/player.ts | 7 +- src/core/features/h5p/classes/storage.ts | 6 +- src/core/features/h5p/services/h5p.ts | 4 +- src/core/features/login/guards/has-sites.ts | 4 +- .../login/pages/email-signup/email-signup.ts | 3 +- .../login/pages/reconnect/reconnect.ts | 4 +- src/core/features/login/pages/site/site.ts | 8 +- .../features/login/services/handlers/cron.ts | 6 +- .../features/login/services/login-helper.ts | 9 +- .../components/user-menu/user-menu.ts | 4 +- .../policy/pages/acceptances/acceptances.ts | 8 +- .../policy/pages/site-policy/site-policy.ts | 7 +- .../services/push-delegate.ts | 4 +- .../services/pushnotifications.ts | 13 +- .../question/components/question/question.ts | 4 +- .../question/services/question-helper.ts | 7 +- .../rating/services/rating-offline.ts | 4 +- .../reminders/services/database/reminders.ts | 6 +- .../components/report-detail/report-detail.ts | 7 +- .../features/reportbuilder/pages/list/list.ts | 6 +- .../global-search-filters.component.ts | 4 +- .../pages/global-search/global-search.ts | 3 +- .../settings/pages/deviceinfo/deviceinfo.ts | 4 +- .../settings/pages/general/general.ts | 4 +- .../settings/pages/space-usage/space-usage.ts | 3 +- .../settings/services/settings-helper.ts | 4 +- .../sharedfiles/services/sharedfiles.ts | 6 +- .../features/sitehome/pages/index/index.ts | 4 +- .../classes/handlers/module-handler.ts | 4 +- .../handlers/module-prefetch-handler.ts | 4 +- .../siteplugins/services/siteplugins-init.ts | 14 +- src/core/features/styles/services/styles.ts | 10 +- src/core/features/tag/pages/search/search.ts | 4 +- .../classes/support/guest-support-config.ts | 4 +- src/core/features/user/pages/about/about.ts | 4 +- .../pages/participants/participants.page.ts | 8 +- .../features/user/pages/profile/profile.ts | 4 +- .../features/user/services/user-delegate.ts | 4 +- .../features/user/services/user-offline.ts | 4 +- src/core/features/user/services/user-sync.ts | 3 +- src/core/features/user/services/user.ts | 9 +- src/core/features/xapi/services/offline.ts | 4 +- src/core/features/xapi/services/xapi.ts | 3 +- src/core/guards/can-leave.ts | 4 +- src/core/services/cron.ts | 12 +- src/core/services/file.ts | 7 +- src/core/services/filepool.ts | 19 +- src/core/services/geolocation.ts | 4 +- src/core/services/navigator.ts | 3 +- src/core/services/sites.ts | 11 +- src/core/services/update-manager.ts | 8 +- src/core/services/utils/iframe.ts | 5 +- src/core/services/utils/utils.ts | 135 +++--------- src/core/singletons/iab.ts | 2 +- src/core/singletons/promise-utils.ts | 199 ++++++++++++++++++ src/testing/services/behat-runtime.ts | 4 +- 263 files changed, 1088 insertions(+), 860 deletions(-) create mode 100644 src/core/singletons/promise-utils.ts diff --git a/src/addons/badges/pages/badge-class/badge-class.ts b/src/addons/badges/pages/badge-class/badge-class.ts index 0184cda39..f7c6c9bbb 100644 --- a/src/addons/badges/pages/badge-class/badge-class.ts +++ b/src/addons/badges/pages/badge-class/badge-class.ts @@ -14,7 +14,7 @@ import { Component, OnInit } from '@angular/core'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreNavigator } from '@services/navigator'; import { ActivatedRoute } from '@angular/router'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; @@ -81,7 +81,7 @@ export class AddonBadgesBadgeClassPage implements OnInit { * @param refresher Refresher. */ async refreshBadgeClass(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(AddonBadges.invalidateBadgeClass(this.badgeId)); + await CorePromiseUtils.ignoreErrors(AddonBadges.invalidateBadgeClass(this.badgeId)); await this.fetchBadgeClass(); diff --git a/src/addons/badges/pages/issued-badge/issued-badge.ts b/src/addons/badges/pages/issued-badge/issued-badge.ts index 0b94c5874..44f0e5405 100644 --- a/src/addons/badges/pages/issued-badge/issued-badge.ts +++ b/src/addons/badges/pages/issued-badge/issued-badge.ts @@ -18,7 +18,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreSites } from '@services/sites'; import { CoreUser } from '@features/user/services/user'; import { AddonBadges, AddonBadgesUserBadge } from '../../services/badges'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreCourses } from '@features/courses/services/courses'; import { CoreNavigator } from '@services/navigator'; import { ActivatedRoute } from '@angular/router'; @@ -151,12 +151,12 @@ export class AddonBadgesIssuedBadgePage implements OnInit, OnDestroy { * @param refresher Refresher. */ async refreshBadges(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.allPromisesIgnoringErrors([ + await CorePromiseUtils.allPromisesIgnoringErrors([ AddonBadges.invalidateUserBadges(this.courseId, this.userId), AddonBadges.invalidateUserBadgeByHash(this.badgeHash), ]); - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ this.fetchIssuedBadge(), ])); diff --git a/src/addons/badges/pages/user-badges/user-badges.ts b/src/addons/badges/pages/user-badges/user-badges.ts index eab870748..18cca0ec4 100644 --- a/src/addons/badges/pages/user-badges/user-badges.ts +++ b/src/addons/badges/pages/user-badges/user-badges.ts @@ -17,7 +17,7 @@ import { AddonBadges, AddonBadgesUserBadge } from '../../services/badges'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreNavigator } from '@services/navigator'; import { CoreListItemsManager } from '@classes/items-management/list-items-manager'; @@ -90,13 +90,13 @@ export class AddonBadgesUserBadgesPage implements AfterViewInit, OnDestroy { * @param refresher Refresher. */ async refreshBadges(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( AddonBadges.invalidateUserBadges( this.badges.getSource().COURSE_ID, this.badges.getSource().USER_ID, ), ); - await CoreUtils.ignoreErrors(this.badges.reload()); + await CorePromiseUtils.ignoreErrors(this.badges.reload()); refresher?.complete(); } diff --git a/src/addons/badges/services/handlers/push-click.ts b/src/addons/badges/services/handlers/push-click.ts index 8d3dfc90a..da50ffb03 100644 --- a/src/addons/badges/services/handlers/push-click.ts +++ b/src/addons/badges/services/handlers/push-click.ts @@ -21,6 +21,7 @@ import { makeSingleton } from '@singletons'; import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications'; import { CoreNavigator } from '@services/navigator'; import { AddonBadgesHelper } from '../badges-helper'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler for badges push notifications clicks. @@ -72,7 +73,7 @@ export class AddonBadgesPushClickHandlerService implements CorePushNotifications } // No hash, open the list of user badges. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( AddonBadges.invalidateUserBadges( 0, Number(notification.usertoid), diff --git a/src/addons/block/myoverview/components/myoverview/myoverview.ts b/src/addons/block/myoverview/components/myoverview/myoverview.ts index 2e3632319..cb4285b47 100644 --- a/src/addons/block/myoverview/components/myoverview/myoverview.ts +++ b/src/addons/block/myoverview/components/myoverview/myoverview.ts @@ -26,7 +26,7 @@ import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/servi import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate'; import { CoreBlockBaseComponent } from '@features/block/classes/base-block-component'; import { CoreSite } from '@classes/sites/site'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreText } from '@singletons/text'; import { AddonCourseCompletion } from '@addons/coursecompletion/services/coursecompletion'; @@ -243,7 +243,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem // Invalidate course completion data. promises.push(this.invalidateCourseList().finally(() => - CoreUtils.allPromises(courseIds.map((courseId) => + CorePromiseUtils.allPromises(courseIds.map((courseId) => AddonCourseCompletion.invalidateCourseCompletion(courseId))))); if (courseIds.length == 1) { @@ -255,7 +255,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem promises.push(CoreCourses.invalidateCoursesByField('ids', courseIds.join(','))); } - await CoreUtils.allPromises(promises).finally(() => { + await CorePromiseUtils.allPromises(promises).finally(() => { this.prefetchIconsInitialized = false; }); } diff --git a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts index 3cc68efad..148146f33 100644 --- a/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts +++ b/src/addons/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts @@ -37,6 +37,7 @@ import { CoreCoursesMyCoursesUpdatedEventAction, CORE_COURSES_STATE_FAVOURITE, } from '@features/courses/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component to render a recent courses block. @@ -118,7 +119,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom // Invalidate course completion data. promises.push(this.invalidateCourseList().finally(() => - CoreUtils.allPromises(courseIds.map((courseId) => + CorePromiseUtils.allPromises(courseIds.map((courseId) => AddonCourseCompletion.invalidateCourseCompletion(courseId))))); if (courseIds.length == 1) { @@ -130,7 +131,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom promises.push(CoreCourses.invalidateCoursesByField('ids', courseIds.join(','))); } - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/block/starredcourses/components/starredcourses/starredcourses.ts b/src/addons/block/starredcourses/components/starredcourses/starredcourses.ts index 2f1d6f04d..0bd36fa50 100644 --- a/src/addons/block/starredcourses/components/starredcourses/starredcourses.ts +++ b/src/addons/block/starredcourses/components/starredcourses/starredcourses.ts @@ -33,6 +33,7 @@ import { CoreCoursesMyCoursesUpdatedEventAction, CORE_COURSES_STATE_FAVOURITE, } from '@features/courses/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component to render a starred courses block. @@ -113,7 +114,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im // Invalidate course completion data. promises.push(this.invalidateCourseList().finally(() => - CoreUtils.allPromises(courseIds.map((courseId) => + CorePromiseUtils.allPromises(courseIds.map((courseId) => AddonCourseCompletion.invalidateCourseCompletion(courseId))))); if (courseIds.length == 1) { @@ -125,7 +126,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im promises.push(CoreCourses.invalidateCoursesByField('ids', courseIds.join(','))); } - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/block/timeline/components/timeline/timeline.ts b/src/addons/block/timeline/components/timeline/timeline.ts index 9a814c0e3..fe552eed2 100644 --- a/src/addons/block/timeline/components/timeline/timeline.ts +++ b/src/addons/block/timeline/components/timeline/timeline.ts @@ -16,7 +16,7 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; import { CoreSites } from '@services/sites'; import { ICoreBlockComponent } from '@features/block/classes/base-block-component'; import { AddonBlockTimeline } from '../../services/timeline'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreCoursesHelper, CoreEnrolledCourseDataWithOptions } from '@features/courses/services/courses-helper'; import { CoreCourses } from '@features/courses/services/courses'; @@ -122,7 +122,7 @@ export class AddonBlockTimelineComponent implements OnInit, ICoreBlockComponent * @inheritdoc */ async invalidateContent(): Promise { - await CoreUtils.allPromises([ + await CorePromiseUtils.allPromises([ AddonBlockTimeline.invalidateActionEventsByTimesort(), AddonBlockTimeline.invalidateActionEventsByCourses(), CoreCourses.invalidateUserCourses(), diff --git a/src/addons/blog/pages/edit-entry/edit-entry.ts b/src/addons/blog/pages/edit-entry/edit-entry.ts index 462df4610..3858ebdbe 100644 --- a/src/addons/blog/pages/edit-entry/edit-entry.ts +++ b/src/addons/blog/pages/edit-entry/edit-entry.ts @@ -47,6 +47,7 @@ import { CoreEvents } from '@singletons/events'; import { CoreForms } from '@singletons/form'; import { CoreFileEntry } from '@services/file-helper'; import { CoreTimeUtils } from '@services/utils/time'; +import { CorePromiseUtils } from '@singletons/promise-utils'; @Component({ selector: 'addon-blog-edit-entry', @@ -323,7 +324,7 @@ export default class AddonBlogEditEntryPage implements CanLeave, OnInit, OnDestr const filters: AddonBlogFilter | undefined = CoreNavigator.getRouteParam('filters'); const entry = this.entry && 'attachment' in this.entry ? this.entry - : await CoreUtils.ignoreErrors(this.getEntry({ filters, lastModified, entryId: this.entry.id })); + : await CorePromiseUtils.ignoreErrors(this.getEntry({ filters, lastModified, entryId: this.entry.id })); const removedFiles = CoreFileUploader.getFilesToDelete(entry?.attachmentfiles ?? [], this.files); diff --git a/src/addons/blog/pages/index/index.ts b/src/addons/blog/pages/index/index.ts index afd431245..64ef920d2 100644 --- a/src/addons/blog/pages/index/index.ts +++ b/src/addons/blog/pages/index/index.ts @@ -36,7 +36,7 @@ import { CoreNetwork } from '@services/network'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUrl } from '@singletons/url'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreArray } from '@singletons/array'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreTime } from '@singletons/time'; @@ -93,7 +93,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy { this.isOnline.set(CoreNetwork.isOnline()); this.logView = CoreTime.once(async () => { - await CoreUtils.ignoreErrors(AddonBlog.logView(this.filter)); + await CorePromiseUtils.ignoreErrors(AddonBlog.logView(this.filter)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM_LIST, @@ -113,7 +113,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy { this.entryUpdateObserver = CoreEvents.on(ADDON_BLOG_ENTRY_UPDATED, async () => { this.loaded.set(false); - await CoreUtils.ignoreErrors(this.refresh()); + await CorePromiseUtils.ignoreErrors(this.refresh()); this.loaded.set(true); }); @@ -123,7 +123,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy { } this.loaded.set(false); - await CoreUtils.ignoreErrors(this.refresh(false)); + await CorePromiseUtils.ignoreErrors(this.refresh(false)); this.loaded.set(true); }); @@ -375,7 +375,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy { * @param refresher Refresher instance. */ async refresh(sync = true, refresher?: HTMLIonRefresherElement): Promise { - const promises = this.entries.map((entry) => { + const promises = this.entries.map(async (entry) => { if (this.isOnlineEntry(entry)) { return CoreComments.invalidateCommentsData( ContextLevel.USER, @@ -399,7 +399,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy { } - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); await this.fetchEntries(true, false, sync); refresher?.complete(); } diff --git a/src/addons/blog/services/blog-offline.ts b/src/addons/blog/services/blog-offline.ts index 3dbcd168a..df964e28a 100644 --- a/src/addons/blog/services/blog-offline.ts +++ b/src/addons/blog/services/blog-offline.ts @@ -17,7 +17,7 @@ import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreFile } from '@services/file'; import { CoreFileEntry } from '@services/file-helper'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { CoreObject } from '@singletons/object'; import { CorePath } from '@singletons/path'; @@ -108,7 +108,7 @@ export class AddonBlogOfflineService { */ async getOfflineEntry(filter: { id?: number; created?: number }, siteId?: string): Promise { const site = await CoreSites.getSite(siteId); - const record = await CoreUtils.ignoreErrors( + const record = await CorePromiseUtils.ignoreErrors( site.getDb().getRecord(OFFLINE_BLOG_ENTRIES_TABLE_NAME, filter), ); diff --git a/src/addons/blog/services/blog.ts b/src/addons/blog/services/blog.ts index 75761cc9f..61e9db79c 100644 --- a/src/addons/blog/services/blog.ts +++ b/src/addons/blog/services/blog.ts @@ -26,6 +26,7 @@ import { CoreUtils } from '@services/utils/utils'; import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonBlogOffline, AddonBlogOfflineEntry } from './blog-offline'; +import { CorePromiseUtils } from '@singletons/promise-utils'; const ROOT_CACHE_KEY = 'addonBlog:'; @@ -229,7 +230,7 @@ export class AddonBlogProvider { } await this.deleteEntryOnline(params, siteId); - await CoreUtils.ignoreErrors(AddonBlogOffline.unmarkEntryAsRemoved(params.entryid)); + await CorePromiseUtils.ignoreErrors(AddonBlogOffline.unmarkEntryAsRemoved(params.entryid)); } catch (error) { if (!CoreUtils.isWebServiceError(error)) { // Couldn't connect to server, store in offline. @@ -311,7 +312,7 @@ export class AddonBlogProvider { const tags = options?.find(option => option.name === 'tags')?.value as string | undefined; const publishState = options?.find(option => option.name === 'publishstate')?.value as AddonBlogPublishState ?? AddonBlogPublishState.draft; - const user = await CoreUtils.ignoreErrors(CoreUser.getProfile(offlineEntry.userid, courseId, true)); + const user = await CorePromiseUtils.ignoreErrors(CoreUser.getProfile(offlineEntry.userid, courseId, true)); const folder = 'id' in offlineEntry && offlineEntry.id ? { id: offlineEntry.id } : { created: offlineEntry.created }; const offlineFiles = await AddonBlogOffline.getOfflineFiles(folder); const optionsFiles = this.getAttachmentFilesFromOptions(options); @@ -375,7 +376,7 @@ export class AddonBlogProvider { } entry.summary = CoreFileHelper.replacePluginfileUrls(entry.summary, entry.summaryfiles || []); - entry.user = await CoreUtils.ignoreErrors(CoreUser.getProfile(entry.userid, entry.courseid, true)); + entry.user = await CorePromiseUtils.ignoreErrors(CoreUser.getProfile(entry.userid, entry.courseid, true)); } /** diff --git a/src/addons/calendar/pages/edit-event/edit-event.ts b/src/addons/calendar/pages/edit-event/edit-event.ts index f3d02d4ce..c95fde316 100644 --- a/src/addons/calendar/pages/edit-event/edit-event.ts +++ b/src/addons/calendar/pages/edit-event/edit-event.ts @@ -53,6 +53,7 @@ import { ContextLevel } from '@/core/constants'; import { CorePopovers } from '@services/popovers'; import { CoreLoadings } from '@services/loadings'; import { REMINDERS_DISABLED, CoreRemindersUnits } from '@features/reminders/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays a form to create/edit an event. @@ -164,7 +165,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave { try { const [types, accessInfo] = await Promise.all([ AddonCalendar.getAllowedEventTypes(this.courseId), - CoreUtils.ignoreErrors(AddonCalendar.getAccessInformation(this.courseId), { + CorePromiseUtils.ignoreErrors(AddonCalendar.getAccessInformation(this.courseId), { canmanageentries: false, canmanageownentries: false, canmanagegroupentries: false, diff --git a/src/addons/calendar/pages/event/event.ts b/src/addons/calendar/pages/event/event.ts index 469e32a0a..5226f55af 100644 --- a/src/addons/calendar/pages/event/event.ts +++ b/src/addons/calendar/pages/event/event.ts @@ -31,7 +31,7 @@ import { CoreTimeUtils } from '@services/utils/time'; import { NgZone, Translate } from '@singletons'; import { Subscription } from 'rxjs'; import { CoreNavigator } from '@services/navigator'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router'; import { CoreConstants } from '@/core/constants'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; @@ -480,7 +480,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { } promises.push(AddonCalendar.invalidateTimeFormat()); - await CoreUtils.allPromisesIgnoringErrors(promises); + await CorePromiseUtils.allPromisesIgnoringErrors(promises); await this.fetchEvent(sync, showErrors); } diff --git a/src/addons/calendar/services/calendar-helper.ts b/src/addons/calendar/services/calendar-helper.ts index 3a22698cf..5299901e8 100644 --- a/src/addons/calendar/services/calendar-helper.ts +++ b/src/addons/calendar/services/calendar-helper.ts @@ -43,6 +43,7 @@ import { } from '../constants'; import { AddonCalendarSyncInvalidateEvent } from './calendar-sync'; import { REMINDERS_DISABLED, REMINDERS_DEFAULT_REMINDER_TIMEBEFORE } from '@features/reminders/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service that provides some features regarding lists of courses and categories. @@ -638,7 +639,7 @@ export class AddonCalendarHelperProvider { const repeatedEvents = await AddonCalendar.getLocalEventsByRepeatIdFromLocalDb(eventData.repeatid, site.id); - await CoreUtils.allPromises(repeatedEvents.map((event) => + await CorePromiseUtils.allPromises(repeatedEvents.map((event) => AddonCalendar.invalidateEvent(event.id))); return; @@ -659,7 +660,7 @@ export class AddonCalendarHelperProvider { })); try { - await CoreUtils.allPromisesIgnoringErrors(promises); + await CorePromiseUtils.allPromisesIgnoringErrors(promises); } finally { const treatedMonths = {}; const treatedDays = {}; @@ -727,7 +728,7 @@ export class AddonCalendarHelperProvider { } }); - await CoreUtils.allPromisesIgnoringErrors(finalPromises); + await CorePromiseUtils.allPromisesIgnoringErrors(finalPromises); } } diff --git a/src/addons/calendar/services/calendar-sync.ts b/src/addons/calendar/services/calendar-sync.ts index ebefd0bfa..e29ac63ce 100644 --- a/src/addons/calendar/services/calendar-sync.ts +++ b/src/addons/calendar/services/calendar-sync.ts @@ -35,6 +35,7 @@ import { ADDON_CALENDAR_MANUAL_SYNCED, ADDON_CALENDAR_SYNC_ID, } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync calendar. @@ -132,7 +133,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider 0) { if (!CoreNetwork.isOnline()) { @@ -142,7 +143,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider this.syncOfflineEvent(eventId, result, siteId)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); if (result.updated) { @@ -152,12 +153,12 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider { // Add default reminder if the event isn't stored already and doesn't have any reminder. - const eventExist = await CoreUtils.promiseWorks(this.getEventFromLocalDb(event.id, siteId)); + const eventExist = await CorePromiseUtils.promiseWorks(this.getEventFromLocalDb(event.id, siteId)); if (eventExist) { return; } @@ -1508,7 +1509,7 @@ export class AddonCalendarProvider { // Now save the reminders if any. if (options.reminders?.length) { - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( Promise.all(options.reminders.map((reminder) => this.addEventReminder(event, reminder.time, siteId))), ); @@ -1531,7 +1532,7 @@ export class AddonCalendarProvider { // Now save the reminders if any. if (options.reminders?.length) { - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( Promise.all(options.reminders.map((reminder) => this.addEventReminder(event, reminder.time, siteId))), ); @@ -1592,7 +1593,7 @@ export class AddonCalendarProvider { if (eventId < 0) { // Offline event has been sent. Change reminders instanceId if any. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreReminders.updateReminders( { instanceId: result.event.id }, { @@ -1606,7 +1607,7 @@ export class AddonCalendarProvider { if (formData.id === 0) { // Store the new event in local DB. - await CoreUtils.ignoreErrors(this.storeEventInLocalDb(result.event, { addDefaultReminder: false, siteId })); + await CorePromiseUtils.ignoreErrors(this.storeEventInLocalDb(result.event, { addDefaultReminder: false, siteId })); } return result.event; diff --git a/src/addons/calendar/services/database/calendar.ts b/src/addons/calendar/services/database/calendar.ts index 4614e1792..9eb62c605 100644 --- a/src/addons/calendar/services/database/calendar.ts +++ b/src/addons/calendar/services/database/calendar.ts @@ -18,7 +18,7 @@ import { REMINDERS_DISABLED } from '@features/reminders/constants'; import { CoreReminders } from '@features/reminders/services/reminders'; import { CoreConfig } from '@services/config'; import { CoreSiteSchema } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Database variables for AddonCalendarProvider service. @@ -199,7 +199,7 @@ const migrateDefaultTime = async (siteId: string, convertToSeconds = false): Pro const key = 'mmaCalendarDefaultNotifTime#' + siteId; try { let defaultTime = await CoreConfig.get(key); - await CoreUtils.ignoreErrors(CoreConfig.delete(key)); + await CorePromiseUtils.ignoreErrors(CoreConfig.delete(key)); if (defaultTime <= 0) { defaultTime = REMINDERS_DISABLED; diff --git a/src/addons/competency/classes/competency-course-competencies-source.ts b/src/addons/competency/classes/competency-course-competencies-source.ts index 363514900..58d8aa081 100644 --- a/src/addons/competency/classes/competency-course-competencies-source.ts +++ b/src/addons/competency/classes/competency-course-competencies-source.ts @@ -14,7 +14,7 @@ import { CoreRoutedItemsManagerSource } from '@classes/items-management/routed-items-manager-source'; import { CoreUserProfile } from '@features/user/services/user'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonCompetency, AddonCompetencyDataForCourseCompetenciesPageCompetency, @@ -70,7 +70,7 @@ export class AddonCompetencyCourseCompetenciesSource * Invalidate course cache. */ async invalidateCache(): Promise { - await CoreUtils.ignoreErrors(AddonCompetency.invalidateCourseCompetencies(this.COURSE_ID, this.USER_ID)); + await CorePromiseUtils.ignoreErrors(AddonCompetency.invalidateCourseCompetencies(this.COURSE_ID, this.USER_ID)); } /** diff --git a/src/addons/competency/classes/competency-plan-competencies-source.ts b/src/addons/competency/classes/competency-plan-competencies-source.ts index a674f4c1e..95396ba69 100644 --- a/src/addons/competency/classes/competency-plan-competencies-source.ts +++ b/src/addons/competency/classes/competency-plan-competencies-source.ts @@ -14,7 +14,7 @@ import { CoreRoutedItemsManagerSource } from '@classes/items-management/routed-items-manager-source'; import { CoreUserProfile } from '@features/user/services/user'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonCompetency, AddonCompetencyDataForPlanPageCompetency, @@ -60,7 +60,7 @@ export class AddonCompetencyPlanCompetenciesSource extends CoreRoutedItemsManage * Invalidate plan cache. */ async invalidateCache(): Promise { - await CoreUtils.ignoreErrors(AddonCompetency.invalidateLearningPlan(this.PLAN_ID)); + await CorePromiseUtils.ignoreErrors(AddonCompetency.invalidateLearningPlan(this.PLAN_ID)); } /** diff --git a/src/addons/competency/pages/competency/competency.page.ts b/src/addons/competency/pages/competency/competency.page.ts index cb94fde05..94e4c67d7 100644 --- a/src/addons/competency/pages/competency/competency.page.ts +++ b/src/addons/competency/pages/competency/competency.page.ts @@ -31,7 +31,7 @@ import { } from '@addons/competency/services/competency'; import { CoreNavigator } from '@services/navigator'; import { ContextLevel } from '@/core/constants'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ADDON_COMPETENCY_SUMMARY_PAGE } from '@addons/competency/constants'; import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; @@ -175,7 +175,7 @@ export class AddonCompetencyCompetencyPage implements OnInit, OnDestroy { async refreshCompetency(refresher: HTMLIonRefresherElement): Promise { const source = this.competencies.getSource(); - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( source instanceof AddonCompetencyPlanCompetenciesSource ? AddonCompetency.invalidateCompetencyInPlan(source.PLAN_ID, this.requireCompetencyId()) : AddonCompetency.invalidateCompetencyInCourse(source.COURSE_ID, this.requireCompetencyId(), source.USER_ID), @@ -287,7 +287,7 @@ export class AddonCompetencyCompetencyPage implements OnInit, OnDestroy { return; } - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( AddonCompetency.logCompetencyInPlanView(source.PLAN_ID, compId, this.planStatus, name, userId), ); @@ -316,7 +316,9 @@ export class AddonCompetencyCompetencyPage implements OnInit, OnDestroy { return; } - await CoreUtils.ignoreErrors(AddonCompetency.logCompetencyInCourseView(source.COURSE_ID, compId, name, source.USER_ID)); + await CorePromiseUtils.ignoreErrors( + AddonCompetency.logCompetencyInCourseView(source.COURSE_ID, compId, name, source.USER_ID), + ); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, diff --git a/src/addons/competency/pages/competencysummary/competencysummary.page.ts b/src/addons/competency/pages/competencysummary/competencysummary.page.ts index 8099d303f..62cdc5c5e 100644 --- a/src/addons/competency/pages/competencysummary/competencysummary.page.ts +++ b/src/addons/competency/pages/competencysummary/competencysummary.page.ts @@ -17,7 +17,7 @@ import { ContextLevel } from '@/core/constants'; import { AddonCompetencySummary, AddonCompetency } from '@addons/competency/services/competency'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ADDON_COMPETENCY_SUMMARY_PAGE } from '@addons/competency/constants'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; @@ -45,7 +45,7 @@ export class AddonCompetencyCompetencySummaryPage implements OnInit { return; } - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( AddonCompetency.logCompetencyView(this.competencyId, this.competency.competency.shortname), ); diff --git a/src/addons/competency/services/competency.ts b/src/addons/competency/services/competency.ts index 0bff1b4d8..3ec9cf87c 100644 --- a/src/addons/competency/services/competency.ts +++ b/src/addons/competency/services/competency.ts @@ -20,7 +20,7 @@ import { CoreCommentsArea } from '@features/comments/services/comments'; import { CoreCourseSummary } from '@features/course/services/course'; import { CoreUserSummary } from '@features/user/services/user'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; const ROOT_CACHE_KEY = 'mmaCompetency:'; @@ -189,7 +189,7 @@ export class AddonCompetencyProvider { return false; } - return CoreUtils.promiseWorks(this.getCourseCompetencies(courseId, undefined, siteId)); + return CorePromiseUtils.promiseWorks(this.getCourseCompetencies(courseId, undefined, siteId)); } /** diff --git a/src/addons/competency/services/handlers/push-click.ts b/src/addons/competency/services/handlers/push-click.ts index 438791a20..b834cf4c0 100644 --- a/src/addons/competency/services/handlers/push-click.ts +++ b/src/addons/competency/services/handlers/push-click.ts @@ -22,6 +22,7 @@ import { CoreUrl } from '@singletons/url'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { AddonCompetency } from '../competency'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler for competencies push notifications clicks. @@ -55,7 +56,7 @@ export class AddonCompetencyPushClickHandlerService implements CorePushNotificat // Open the learning plan. const planId = Number(contextUrlParams.id); - await CoreUtils.ignoreErrors(AddonCompetency.invalidateLearningPlan(planId, notification.site)); + await CorePromiseUtils.ignoreErrors(AddonCompetency.invalidateLearningPlan(planId, notification.site)); await CoreNavigator.navigateToSitePath(`${ADDON_COMPETENCY_LEARNING_PLANS_PAGE}/${planId}`, { siteId: notification.site, @@ -71,7 +72,9 @@ export class AddonCompetencyPushClickHandlerService implements CorePushNotificat const planId = Number(contextUrlParams.planid); const userId = Number(contextUrlParams.userid); - await CoreUtils.ignoreErrors(AddonCompetency.invalidateCompetencyInPlan(planId, competencyId, notification.site)); + await CorePromiseUtils.ignoreErrors( + AddonCompetency.invalidateCompetencyInPlan(planId, competencyId, notification.site), + ); if (courseId) { await CoreNavigator.navigateToSitePath( @@ -101,7 +104,7 @@ export class AddonCompetencyPushClickHandlerService implements CorePushNotificat // Open the list of plans. const userId = Number(contextUrlParams.userid); - await CoreUtils.ignoreErrors(AddonCompetency.invalidateLearningPlans(userId, notification.site)); + await CorePromiseUtils.ignoreErrors(AddonCompetency.invalidateLearningPlans(userId, notification.site)); await CoreNavigator.navigateToSitePath(ADDON_COMPETENCY_LEARNING_PLANS_PAGE, { params: { userId }, diff --git a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts index 0ad77d343..6d96b9607 100644 --- a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts +++ b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts @@ -19,7 +19,7 @@ import { CoreFilterFilter, CoreFilterFormatTextOptions } from '@features/filter/ import { CoreLang } from '@services/lang'; import { CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreEvents } from '@singletons/events'; import { CoreSite } from '@classes/sites/site'; import { makeSingleton } from '@singletons'; @@ -180,7 +180,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan // Make sure the element is in DOM, otherwise some equations don't work. // Automatically timeout the promise after a certain time, we don't want to wait forever. - await CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(CoreDom.waitToBeInDOM(container), 15000)); + await CorePromiseUtils.ignoreErrors(CorePromiseUtils.timeoutPromise(CoreDom.waitToBeInDOM(container), 15000)); await this.window.M!.filter_mathjaxloader!.typeset(container); } @@ -336,7 +336,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan } await CoreWait.wait(250); - await CoreUtils.ignoreErrors(this.waitForReady(retries + 1)); + await CorePromiseUtils.ignoreErrors(this.waitForReady(retries + 1)); } /** diff --git a/src/addons/messageoutput/airnotifier/pages/devices/devices.ts b/src/addons/messageoutput/airnotifier/pages/devices/devices.ts index 829d4f798..3850195ca 100644 --- a/src/addons/messageoutput/airnotifier/pages/devices/devices.ts +++ b/src/addons/messageoutput/airnotifier/pages/devices/devices.ts @@ -17,7 +17,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { CoreDomUtils } from '@services/utils/dom'; import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; import { AddonMessageOutputAirnotifier, AddonMessageOutputAirnotifierDevice } from '../../services/airnotifier'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays the list of devices. @@ -112,7 +112,7 @@ export class AddonMessageOutputAirnotifierDevicesPage implements OnInit, OnDestr * Fetch devices. The purpose is to store the updated data, it won't be reflected in the view. */ protected async updateDevices(): Promise { - await CoreUtils.ignoreErrors(AddonMessageOutputAirnotifier.invalidateUserDevices()); + await CorePromiseUtils.ignoreErrors(AddonMessageOutputAirnotifier.invalidateUserDevices()); await AddonMessageOutputAirnotifier.getUserDevices(); } @@ -124,7 +124,7 @@ export class AddonMessageOutputAirnotifierDevicesPage implements OnInit, OnDestr */ async refreshDevices(refresher: HTMLIonRefresherElement): Promise { try { - await CoreUtils.ignoreErrors(AddonMessageOutputAirnotifier.invalidateUserDevices()); + await CorePromiseUtils.ignoreErrors(AddonMessageOutputAirnotifier.invalidateUserDevices()); await this.fetchDevices(); } finally { diff --git a/src/addons/messages/pages/discussion/discussion.ts b/src/addons/messages/pages/discussion/discussion.ts index fdd9036a1..9da031d1b 100644 --- a/src/addons/messages/pages/discussion/discussion.ts +++ b/src/addons/messages/pages/discussion/discussion.ts @@ -29,7 +29,7 @@ import { AddonMessagesOffline, AddonMessagesOfflineMessagesDBRecordFormatted } f import { AddonMessagesSync } from '../../services/messages-sync'; import { CoreUser } from '@features/user/services/user'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreLogger } from '@singletons/logger'; import { CoreInfiniteLoadingComponent } from '@components/infinite-loading/infinite-loading'; import { Md5 } from 'ts-md5/dist/md5'; @@ -897,7 +897,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView } await CoreWait.wait(400); - await CoreUtils.ignoreErrors(this.waitForFetch()); + await CorePromiseUtils.ignoreErrors(this.waitForFetch()); } /** diff --git a/src/addons/messages/pages/discussions-35/discussions.ts b/src/addons/messages/pages/discussions-35/discussions.ts index e4a140d66..ad84ed038 100644 --- a/src/addons/messages/pages/discussions-35/discussions.ts +++ b/src/addons/messages/pages/discussions-35/discussions.ts @@ -33,6 +33,7 @@ import { CorePlatform } from '@services/platform'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreKeyboard } from '@singletons/keyboard'; import { ADDON_MESSAGES_NEW_MESSAGE_EVENT, ADDON_MESSAGES_READ_CHANGED_EVENT } from '@addons/messages/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays the list of discussions. @@ -170,7 +171,7 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy { promises.push(AddonMessages.invalidateUnreadConversationCounts(this.siteId)); } - await CoreUtils.allPromises(promises).finally(() => this.fetchData().finally(() => { + await CorePromiseUtils.allPromises(promises).finally(() => this.fetchData().finally(() => { if (refresher) { refresher?.complete(); } diff --git a/src/addons/messages/services/messages.ts b/src/addons/messages/services/messages.ts index a48c8e754..680a49ed8 100644 --- a/src/addons/messages/services/messages.ts +++ b/src/addons/messages/services/messages.ts @@ -52,6 +52,7 @@ import { AddonMessagesMessagePrivacy, AddonMessagesUpdateConversationAction, } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; declare module '@singletons/events' { @@ -240,7 +241,7 @@ export class AddonMessagesProvider { await site.write('core_message_confirm_contact_request', params); - await CoreUtils.allPromises([ + await CorePromiseUtils.allPromises([ this.invalidateAllMemberInfo(userId, site), this.invalidateContactsCache(site.id), this.invalidateUserContacts(site.id), @@ -305,7 +306,7 @@ export class AddonMessagesProvider { await site.write('core_message_decline_contact_request', params); - await CoreUtils.allPromises([ + await CorePromiseUtils.allPromises([ this.invalidateAllMemberInfo(userId, site), this.refreshContactRequestsCount(site.id), ]).finally(() => { @@ -1934,7 +1935,7 @@ export class AddonMessagesProvider { * @returns Promise resolved when done. */ protected async invalidateAllMemberInfo(userId: number, site: CoreSite): Promise { - await CoreUtils.allPromises([ + await CorePromiseUtils.allPromises([ this.invalidateMemberInfo(userId, site.id), this.invalidateUserContacts(site.id), this.invalidateBlockedContactsCache(site.id), @@ -1952,7 +1953,7 @@ export class AddonMessagesProvider { site.id, undefined, true, - ).then((conversation) => CoreUtils.allPromises([ + ).then((conversation) => CorePromiseUtils.allPromises([ this.invalidateConversation(conversation.id), this.invalidateConversationMembers(conversation.id, site.id), ])).catch(() => { @@ -2314,7 +2315,7 @@ export class AddonMessagesProvider { await site.write('core_message_delete_contacts', params, preSets); - return CoreUtils.allPromises([ + return CorePromiseUtils.allPromises([ this.invalidateUserContacts(site.id), this.invalidateAllMemberInfo(userId, site), this.invalidateContactsCache(site.id), diff --git a/src/addons/mod/assign/classes/submissions-source.ts b/src/addons/mod/assign/classes/submissions-source.ts index d630dbc32..aa7f320e1 100644 --- a/src/addons/mod/assign/classes/submissions-source.ts +++ b/src/addons/mod/assign/classes/submissions-source.ts @@ -16,7 +16,7 @@ import { Params } from '@angular/router'; import { CoreRoutedItemsManagerSource } from '@classes/items-management/routed-items-manager-source'; import { CoreGroupInfo, CoreGroups } from '@services/groups'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { CoreIonicColorNames } from '@singletons/colors'; import { CoreEvents } from '@singletons/events'; @@ -194,7 +194,7 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc const showSubmissions: AddonModAssignSubmissionForList[] = await Promise.all( submissions.map(async (submission: AddonModAssignSubmissionForList) => { const gradeData = - await CoreUtils.ignoreErrors(AddonModAssignOffline.getSubmissionGrade(assign.id, submission.userid)); + await CorePromiseUtils.ignoreErrors(AddonModAssignOffline.getSubmissionGrade(assign.id, submission.userid)); // Load offline grades. const notSynced = !!gradeData && submission.timemodified < gradeData.timemodified; diff --git a/src/addons/mod/assign/components/edit-feedback-modal/edit-feedback-modal.ts b/src/addons/mod/assign/components/edit-feedback-modal/edit-feedback-modal.ts index aafd35365..9f05e1b04 100644 --- a/src/addons/mod/assign/components/edit-feedback-modal/edit-feedback-modal.ts +++ b/src/addons/mod/assign/components/edit-feedback-modal/edit-feedback-modal.ts @@ -16,7 +16,7 @@ import { Component, Input, ViewChild, ElementRef } from '@angular/core'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreFormFields, CoreForms } from '@singletons/form'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ModalController, Translate } from '@singletons'; import { AddonModAssignAssign, AddonModAssignPlugin, AddonModAssignSubmission } from '../../services/assign'; import { AddonModAssignFeedbackDelegate } from '../../services/feedback-delegate'; @@ -88,7 +88,7 @@ export class AddonModAssignEditFeedbackModalComponent { * @returns Promise resolved with boolean: whether the data has changed. */ protected async hasDataChanged(): Promise { - const changed = await CoreUtils.ignoreErrors( + const changed = await CorePromiseUtils.ignoreErrors( AddonModAssignFeedbackDelegate.hasPluginDataChanged( this.assign, this.submission, diff --git a/src/addons/mod/assign/components/index/index.ts b/src/addons/mod/assign/components/index/index.ts index eb31d7487..0913fd8af 100644 --- a/src/addons/mod/assign/components/index/index.ts +++ b/src/addons/mod/assign/components/index/index.ts @@ -24,7 +24,7 @@ import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreTimeUtils } from '@services/utils/time'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreTime } from '@singletons/time'; @@ -182,7 +182,7 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo if (sync) { // Try to synchronize the assign. - await CoreUtils.ignoreErrors(this.syncActivity(showErrors)); + await CorePromiseUtils.ignoreErrors(this.syncActivity(showErrors)); } // Check if there's any offline data for this assign. @@ -250,18 +250,18 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo return; // Shouldn't happen. } - await CoreUtils.ignoreErrors(AddonModAssign.logView(this.assign.id)); + await CorePromiseUtils.ignoreErrors(AddonModAssign.logView(this.assign.id)); this.analyticsLogEvent('mod_assign_view_assign'); if (this.canViewAllSubmissions) { // User can see all submissions, log grading view. - await CoreUtils.ignoreErrors(AddonModAssign.logGradingView(this.assign.id)); + await CorePromiseUtils.ignoreErrors(AddonModAssign.logGradingView(this.assign.id)); this.analyticsLogEvent('mod_assign_view_grading_table', { sendUrl: false }); } else if (this.canViewOwnSubmission) { // User can only see their own submission, log view the user submission. - await CoreUtils.ignoreErrors(AddonModAssign.logSubmissionView(this.assign.id)); + await CorePromiseUtils.ignoreErrors(AddonModAssign.logSubmissionView(this.assign.id)); this.analyticsLogEvent('mod_assign_view_submission_status', { sendUrl: false }); } diff --git a/src/addons/mod/assign/components/submission/submission.ts b/src/addons/mod/assign/components/submission/submission.ts index c918cb08c..17283e4bd 100644 --- a/src/addons/mod/assign/components/submission/submission.ts +++ b/src/addons/mod/assign/components/submission/submission.ts @@ -70,6 +70,7 @@ import { } from '../../constants'; import { CoreViewer } from '@features/viewer/services/viewer'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component that displays an assignment submission. @@ -327,7 +328,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can const previousSubmission = this.previousAttempt.submission; let modal = await CoreLoadings.show(); - const size = await CoreUtils.ignoreErrors( + const size = await CorePromiseUtils.ignoreErrors( AddonModAssignHelper.getSubmissionSizeForCopy(this.assign, previousSubmission), -1, ); // Error calculating size, return -1. @@ -548,7 +549,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can }); } - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); await this.loadData(sync); } @@ -716,7 +717,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can // If we have data about the grader, get its profile. if (feedback.grade && feedback.grade.grader > 0) { - this.grader = await CoreUtils.ignoreErrors(CoreUser.getProfile(feedback.grade.grader, this.courseId)); + this.grader = await CorePromiseUtils.ignoreErrors(CoreUser.getProfile(feedback.grade.grader, this.courseId)); } else { delete this.grader; } @@ -803,7 +804,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can // Submission grades aren't identified by attempt number so it can retrieve the feedback for a previous attempt. // The app will not treat that as an special case. - const submissionGrade = await CoreUtils.ignoreErrors( + const submissionGrade = await CorePromiseUtils.ignoreErrors( AddonModAssignOffline.getSubmissionGrade(assign.id, this.submitId), ); @@ -1075,7 +1076,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can const [gradebookGrades, assignGrades] = await Promise.all([ CoreGradesHelper.getGradeModuleItems(this.courseId, this.moduleId, this.submitId), gradeNotReleased ? - CoreUtils.ignoreErrors(AddonModAssign.getAssignmentGrades(assign.id, { cmId: assign.cmid })) : + CorePromiseUtils.ignoreErrors(AddonModAssign.getAssignmentGrades(assign.id, { cmId: assign.cmid })) : undefined, ]); diff --git a/src/addons/mod/assign/feedback/comments/component/comments.ts b/src/addons/mod/assign/feedback/comments/component/comments.ts index 0513d89ef..686166d7a 100644 --- a/src/addons/mod/assign/feedback/comments/component/comments.ts +++ b/src/addons/mod/assign/feedback/comments/component/comments.ts @@ -23,7 +23,7 @@ import { } from '../services/handler'; import { AddonModAssignFeedbackDelegate } from '@addons/mod/assign/services/feedback-delegate'; import { AddonModAssignOffline } from '@addons/mod/assign/services/assign-offline'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModAssignFeedbackPluginBaseComponent } from '@addons/mod/assign/classes/base-feedback-plugin-component'; import { ContextLevel } from '@/core/constants'; import { ADDON_MOD_ASSIGN_COMPONENT } from '@addons/mod/assign/constants'; @@ -124,7 +124,7 @@ export class AddonModAssignFeedbackCommentsComponent extends AddonModAssignFeedb } // There is no draft saved. Check if we have anything offline. - const offlineData = await CoreUtils.ignoreErrors( + const offlineData = await CorePromiseUtils.ignoreErrors( AddonModAssignOffline.getSubmissionGrade(this.assign.id, this.userId), undefined, ); diff --git a/src/addons/mod/assign/feedback/comments/services/handler.ts b/src/addons/mod/assign/feedback/comments/services/handler.ts index 692fff657..0ccb29a4f 100644 --- a/src/addons/mod/assign/feedback/comments/services/handler.ts +++ b/src/addons/mod/assign/feedback/comments/services/handler.ts @@ -25,7 +25,7 @@ import { AddonModAssignFeedbackHandler } from '@addons/mod/assign/services/feedb import { Injectable, Type } from '@angular/core'; import { CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { CoreFileHelper } from '@services/file-helper'; @@ -125,7 +125,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss userId: number, ): Promise { // Get it from plugin or offline. - const offlineData = await CoreUtils.ignoreErrors( + const offlineData = await CorePromiseUtils.ignoreErrors( AddonModAssignOffline.getSubmissionGrade(assign.id, userId), undefined, ); diff --git a/src/addons/mod/assign/pages/edit/edit.ts b/src/addons/mod/assign/pages/edit/edit.ts index 910112882..14526008a 100644 --- a/src/addons/mod/assign/pages/edit/edit.ts +++ b/src/addons/mod/assign/pages/edit/edit.ts @@ -47,6 +47,7 @@ import { } from '../../constants'; import { CoreToasts, ToastDuration } from '@services/toasts'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that allows adding or editing an assigment submission. @@ -232,7 +233,7 @@ export class AddonModAssignEditPage implements OnInit, OnDestroy, CanLeave { } // Check if there's any offline data for this submission. - this.hasOffline = await CoreUtils.promiseWorks(AddonModAssignOffline.getSubmission(this.assign.id, this.userId)); + this.hasOffline = await CorePromiseUtils.promiseWorks(AddonModAssignOffline.getSubmission(this.assign.id, this.userId)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, diff --git a/src/addons/mod/assign/services/assign-helper.ts b/src/addons/mod/assign/services/assign-helper.ts index a816ecab6..296611d17 100644 --- a/src/addons/mod/assign/services/assign-helper.ts +++ b/src/addons/mod/assign/services/assign-helper.ts @@ -37,6 +37,7 @@ import { makeSingleton } from '@singletons'; import { CoreFormFields } from '@singletons/form'; import { CoreFileEntry } from '@services/file-helper'; import { ADDON_MOD_ASSIGN_COMPONENT } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service that provides some helper functions for assign. @@ -81,7 +82,7 @@ export class AddonModAssignHelperProvider { return true; } - if (await CoreUtils.promiseWorks(AddonModAssignOffline.getSubmission(assign.id, submission.userid))) { + if (await CorePromiseUtils.promiseWorks(AddonModAssignOffline.getSubmission(assign.id, submission.userid))) { // Submission was saved or deleted offline, allow editing it or creating a new one. return true; } @@ -530,7 +531,7 @@ export class AddonModAssignHelperProvider { const promises = feedback.plugins.map((plugin) => this.prepareFeedbackPluginData(assign.id, userId, feedback).then(async (inputData) => { - const changed = await CoreUtils.ignoreErrors( + const changed = await CorePromiseUtils.ignoreErrors( AddonModAssignFeedbackDelegate.hasPluginDataChanged(assign, submission, plugin, inputData, userId), false, ); @@ -541,7 +542,7 @@ export class AddonModAssignHelperProvider { return; })); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); return hasChanged; } @@ -579,7 +580,7 @@ export class AddonModAssignHelperProvider { })) : []; - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); return hasChanged; } diff --git a/src/addons/mod/assign/services/assign-sync.ts b/src/addons/mod/assign/services/assign-sync.ts index 22b3c7c47..602d673f9 100644 --- a/src/addons/mod/assign/services/assign-sync.ts +++ b/src/addons/mod/assign/services/assign-sync.ts @@ -40,6 +40,7 @@ import { CoreGradesFormattedItem, CoreGradesHelper } from '@features/grades/serv import { AddonModAssignSubmissionDelegate } from './submission-delegate'; import { AddonModAssignFeedbackDelegate } from './feedback-delegate'; import { ADDON_MOD_ASSIGN_AUTO_SYNCED, ADDON_MOD_ASSIGN_COMPONENT, ADDON_MOD_ASSIGN_MANUAL_SYNCED } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync assigns. @@ -189,7 +190,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid */ protected async performSyncAssign(assignId: number, siteId: string): Promise { // Sync offline logs. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreCourseLogHelper.syncActivity(ADDON_MOD_ASSIGN_COMPONENT, assignId, siteId), ); @@ -207,7 +208,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid if (!submissions.length && !grades.length) { // Nothing to sync. - await CoreUtils.ignoreErrors(this.setSyncTime(assignId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(assignId, siteId)); return result; } @@ -246,15 +247,15 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid } })); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); if (result.updated) { // Data has been sent to server. Now invalidate the WS calls. - await CoreUtils.ignoreErrors(AddonModAssign.invalidateContent(assign.cmid, courseId, siteId)); + await CorePromiseUtils.ignoreErrors(AddonModAssign.invalidateContent(assign.cmid, courseId, siteId)); } // Sync finished, set sync time. - await CoreUtils.ignoreErrors(this.setSyncTime(assignId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(assignId, siteId)); // All done, return the result. return result; @@ -272,7 +273,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid siteId: string, ): Promise { // If no offline data found, return empty array. - return CoreUtils.ignoreErrors(AddonModAssignOffline.getAssignSubmissionsGrade(assignId, siteId), []); + return CorePromiseUtils.ignoreErrors(AddonModAssignOffline.getAssignSubmissionsGrade(assignId, siteId), []); } /** @@ -287,7 +288,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid siteId: string, ): Promise { // If no offline data found, return empty array. - return CoreUtils.ignoreErrors(AddonModAssignOffline.getAssignSubmissions(assignId, siteId), []); + return CorePromiseUtils.ignoreErrors(AddonModAssignOffline.getAssignSubmissions(assignId, siteId), []); } /** @@ -508,7 +509,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid // Update cached data. promises.push(AddonModAssign.getSubmissionStatus(assign.id, options)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } catch (error) { if (!error || !CoreUtils.isWebServiceError(error)) { // Local error, reject. diff --git a/src/addons/mod/assign/services/handlers/prefetch.ts b/src/addons/mod/assign/services/handlers/prefetch.ts index bede2324a..63817e54b 100644 --- a/src/addons/mod/assign/services/handlers/prefetch.ts +++ b/src/addons/mod/assign/services/handlers/prefetch.ts @@ -27,7 +27,7 @@ import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/ import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreWSFile } from '@services/ws'; import { AddonModAssignHelper, AddonModAssignSubmissionFormatted } from '../assign-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreFilepool } from '@services/filepool'; import { CoreGroups } from '@services/groups'; import { AddonModAssignSync, AddonModAssignSyncResult } from '../assign-sync'; @@ -252,7 +252,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref if (blindMarking) { promises.push( - CoreUtils.ignoreErrors(AddonModAssign.getAssignmentUserMappings(assign.id, -1, modOptions)), + CorePromiseUtils.ignoreErrors(AddonModAssign.getAssignmentUserMappings(assign.id, -1, modOptions)), ); } @@ -260,7 +260,7 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref promises.push(CoreCourse.getModuleBasicInfoByInstance(assign.id, 'assign', { siteId })); // Get course data, needed to determine upload max size if it's configured to be course limit. - promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + promises.push(CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); // Download intro files and attachments. Do not call getFiles because it'd call some WS twice. let files: CoreWSFile[] = assign.introattachments || []; diff --git a/src/addons/mod/assign/services/handlers/push-click.ts b/src/addons/mod/assign/services/handlers/push-click.ts index 9388eb4d2..56a568495 100644 --- a/src/addons/mod/assign/services/handlers/push-click.ts +++ b/src/addons/mod/assign/services/handlers/push-click.ts @@ -21,6 +21,7 @@ import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { AddonModAssign } from '../assign'; import { ADDON_MOD_ASSIGN_FEATURE_NAME } from '../../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler for assign push notifications clicks. @@ -54,7 +55,7 @@ export class AddonModAssignPushClickHandlerService implements CorePushNotificati const courseId = Number(notification.courseid); const moduleId = Number(contextUrlParams.id); - await CoreUtils.ignoreErrors(AddonModAssign.invalidateContent(moduleId, courseId, notification.site)); + await CorePromiseUtils.ignoreErrors(AddonModAssign.invalidateContent(moduleId, courseId, notification.site)); await CoreCourseHelper.navigateToModule(moduleId, { courseId, siteId: notification.site, diff --git a/src/addons/mod/assign/submission/file/component/file.ts b/src/addons/mod/assign/submission/file/component/file.ts index e142c842f..a3e9becfd 100644 --- a/src/addons/mod/assign/submission/file/component/file.ts +++ b/src/addons/mod/assign/submission/file/component/file.ts @@ -18,7 +18,7 @@ import { AddonModAssignOffline } from '@addons/mod/assign/services/assign-offlin import { Component, OnInit } from '@angular/core'; import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreFileSession } from '@services/file-session'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModAssignSubmissionFileHandlerService } from '../services/handler'; import { FileEntry } from '@awesome-cordova-plugins/file/ngx'; import { AddonModAssignSubmissionPluginBaseComponent } from '@addons/mod/assign/classes/base-submission-plugin-component'; @@ -54,7 +54,7 @@ export class AddonModAssignSubmissionFileComponent extends AddonModAssignSubmiss : undefined; // Get the offline data. - const offlineData = await CoreUtils.ignoreErrors( + const offlineData = await CorePromiseUtils.ignoreErrors( AddonModAssignOffline.getSubmission(this.assign.id), undefined, ); @@ -67,7 +67,7 @@ export class AddonModAssignSubmissionFileComponent extends AddonModAssignSubmiss // It has offline data. let offlineFiles: FileEntry[] = []; if (offlineDataFiles.offline) { - offlineFiles = await CoreUtils.ignoreErrors( + offlineFiles = await CorePromiseUtils.ignoreErrors( AddonModAssignHelper.getStoredSubmissionFiles( this.assign.id, AddonModAssignSubmissionFileHandlerService.FOLDER_NAME, diff --git a/src/addons/mod/assign/submission/file/services/handler.ts b/src/addons/mod/assign/submission/file/services/handler.ts index 4039426ab..ae771cf8d 100644 --- a/src/addons/mod/assign/submission/file/services/handler.ts +++ b/src/addons/mod/assign/submission/file/services/handler.ts @@ -31,6 +31,7 @@ import { makeSingleton } from '@singletons'; import { FileEntry } from '@awesome-cordova-plugins/file/ngx'; import type { AddonModAssignSubmissionPluginBaseComponent } from '@addons/mod/assign/classes/base-submission-plugin-component'; import { ADDON_MOD_ASSIGN_COMPONENT } from '@addons/mod/assign/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler for file submission plugin. @@ -117,7 +118,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig siteId?: string, ): Promise { - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( AddonModAssignHelper.deleteStoredSubmissionFiles( assign.id, AddonModAssignSubmissionFileHandlerService.FOLDER_NAME, @@ -175,7 +176,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig submission: AddonModAssignSubmission, plugin: AddonModAssignPlugin, ): Promise { - const offlineData = await CoreUtils.ignoreErrors( + const offlineData = await CorePromiseUtils.ignoreErrors( // Check if there's any offline data. AddonModAssignOffline.getSubmission(assign.id, submission.userid), undefined, @@ -303,7 +304,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig if (filesData.offline) { // Has offline files, get them and add them to the list. - const storedFiles = await CoreUtils.ignoreErrors( + const storedFiles = await CorePromiseUtils.ignoreErrors( AddonModAssignHelper.getStoredSubmissionFiles( assign.id, AddonModAssignSubmissionFileHandlerService.FOLDER_NAME, diff --git a/src/addons/mod/assign/submission/onlinetext/component/onlinetext.ts b/src/addons/mod/assign/submission/onlinetext/component/onlinetext.ts index 04447b4d3..de3766f1d 100644 --- a/src/addons/mod/assign/submission/onlinetext/component/onlinetext.ts +++ b/src/addons/mod/assign/submission/onlinetext/component/onlinetext.ts @@ -19,7 +19,7 @@ import { Component, OnInit, ElementRef } from '@angular/core'; import { FormBuilder, FormControl } from '@angular/forms'; import { CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModAssignSubmissionOnlineTextPluginData } from '../services/handler'; import { ContextLevel } from '@/core/constants'; import { ADDON_MOD_ASSIGN_COMPONENT } from '@addons/mod/assign/constants'; @@ -60,7 +60,7 @@ export class AddonModAssignSubmissionOnlineTextComponent extends AddonModAssignS */ async ngOnInit(): Promise { // Get the text. Check if we have anything offline. - const offlineData = await CoreUtils.ignoreErrors( + const offlineData = await CorePromiseUtils.ignoreErrors( AddonModAssignOffline.getSubmission(this.assign.id), undefined, ); diff --git a/src/addons/mod/assign/submission/onlinetext/services/handler.ts b/src/addons/mod/assign/submission/onlinetext/services/handler.ts index c6f55a8de..22e262032 100644 --- a/src/addons/mod/assign/submission/onlinetext/services/handler.ts +++ b/src/addons/mod/assign/submission/onlinetext/services/handler.ts @@ -26,7 +26,7 @@ import { Injectable, Type } from '@angular/core'; import { CoreError } from '@classes/errors/error'; import { CoreFileHelper } from '@services/file-helper'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; @@ -178,7 +178,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo // Get the original text from plugin or offline. const offlineData = - await CoreUtils.ignoreErrors(AddonModAssignOffline.getSubmission(assign.id, submission.userid)); + await CorePromiseUtils.ignoreErrors(AddonModAssignOffline.getSubmission(assign.id, submission.userid)); let initialText = ''; if (offlineData && offlineData.plugindata && offlineData.plugindata.onlinetext_editor) { diff --git a/src/addons/mod/bigbluebuttonbn/components/index/index.ts b/src/addons/mod/bigbluebuttonbn/components/index/index.ts index faeb11b60..461617dd4 100644 --- a/src/addons/mod/bigbluebuttonbn/components/index/index.ts +++ b/src/addons/mod/bigbluebuttonbn/components/index/index.ts @@ -34,6 +34,7 @@ import { import { ADDON_MOD_BBB_COMPONENT } from '../../constants'; import { CoreLoadings } from '@services/loadings'; import { convertTextToHTMLElement } from '@/core/utils/create-html-element'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component that displays a Big Blue Button activity. @@ -228,7 +229,7 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo return; // Shouldn't happen. } - await CoreUtils.ignoreErrors(AddonModBBB.logView(this.bbb.id)); + await CorePromiseUtils.ignoreErrors(AddonModBBB.logView(this.bbb.id)); this.analyticsLogEvent('mod_bigbluebuttonbn_view_bigbluebuttonbn'); } diff --git a/src/addons/mod/book/components/index/index.ts b/src/addons/mod/book/components/index/index.ts index 1a03cb0db..ed9b5f425 100644 --- a/src/addons/mod/book/components/index/index.ts +++ b/src/addons/mod/book/components/index/index.ts @@ -18,7 +18,7 @@ import { AddonModBook, AddonModBookBookWSData, AddonModBookTocChapter } from '.. import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { CoreCourse } from '@features/course/services/course'; import { CoreNavigator } from '@services/navigator'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ADDON_MOD_BOOK_PAGE_NAME, AddonModBookNumbering } from '../../constants'; /** @@ -104,7 +104,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp * @inheritdoc */ protected async logActivity(): Promise { - await CoreUtils.ignoreErrors(AddonModBook.logView(this.module.instance)); + await CorePromiseUtils.ignoreErrors(AddonModBook.logView(this.module.instance)); this.analyticsLogEvent('mod_book_view_book'); } diff --git a/src/addons/mod/book/pages/contents/contents.ts b/src/addons/mod/book/pages/contents/contents.ts index 2ce0ca58e..b9c72d556 100644 --- a/src/addons/mod/book/pages/contents/contents.ts +++ b/src/addons/mod/book/pages/contents/contents.ts @@ -26,7 +26,7 @@ import { CoreNetwork } from '@services/network'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreErrorHelper } from '@services/error-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { AddonModBook, @@ -163,13 +163,13 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy { */ async doRefresh(refresher?: HTMLIonRefresherElement): Promise { if (this.manager) { - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ this.manager.getSource().invalidateContent(), CoreCourseModulePrefetchDelegate.invalidateCourseUpdates(this.courseId), // To detect if book was updated. ])); } - await CoreUtils.ignoreErrors(this.fetchContent(true)); + await CorePromiseUtils.ignoreErrors(this.fetchContent(true)); refresher?.complete(); } @@ -219,7 +219,7 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy { } // Chapter loaded, log view. - await CoreUtils.ignoreErrors(AddonModBook.logView(this.module.instance, chapterId)); + await CorePromiseUtils.ignoreErrors(AddonModBook.logView(this.module.instance, chapterId)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, diff --git a/src/addons/mod/book/services/book.ts b/src/addons/mod/book/services/book.ts index 51597fcc7..e6765d299 100644 --- a/src/addons/mod/book/services/book.ts +++ b/src/addons/mod/book/services/book.ts @@ -19,7 +19,7 @@ import { CoreWSExternalWarning, CoreWSExternalFile, CoreWS } from '@services/ws' import { makeSingleton, Translate } from '@singletons'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourse, CoreCourseModuleContentFile } from '@features/course/services/course'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreFilepool } from '@services/filepool'; import { CoreText } from '@singletons/text'; import { CoreDomUtils } from '@services/utils/dom'; @@ -311,7 +311,7 @@ export class AddonModBookProvider { promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_BOOK_COMPONENT, moduleId)); promises.push(CoreCourse.invalidateModule(moduleId, siteId)); - return CoreUtils.allPromises(promises); + return CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/book/services/handlers/prefetch.ts b/src/addons/mod/book/services/handlers/prefetch.ts index 640a69e40..aebf2a92f 100644 --- a/src/addons/mod/book/services/handlers/prefetch.ts +++ b/src/addons/mod/book/services/handlers/prefetch.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler'; import { CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourseModuleData } from '@features/course/services/course-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModBook } from '../book'; @@ -46,7 +46,7 @@ export class AddonModBookPrefetchHandlerService extends CoreCourseResourcePrefet promises.push(super.downloadOrPrefetch(module, courseId, prefetch)); // Ignore errors since this WS isn't available in some Moodle versions. - promises.push(CoreUtils.ignoreErrors(AddonModBook.getBook(courseId, module.id))); + promises.push(CorePromiseUtils.ignoreErrors(AddonModBook.getBook(courseId, module.id))); await Promise.all(promises); } @@ -58,7 +58,7 @@ export class AddonModBookPrefetchHandlerService extends CoreCourseResourcePrefet * @returns Promise resolved with list of intro files. */ async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { - const book = await CoreUtils.ignoreErrors(AddonModBook.getBook(courseId, module.id)); + const book = await CorePromiseUtils.ignoreErrors(AddonModBook.getBook(courseId, module.id)); return this.getIntroFilesFromInstance(module, book); } diff --git a/src/addons/mod/chat/classes/chat-sessions-source.ts b/src/addons/mod/chat/classes/chat-sessions-source.ts index 30c59c06c..1308b3b3e 100644 --- a/src/addons/mod/chat/classes/chat-sessions-source.ts +++ b/src/addons/mod/chat/classes/chat-sessions-source.ts @@ -16,7 +16,7 @@ import { Params } from '@angular/router'; import { CoreRoutedItemsManagerSource } from '@classes/items-management/routed-items-manager-source'; import { CoreUser } from '@features/user/services/user'; import { CoreGroupInfo, CoreGroups } from '@services/groups'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { AddonModChat, AddonModChatSession, AddonModChatSessionUser } from '../services/chat'; @@ -45,10 +45,10 @@ export class AddonModChatSessionsSource extends CoreRoutedItemsManagerSource { - await CoreUtils.ignoreErrors(CoreUtils.allPromises([ + await CorePromiseUtils.allPromisesIgnoringErrors([ CoreGroups.invalidateActivityGroupInfo(this.CM_ID), AddonModChat.invalidateSessions(this.CHAT_ID, this.groupId, this.showAll), - ])); + ]); } /** diff --git a/src/addons/mod/chat/pages/chat/chat.ts b/src/addons/mod/chat/pages/chat/chat.ts index 482c04526..81fb81cb7 100644 --- a/src/addons/mod/chat/pages/chat/chat.ts +++ b/src/addons/mod/chat/pages/chat/chat.ts @@ -20,7 +20,7 @@ import { CoreNetwork } from '@services/network'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { NgZone, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { Subscription } from 'rxjs'; @@ -258,7 +258,7 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave { // Start polling. this.polling = window.setInterval(() => { - CoreUtils.ignoreErrors(this.fetchMessagesInterval()); + CorePromiseUtils.ignoreErrors(this.fetchMessagesInterval()); }, AddonModChatChatPage.POLL_INTERVAL); } @@ -324,7 +324,7 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave { await AddonModChat.sendMessage(this.sessionId!, text, beep); // Update messages to show the sent message. - CoreUtils.ignoreErrors(this.fetchMessagesInterval()); + CorePromiseUtils.ignoreErrors(this.fetchMessagesInterval()); } catch (error) { // Only close the keyboard if an error happens, we want the user to be able to send multiple // messages without the keyboard being closed. diff --git a/src/addons/mod/chat/pages/session-messages/session-messages.ts b/src/addons/mod/chat/pages/session-messages/session-messages.ts index 682bb738e..d26238d12 100644 --- a/src/addons/mod/chat/pages/session-messages/session-messages.ts +++ b/src/addons/mod/chat/pages/session-messages/session-messages.ts @@ -17,7 +17,7 @@ import { CoreUser } from '@features/user/services/user'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModChat } from '../../services/chat'; import { AddonModChatFormattedSessionMessage, AddonModChatHelper } from '../../services/chat-helper'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; @@ -48,7 +48,7 @@ export class AddonModChatSessionMessagesPage implements OnInit { constructor() { this.logView = CoreTime.once(async () => { - await CoreUtils.ignoreErrors(AddonModChat.logViewSessions(this.cmId, { + await CorePromiseUtils.ignoreErrors(AddonModChat.logViewSessions(this.cmId, { start: this.sessionStart, end: this.sessionEnd, })); @@ -159,7 +159,9 @@ export class AddonModChatSessionMessagesPage implements OnInit { */ async refreshMessages(refresher: HTMLIonRefresherElement): Promise { try { - await CoreUtils.ignoreErrors(AddonModChat.invalidateSessionMessages(this.chatId, this.sessionStart, this.groupId)); + await CorePromiseUtils.ignoreErrors( + AddonModChat.invalidateSessionMessages(this.chatId, this.sessionStart, this.groupId), + ); await this.fetchMessages(); } finally { diff --git a/src/addons/mod/chat/pages/sessions/sessions.ts b/src/addons/mod/chat/pages/sessions/sessions.ts index 852504dc9..517ae447e 100644 --- a/src/addons/mod/chat/pages/sessions/sessions.ts +++ b/src/addons/mod/chat/pages/sessions/sessions.ts @@ -24,7 +24,7 @@ import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreTime } from '@singletons/time'; import { Translate } from '@singletons'; import { AddonModChat } from '@addons/mod/chat/services/chat'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreLoadings } from '@services/loadings'; /** @@ -46,7 +46,7 @@ export class AddonModChatSessionsPage implements OnInit, AfterViewInit, OnDestro this.logView = CoreTime.once(async () => { const source = this.sessions.getSource(); - await CoreUtils.ignoreErrors(AddonModChat.logViewSessions(this.sessions.getSource().CM_ID)); + await CorePromiseUtils.ignoreErrors(AddonModChat.logViewSessions(this.sessions.getSource().CM_ID)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM_LIST, diff --git a/src/addons/mod/chat/services/handlers/prefetch-lazy.ts b/src/addons/mod/chat/services/handlers/prefetch-lazy.ts index 1f92df135..858008618 100644 --- a/src/addons/mod/chat/services/handlers/prefetch-lazy.ts +++ b/src/addons/mod/chat/services/handlers/prefetch-lazy.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { AddonModChatPrefetchHandlerService } from './prefetch'; import { AddonModChat, AddonModChatSession } from '../chat'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreSitesReadingStrategy } from '@services/sites'; import { CoreGroups } from '@services/groups'; @@ -34,7 +34,7 @@ export class AddonModChatPrefetchHandlerLazyService extends AddonModChatPrefetch async invalidateContent(moduleId: number, courseId: number): Promise { const chat = await AddonModChat.getChat(courseId, moduleId); - await CoreUtils.allPromises([ + await CorePromiseUtils.allPromises([ AddonModChat.invalidateAllSessions(chat.id), AddonModChat.invalidateAllSessionMessages(chat.id), ]); @@ -44,7 +44,7 @@ export class AddonModChatPrefetchHandlerLazyService extends AddonModChatPrefetch * @inheritdoc */ async invalidateModule(module: CoreCourseAnyModuleData, courseId: number): Promise { - await CoreUtils.allPromises([ + await CorePromiseUtils.allPromises([ AddonModChat.invalidateChats(courseId), CoreCourse.invalidateModule(module.id), ]); diff --git a/src/addons/mod/choice/services/choice-sync.ts b/src/addons/mod/choice/services/choice-sync.ts index 3d2f7b7d9..94e5ab90e 100644 --- a/src/addons/mod/choice/services/choice-sync.ts +++ b/src/addons/mod/choice/services/choice-sync.ts @@ -27,6 +27,7 @@ import { AddonModChoice } from './choice'; import { AddonModChoiceOffline } from './choice-offline'; import { AddonModChoicePrefetchHandler } from './handlers/prefetch'; import { ADDON_MOD_CHOICE_AUTO_SYNCED, ADDON_MOD_CHOICE_COMPONENT } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; declare module '@singletons/events' { @@ -162,9 +163,9 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid }; // Sync offline logs. - await CoreUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_CHOICE_COMPONENT, choiceId, siteId)); + await CorePromiseUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_CHOICE_COMPONENT, choiceId, siteId)); - const data = await CoreUtils.ignoreErrors(AddonModChoiceOffline.getResponse(choiceId, siteId, userId)); + const data = await CorePromiseUtils.ignoreErrors(AddonModChoiceOffline.getResponse(choiceId, siteId, userId)); if (!data || !data.choiceid) { // Nothing to sync. Set sync time. diff --git a/src/addons/mod/choice/services/choice.ts b/src/addons/mod/choice/services/choice.ts index 489858904..3c31c625a 100644 --- a/src/addons/mod/choice/services/choice.ts +++ b/src/addons/mod/choice/services/choice.ts @@ -27,6 +27,7 @@ import { AddonModChoiceOffline } from './choice-offline'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { ADDON_MOD_CHOICE_COMPONENT, AddonModChoiceShowResults } from '../constants'; import { CoreCacheUpdateFrequency } from '@/core/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service that provides some features for choices. @@ -158,7 +159,7 @@ export class AddonModChoiceProvider { } // Invalidate related data. - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ this.invalidateOptions(choiceId, site.id), this.invalidateResults(choiceId, site.id), ])); @@ -462,7 +463,7 @@ export class AddonModChoiceProvider { await site.write('mod_choice_submit_choice_response', params); // Invalidate related data. - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ this.invalidateOptions(choiceId, siteId), this.invalidateResults(choiceId, siteId), ])); diff --git a/src/addons/mod/choice/services/handlers/prefetch.ts b/src/addons/mod/choice/services/handlers/prefetch.ts index 2bb83c85b..9eed10b86 100644 --- a/src/addons/mod/choice/services/handlers/prefetch.ts +++ b/src/addons/mod/choice/services/handlers/prefetch.ts @@ -18,7 +18,7 @@ import { CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features import { CoreUser } from '@features/user/services/user'; import { CoreFilepool } from '@services/filepool'; import { CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModChoice } from '../choice'; @@ -117,7 +117,7 @@ export class AddonModChoicePrefetchHandlerService extends CoreCourseActivityPref * @inheritdoc */ async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { - const choice = await CoreUtils.ignoreErrors(AddonModChoice.getChoice(courseId, module.id)); + const choice = await CorePromiseUtils.ignoreErrors(AddonModChoice.getChoice(courseId, module.id)); return this.getIntroFilesFromInstance(module, choice); } diff --git a/src/addons/mod/data/components/index/index.ts b/src/addons/mod/data/components/index/index.ts index b028db3a8..0265b0635 100644 --- a/src/addons/mod/data/components/index/index.ts +++ b/src/addons/mod/data/components/index/index.ts @@ -52,6 +52,7 @@ import { AddonModDataTemplateMode, } from '../../constants'; import { CoreModals } from '@services/modals'; +import { CorePromiseUtils } from '@singletons/promise-utils'; const contentToken = ''; @@ -223,7 +224,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp if (sync) { // Try to synchronize the data. - await CoreUtils.ignoreErrors(this.syncActivity(showErrors)); + await CorePromiseUtils.ignoreErrors(this.syncActivity(showErrors)); } this.groupInfo = await CoreGroups.getActivityGroupInfo(this.database.coursemodule); diff --git a/src/addons/mod/data/pages/entry/entry.ts b/src/addons/mod/data/pages/entry/entry.ts index 4e2ea678c..82844859e 100644 --- a/src/addons/mod/data/pages/entry/entry.ts +++ b/src/addons/mod/data/pages/entry/entry.ts @@ -43,6 +43,7 @@ import { AddonModDataTemplateType, AddonModDataTemplateMode, } from '../../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays the view entry page. @@ -432,7 +433,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { return; } - await CoreUtils.ignoreErrors(AddonModData.logView(this.database.id)); + await CorePromiseUtils.ignoreErrors(AddonModData.logView(this.database.id)); // Store module viewed because this page also updates recent accessed items block. CoreCourse.storeModuleViewed(this.courseId, this.moduleId); diff --git a/src/addons/mod/data/services/data-helper.ts b/src/addons/mod/data/services/data-helper.ts index a8d828af7..3abf13517 100644 --- a/src/addons/mod/data/services/data-helper.ts +++ b/src/addons/mod/data/services/data-helper.ts @@ -22,7 +22,7 @@ import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreFormFields } from '@singletons/form'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { @@ -174,7 +174,7 @@ export class AddonModDataHelperProvider { promises.push(AddonModData.invalidateEntryData(dataId, entryId, siteId)); promises.push(AddonModData.invalidateEntriesData(dataId, siteId)); - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); CoreEvents.trigger(ADDON_MOD_DATA_ENTRY_CHANGED, { dataId: dataId, entryId: entryId }, siteId); diff --git a/src/addons/mod/data/services/data-offline.ts b/src/addons/mod/data/services/data-offline.ts index 69b363586..a2ab5c134 100644 --- a/src/addons/mod/data/services/data-offline.ts +++ b/src/addons/mod/data/services/data-offline.ts @@ -17,7 +17,7 @@ import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fi import { CoreFile } from '@services/file'; import { CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { CorePath } from '@singletons/path'; import { AddonModDataEntryWSField } from './data'; @@ -80,7 +80,7 @@ export class AddonModDataOfflineProvider { */ protected async deleteEntryFiles(dataId: number, entryId: number, action: AddonModDataAction, siteId?: string): Promise { const site = await CoreSites.getSite(siteId); - const entry = await CoreUtils.ignoreErrors(this.getEntry(dataId, entryId, action, site.id)); + const entry = await CorePromiseUtils.ignoreErrors(this.getEntry(dataId, entryId, action, site.id)); if (!entry || !entry.fields) { // Entry not found or no fields, ignore. @@ -191,7 +191,7 @@ export class AddonModDataOfflineProvider { async hasOfflineData(dataId: number, siteId?: string): Promise { const site = await CoreSites.getSite(siteId); - return CoreUtils.promiseWorks( + return CorePromiseUtils.promiseWorks( site.getDb().recordExists(DATA_ENTRY_TABLE, { dataid: dataId }), ); } diff --git a/src/addons/mod/data/services/data-sync.ts b/src/addons/mod/data/services/data-sync.ts index f940aae39..224f8002d 100644 --- a/src/addons/mod/data/services/data-sync.ts +++ b/src/addons/mod/data/services/data-sync.ts @@ -34,6 +34,7 @@ import { AddonModDataHelper } from './data-helper'; import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline'; import { ADDON_MOD_DATA_AUTO_SYNCED, ADDON_MOD_DATA_COMPONENT, AddonModDataAction } from '../constants'; import { CoreText } from '@singletons/text'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync databases. @@ -164,7 +165,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider */ protected async performSyncDatabase(dataId: number, siteId: string): Promise { // Sync offline logs. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreCourseLogHelper.syncActivity(ADDON_MOD_DATA_COMPONENT, dataId, siteId), ); @@ -175,11 +176,11 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider // Get answers to be sent. const offlineActions: AddonModDataOfflineAction[] = - await CoreUtils.ignoreErrors(AddonModDataOffline.getDatabaseEntries(dataId, siteId), []); + await CorePromiseUtils.ignoreErrors(AddonModDataOffline.getDatabaseEntries(dataId, siteId), []); if (!offlineActions.length) { // Nothing to sync. - await CoreUtils.ignoreErrors(this.setSyncTime(dataId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(dataId, siteId)); return result; } @@ -211,11 +212,11 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider if (result.updated) { // Data has been sent to server. Now invalidate the WS calls. - await CoreUtils.ignoreErrors(AddonModData.invalidateContent(database.coursemodule, courseId, siteId)); + await CorePromiseUtils.ignoreErrors(AddonModData.invalidateContent(database.coursemodule, courseId, siteId)); } // Sync finished, set sync time. - await CoreUtils.ignoreErrors(this.setSyncTime(dataId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(dataId, siteId)); return result; } @@ -453,7 +454,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider }); } - return CoreUtils.allPromises(subPromises); + return CorePromiseUtils.allPromises(subPromises); })); await Promise.all(promises); diff --git a/src/addons/mod/data/services/data.ts b/src/addons/mod/data/services/data.ts index aab92f797..89292ac97 100644 --- a/src/addons/mod/data/services/data.ts +++ b/src/addons/mod/data/services/data.ts @@ -35,6 +35,7 @@ import { AddonModDataAction, } from '../constants'; import { CoreCacheUpdateFrequency } from '@/core/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; declare module '@singletons/events' { @@ -823,7 +824,7 @@ export class AddonModDataProvider { promises.push(this.invalidateFiles(moduleId, siteId)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/data/services/handlers/prefetch-lazy.ts b/src/addons/mod/data/services/handlers/prefetch-lazy.ts index d79159dbd..a185d7e05 100644 --- a/src/addons/mod/data/services/handlers/prefetch-lazy.ts +++ b/src/addons/mod/data/services/handlers/prefetch-lazy.ts @@ -27,6 +27,7 @@ import { AddonModDataEntry, AddonModData, AddonModDataData } from '../data'; import { AddonModDataSync, AddonModDataSyncResult } from '../data-sync'; import { ContextLevel } from '@/core/constants'; import { AddonModDataPrefetchHandlerService } from '@addons/mod/data/services/handlers/prefetch'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler to prefetch databases. @@ -151,7 +152,7 @@ export class AddonModDataPrefetchHandlerLazyService extends AddonModDataPrefetch * @inheritdoc */ async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { - const data = await CoreUtils.ignoreErrors(AddonModData.getDatabase(courseId, module.id)); + const data = await CorePromiseUtils.ignoreErrors(AddonModData.getDatabase(courseId, module.id)); return this.getIntroFilesFromInstance(module, data); } @@ -260,7 +261,7 @@ export class AddonModDataPrefetchHandlerLazyService extends AddonModDataPrefetch promises.push(CoreCourse.getModuleBasicInfoByInstance(database.id, 'data', { siteId })); // Get course data, needed to determine upload max size if it's configured to be course limit. - promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + promises.push(CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); await Promise.all(promises); } diff --git a/src/addons/mod/feedback/components/index/index.ts b/src/addons/mod/feedback/components/index/index.ts index 268ad383c..33e571e70 100644 --- a/src/addons/mod/feedback/components/index/index.ts +++ b/src/addons/mod/feedback/components/index/index.ts @@ -23,7 +23,7 @@ import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; import { CoreTimeUtils } from '@services/utils/time'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { AddonModFeedback, @@ -108,7 +108,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity // Prefetch data if needed. if (!data.offline && this.isPrefetched()) { - await CoreUtils.ignoreErrors(AddonModFeedbackSync.prefetchAfterUpdate( + await CorePromiseUtils.ignoreErrors(AddonModFeedbackSync.prefetchAfterUpdate( AddonModFeedbackPrefetchHandler.instance, this.module, this.courseId, diff --git a/src/addons/mod/feedback/pages/attempts/attempts.ts b/src/addons/mod/feedback/pages/attempts/attempts.ts index 17114add8..680d0f6cc 100644 --- a/src/addons/mod/feedback/pages/attempts/attempts.ts +++ b/src/addons/mod/feedback/pages/attempts/attempts.ts @@ -21,7 +21,7 @@ import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreGroupInfo } from '@services/groups'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModFeedbackAttemptItem, AddonModFeedbackAttemptsSource } from '../../classes/feedback-attempts-source'; import { AddonModFeedbackWSAnonAttempt, AddonModFeedbackWSAttempt } from '../../services/feedback'; import { CoreTime } from '@singletons/time'; @@ -180,7 +180,7 @@ export class AddonModFeedbackAttemptsPage implements AfterViewInit, OnDestroy { try { this.fetchFailed = false; - await CoreUtils.ignoreErrors(attempts.getSource().invalidateCache()); + await CorePromiseUtils.ignoreErrors(attempts.getSource().invalidateCache()); await attempts.getSource().loadFeedback(); await attempts.reload(); } catch (error) { diff --git a/src/addons/mod/feedback/pages/form/form.ts b/src/addons/mod/feedback/pages/form/form.ts index 874dcba5f..388f7d37c 100644 --- a/src/addons/mod/feedback/pages/form/form.ts +++ b/src/addons/mod/feedback/pages/form/form.ts @@ -44,6 +44,7 @@ import { } from '../../constants'; import { CoreLoadings } from '@services/loadings'; import { CoreError } from '@classes/errors/error'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays feedback form. @@ -349,7 +350,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave { try { // Sync other pages first. - await CoreUtils.ignoreErrors(AddonModFeedbackSync.syncFeedback(this.feedback.id)); + await CorePromiseUtils.ignoreErrors(AddonModFeedbackSync.syncFeedback(this.feedback.id)); const response = await AddonModFeedback.processPage(this.feedback.id, this.currentPage, responses, { goPrevious, diff --git a/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts b/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts index 66a88cd4f..30073a27a 100644 --- a/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts +++ b/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts @@ -16,7 +16,7 @@ import { Component, OnInit } from '@angular/core'; import { CoreGroupInfo, CoreGroups } from '@services/groups'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModFeedback, AddonModFeedbackWSFeedback } from '../../services/feedback'; import { AddonModFeedbackHelper, AddonModFeedbackNonRespondent } from '../../services/feedback-helper'; import { CoreTime } from '@singletons/time'; @@ -182,7 +182,7 @@ export class AddonModFeedbackNonRespondentsPage implements OnInit { promises.push(AddonModFeedback.invalidateNonRespondentsData(this.feedback.id)); } - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); await this.fetchData(true); } finally { diff --git a/src/addons/mod/feedback/services/feedback-sync.ts b/src/addons/mod/feedback/services/feedback-sync.ts index 636805023..9dc1c555f 100644 --- a/src/addons/mod/feedback/services/feedback-sync.ts +++ b/src/addons/mod/feedback/services/feedback-sync.ts @@ -28,6 +28,7 @@ import { AddonModFeedback, AddonModFeedbackWSFeedback } from './feedback'; import { AddonModFeedbackOffline, AddonModFeedbackOfflineResponse } from './feedback-offline'; import { AddonModFeedbackPrefetchHandler, AddonModFeedbackPrefetchHandlerService } from './handlers/prefetch'; import { ADDON_MOD_FEEDBACK_AUTO_SYNCED, ADDON_MOD_FEEDBACK_COMPONENT } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync feedbacks. @@ -161,14 +162,14 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv }; // Sync offline logs. - await CoreUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_FEEDBACK_COMPONENT, feedbackId, siteId)); + await CorePromiseUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_FEEDBACK_COMPONENT, feedbackId, siteId)); // Get offline responses to be sent. - const responses = await CoreUtils.ignoreErrors(AddonModFeedbackOffline.getFeedbackResponses(feedbackId, siteId)); + const responses = await CorePromiseUtils.ignoreErrors(AddonModFeedbackOffline.getFeedbackResponses(feedbackId, siteId)); if (!responses || !responses.length) { // Nothing to sync. - await CoreUtils.ignoreErrors(this.setSyncTime(feedbackId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(feedbackId, siteId)); return result; } @@ -198,7 +199,7 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv Translate.instant('addon.mod_feedback.this_feedback_is_already_submitted'), ); - await CoreUtils.ignoreErrors(this.setSyncTime(feedbackId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(feedbackId, siteId)); return result; } @@ -217,7 +218,7 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv })); // Execute all the processes in order to solve dependencies. - await CoreUtils.executeOrderedPromises(orderedData); + await CorePromiseUtils.executeOrderedPromises(orderedData); if (result.updated) { // Data has been sent to server, update data. @@ -231,7 +232,7 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv } // Sync finished, set sync time. - await CoreUtils.ignoreErrors(this.setSyncTime(feedbackId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(feedbackId, siteId)); return result; } diff --git a/src/addons/mod/feedback/services/feedback.ts b/src/addons/mod/feedback/services/feedback.ts index abd261725..6d781f54d 100644 --- a/src/addons/mod/feedback/services/feedback.ts +++ b/src/addons/mod/feedback/services/feedback.ts @@ -35,6 +35,7 @@ import { AddonModFeedbackIndexTabName, } from '../constants'; import { CoreCacheUpdateFrequency } from '@/core/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service that provides some features for feedbacks. @@ -156,7 +157,7 @@ export class AddonModFeedbackProvider { } // Merge with offline data. - const offlineResponses = await CoreUtils.ignoreErrors( + const offlineResponses = await CorePromiseUtils.ignoreErrors( AddonModFeedbackOffline.getFeedbackResponses(feedbackId, options.siteId), ); @@ -1086,7 +1087,7 @@ export class AddonModFeedbackProvider { ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; - return CoreUtils.promiseWorks(site.read('mod_feedback_get_last_completed', params, preSets)); + return CorePromiseUtils.promiseWorks(site.read('mod_feedback_get_last_completed', params, preSets)); } /** @@ -1233,9 +1234,9 @@ export class AddonModFeedbackProvider { const response = await site.write('mod_feedback_process_page', params); // Invalidate and update current values because they will change. - await CoreUtils.ignoreErrors(this.invalidateCurrentValuesData(feedbackId, site.getId())); + await CorePromiseUtils.ignoreErrors(this.invalidateCurrentValuesData(feedbackId, site.getId())); - await CoreUtils.ignoreErrors(this.getCurrentValues(feedbackId, { siteId: site.getId() })); + await CorePromiseUtils.ignoreErrors(this.getCurrentValues(feedbackId, { siteId: site.getId() })); return response; } diff --git a/src/addons/mod/feedback/services/handlers/prefetch.ts b/src/addons/mod/feedback/services/handlers/prefetch.ts index 576c841fd..3d8ffbdb3 100644 --- a/src/addons/mod/feedback/services/handlers/prefetch.ts +++ b/src/addons/mod/feedback/services/handlers/prefetch.ts @@ -19,7 +19,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreGroups } from '@services/groups'; import { CoreSitesReadingStrategy } from '@services/sites'; import { CoreTimeUtils } from '@services/utils/time'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { @@ -70,7 +70,7 @@ export class AddonModFeedbackPrefetchHandlerService extends CoreCourseActivityPr * @inheritdoc */ async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { - const feedback = await CoreUtils.ignoreErrors(AddonModFeedback.getFeedback(courseId, module.id)); + const feedback = await CorePromiseUtils.ignoreErrors(AddonModFeedback.getFeedback(courseId, module.id)); return this.getIntroFilesFromInstance(module, feedback); } diff --git a/src/addons/mod/folder/components/index/index.ts b/src/addons/mod/folder/components/index/index.ts index a9baa74f8..71b4559be 100644 --- a/src/addons/mod/folder/components/index/index.ts +++ b/src/addons/mod/folder/components/index/index.ts @@ -21,7 +21,7 @@ import { CoreNavigator } from '@services/navigator'; import { Md5 } from 'ts-md5'; import { AddonModFolder, AddonModFolderFolder } from '../../services/folder'; import { AddonModFolderFolderFormattedData, AddonModFolderHelper } from '../../services/folder-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ADDON_MOD_FOLDER_COMPONENT, ADDON_MOD_FOLDER_PAGE_NAME } from '../../constants'; /** @@ -121,7 +121,7 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo * @inheritdoc */ protected async logActivity(): Promise { - await CoreUtils.ignoreErrors(AddonModFolder.logView(this.module.instance)); + await CorePromiseUtils.ignoreErrors(AddonModFolder.logView(this.module.instance)); this.analyticsLogEvent('mod_folder_view_folder'); } diff --git a/src/addons/mod/folder/services/folder.ts b/src/addons/mod/folder/services/folder.ts index 6e00dc5f6..272565c56 100644 --- a/src/addons/mod/folder/services/folder.ts +++ b/src/addons/mod/folder/services/folder.ts @@ -18,7 +18,7 @@ import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { CoreCourse } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { ADDON_MOD_FOLDER_COMPONENT } from '../constants'; @@ -106,7 +106,7 @@ export class AddonModFolderProvider { promises.push(this.invalidateFolderData(courseId, siteId)); promises.push(CoreCourse.invalidateModule(moduleId, siteId)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/forum/classes/forum-discussions-source.ts b/src/addons/mod/forum/classes/forum-discussions-source.ts index f94712b52..fe881492e 100644 --- a/src/addons/mod/forum/classes/forum-discussions-source.ts +++ b/src/addons/mod/forum/classes/forum-discussions-source.ts @@ -27,6 +27,7 @@ import { import { AddonModForumOffline, AddonModForumOfflineDiscussion } from '../services/forum-offline'; import { ADDON_MOD_FORUM_DISCUSSIONS_PER_PAGE, AddonModForumType } from '../constants'; import { CoreSites } from '@services/sites'; +import { CorePromiseUtils } from '@singletons/promise-utils'; export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource { @@ -157,7 +158,7 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource async loadGroupInfo(forumId: number): Promise { [this.groupInfo, this.allPartsPermissions] = await Promise.all([ CoreGroups.getActivityGroupInfo(this.CM_ID, false), - CoreUtils.ignoreErrors(AddonModForum.canAddDiscussionToAll(forumId, { cmId: this.CM_ID })), + CorePromiseUtils.ignoreErrors(AddonModForum.canAddDiscussionToAll(forumId, { cmId: this.CM_ID })), ]); this.supportsChangeGroup = AddonModForum.isGetDiscussionPostsAvailable(); diff --git a/src/addons/mod/forum/components/post/post.ts b/src/addons/mod/forum/components/post/post.ts index 3ae86c5ef..da0d15195 100644 --- a/src/addons/mod/forum/components/post/post.ts +++ b/src/addons/mod/forum/components/post/post.ts @@ -58,6 +58,7 @@ import { toBoolean } from '@/core/transforms/boolean'; import { CorePopovers } from '@services/popovers'; import { CoreLoadings } from '@services/loadings'; import { CoreWSFile } from '@services/ws'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Components that shows a discussion post, its attachments and the action buttons allowed (reply, etc.). @@ -599,7 +600,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges })); } - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); // Reset data. this.setFormData(); diff --git a/src/addons/mod/forum/pages/discussion/discussion.ts b/src/addons/mod/forum/pages/discussion/discussion.ts index e023ce08e..a5aa68859 100644 --- a/src/addons/mod/forum/pages/discussion/discussion.ts +++ b/src/addons/mod/forum/pages/discussion/discussion.ts @@ -62,6 +62,7 @@ import { import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { CoreToasts } from '@services/toasts'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; type SortType = 'flat-newest' | 'flat-oldest' | 'nested'; @@ -414,7 +415,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes try { if (sync) { // Try to synchronize the forum. - await CoreUtils.ignoreErrors(this.syncDiscussion(!!showErrors)); + await CorePromiseUtils.ignoreErrors(this.syncDiscussion(!!showErrors)); } const response = await AddonModForum.getDiscussionPosts(this.discussionId, { cmId: this.cmId }); @@ -689,7 +690,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes this.forumId && promises.push(AddonModForum.invalidateAccessInformation(this.forumId)); this.forumId && promises.push(AddonModForum.invalidateCanAddDiscussion(this.forumId)); - await CoreUtils.ignoreErrors(CoreUtils.allPromises(promises)); + await CorePromiseUtils.allPromisesIgnoringErrors(promises); await this.fetchPosts(sync, showErrors); } @@ -872,7 +873,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes * @param logAnalytics Whether to log analytics too or not. */ protected async logDiscussionView(logAnalytics = false): Promise { - await CoreUtils.ignoreErrors(AddonModForum.logDiscussionView(this.discussionId, this.forumId || -1)); + await CorePromiseUtils.ignoreErrors(AddonModForum.logDiscussionView(this.discussionId, this.forumId || -1)); if (logAnalytics) { CoreAnalytics.logEvent({ diff --git a/src/addons/mod/forum/pages/new-discussion/new-discussion.ts b/src/addons/mod/forum/pages/new-discussion/new-discussion.ts index 9e8d0a7e9..227386113 100644 --- a/src/addons/mod/forum/pages/new-discussion/new-discussion.ts +++ b/src/addons/mod/forum/pages/new-discussion/new-discussion.ts @@ -53,6 +53,7 @@ import { } from '../../constants'; import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; type NewDiscussionData = { subject: string; @@ -242,7 +243,7 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea // Use the canAddDiscussion WS to check if the user can add attachments and pin discussions. promises.push( - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( AddonModForum.instance .canAddDiscussionToAll(this.forumId, { cmId: this.cmId }) .then((response) => { @@ -611,7 +612,7 @@ export class AddonModForumNewDiscussionPage implements OnInit, OnDestroy, CanLea promises.push(AddonModForumOffline.deleteNewDiscussion(this.forumId, this.timeCreated)); promises.push( - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( AddonModForumHelper.deleteNewDiscussionStoredFiles(this.forumId, this.timeCreated), ), ); diff --git a/src/addons/mod/forum/pages/search/search.ts b/src/addons/mod/forum/pages/search/search.ts index 89c701de2..934a85d4f 100644 --- a/src/addons/mod/forum/pages/search/search.ts +++ b/src/addons/mod/forum/pages/search/search.ts @@ -30,6 +30,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreUrl } from '@singletons/url'; import { CoreUtils } from '@services/utils/utils'; import { Translate } from '@singletons'; +import { CorePromiseUtils } from '@singletons/promise-utils'; @Component({ selector: 'page-addon-mod-forum-search', @@ -104,7 +105,7 @@ export class AddonModForumSearchPage implements OnInit { await CoreDomUtils.showOperationModals('core.searching', true, async () => { await this.resultsSource.reload(); - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreSearchGlobalSearch.logViewResults(this.resultsSource.getQuery(), this.resultsSource.getFilters()), ); diff --git a/src/addons/mod/forum/services/forum-helper.ts b/src/addons/mod/forum/services/forum-helper.ts index d76a133c4..734c589be 100644 --- a/src/addons/mod/forum/services/forum-helper.ts +++ b/src/addons/mod/forum/services/forum-helper.ts @@ -32,6 +32,7 @@ import { import { AddonModForumDiscussionOptions, AddonModForumOffline, AddonModForumOfflineReply } from './forum-offline'; import { CoreFileEntry } from '@services/file-helper'; import { ADDON_MOD_FORUM_ALL_GROUPS, ADDON_MOD_FORUM_COMPONENT } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service that provides some features for forums. @@ -224,7 +225,7 @@ export class AddonModForumHelperProvider { // Get user data. promises.push( - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( CoreUser.instance .getProfile(offlineReply.userid, offlineReply.courseid, true) .then(user => { @@ -255,7 +256,7 @@ export class AddonModForumHelperProvider { const folderPath = await AddonModForumOffline.getNewDiscussionFolder(forumId, timecreated, siteId); // Ignore any errors, CoreFile.removeDir fails if folder doesn't exist. - await CoreUtils.ignoreErrors(CoreFile.removeDir(folderPath)); + await CorePromiseUtils.ignoreErrors(CoreFile.removeDir(folderPath)); } /** @@ -271,7 +272,7 @@ export class AddonModForumHelperProvider { const folderPath = await AddonModForumOffline.getReplyFolder(forumId, postId, siteId, userId); // Ignore any errors, CoreFile.removeDir fails if folder doesn't exist. - await CoreUtils.ignoreErrors(CoreFile.removeDir(folderPath)); + await CorePromiseUtils.ignoreErrors(CoreFile.removeDir(folderPath)); } /** diff --git a/src/addons/mod/forum/services/forum-sync.ts b/src/addons/mod/forum/services/forum-sync.ts index cd3f6dbc1..261b07ec3 100644 --- a/src/addons/mod/forum/services/forum-sync.ts +++ b/src/addons/mod/forum/services/forum-sync.ts @@ -38,6 +38,7 @@ import { ADDON_MOD_FORUM_COMPONENT, ADDON_MOD_FORUM_MANUAL_SYNCED, } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; declare module '@singletons/events' { @@ -224,12 +225,12 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide // Sync offline logs. const syncDiscussions = async (): Promise => { - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreCourseLogHelper.syncActivity(ADDON_MOD_FORUM_COMPONENT, forumId, siteId), ); // Get offline responses to be sent. - const discussions = await CoreUtils.ignoreErrors( + const discussions = await CorePromiseUtils.ignoreErrors( AddonModForumOffline.getNewDiscussions(forumId, siteId, userId), [] as AddonModForumOfflineDiscussion[], ); @@ -298,11 +299,11 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide AddonModForum.invalidateCanAddDiscussion(forumId, siteId), ]; - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); } // Sync finished, set sync time. - await CoreUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); return result; }; @@ -350,7 +351,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide } }); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); return { updated, warnings }; } @@ -365,7 +366,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide */ async syncForumReplies(forumId: number, userId?: number, siteId?: string): Promise { // Get offline forum replies to be sent. - const replies = await CoreUtils.ignoreErrors( + const replies = await CorePromiseUtils.ignoreErrors( AddonModForumOffline.getForumReplies(forumId, siteId, userId), [] as AddonModForumOfflineReply[], ); @@ -457,7 +458,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide // Get offline responses to be sent. const syncReplies = async () => { - const replies = await CoreUtils.ignoreErrors( + const replies = await CorePromiseUtils.ignoreErrors( AddonModForumOffline.getDiscussionReplies(discussionId, siteId, userId), [] as AddonModForumOfflineReply[], ); @@ -515,10 +516,10 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide invalidationPromises.push(AddonModForum.invalidateDiscussionPosts(discussionId, forumId, siteId)); - await CoreUtils.ignoreErrors(CoreUtils.allPromises(invalidationPromises)); + await CorePromiseUtils.allPromisesIgnoringErrors(invalidationPromises); // Sync finished, set sync time. - await CoreUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); // All done, return the warnings. return result; @@ -539,7 +540,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide protected async deleteNewDiscussion(forumId: number, timecreated: number, siteId?: string, userId?: number): Promise { await Promise.all([ AddonModForumOffline.deleteNewDiscussion(forumId, timecreated, siteId, userId), - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( AddonModForumHelper.deleteNewDiscussionStoredFiles(forumId, timecreated, siteId), ), ]); @@ -557,7 +558,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide protected async deleteReply(forumId: number, postId: number, siteId?: string, userId?: number): Promise { await Promise.all([ AddonModForumOffline.deleteReply(postId, siteId, userId), - CoreUtils.ignoreErrors(AddonModForumHelper.deleteReplyStoredFiles(forumId, postId, siteId, userId)), + CorePromiseUtils.ignoreErrors(AddonModForumHelper.deleteReplyStoredFiles(forumId, postId, siteId, userId)), ]); } diff --git a/src/addons/mod/forum/services/forum.ts b/src/addons/mod/forum/services/forum.ts index ade581784..8ffbc4a9b 100644 --- a/src/addons/mod/forum/services/forum.ts +++ b/src/addons/mod/forum/services/forum.ts @@ -50,6 +50,7 @@ import { AddonModForumType, } from '../constants'; import { CoreCacheUpdateFrequency } from '@/core/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; declare module '@singletons/events' { @@ -733,7 +734,7 @@ export class AddonModForumProvider { let sortOrderValue: number | null = null; if (this.isDiscussionListSortingAvailable()) { - const preferenceValue = await CoreUtils.ignoreErrors( + const preferenceValue = await CorePromiseUtils.ignoreErrors( CoreUser.getUserPreference(ADDON_MOD_FORUM_PREFERENCE_SORTORDER), ); @@ -931,7 +932,7 @@ export class AddonModForumProvider { promises.push(this.invalidateDiscussionPosts(discussion.discussion, forum.id)); }); - return CoreUtils.allPromises(promises); + return CorePromiseUtils.allPromises(promises); }), ); }); @@ -940,7 +941,7 @@ export class AddonModForumProvider { promises.push(CoreUser.invalidateUserPreference(ADDON_MOD_FORUM_PREFERENCE_SORTORDER)); } - return CoreUtils.allPromises(promises); + return CorePromiseUtils.allPromises(promises); } /** @@ -972,7 +973,7 @@ export class AddonModForumProvider { promises.push(site.invalidateWsCacheForKeyStartingWith(this.getForumDiscussionDataCacheKey(forumId, discussionId))); } - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/forum/services/handlers/prefetch.ts b/src/addons/mod/forum/services/handlers/prefetch.ts index d9aa37500..c9eaebfd7 100644 --- a/src/addons/mod/forum/services/handlers/prefetch.ts +++ b/src/addons/mod/forum/services/handlers/prefetch.ts @@ -21,7 +21,7 @@ import { CoreWSFile } from '@services/ws'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreUser } from '@features/user/services/user'; import { CoreGroups, CoreGroupsProvider } from '@services/groups'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModForumSync, AddonModForumSyncResult } from '../forum-sync'; import { makeSingleton } from '@singletons'; import { CoreCourses } from '@features/courses/services/courses'; @@ -251,7 +251,7 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe promises.push(AddonModForum.getAccessInformation(forum.id, modOptions)); // Get course data, needed to determine upload max size if it's configured to be course limit. - promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + promises.push(CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); await Promise.all(promises); } @@ -282,7 +282,7 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe if (mode !== CoreGroupsProvider.SEPARATEGROUPS && mode !== CoreGroupsProvider.VISIBLEGROUPS) { // Activity doesn't use groups. Prefetch canAddDiscussionToAll to determine if user can pin/attach. - await CoreUtils.ignoreErrors(AddonModForum.canAddDiscussionToAll(forum.id, options)); + await CorePromiseUtils.ignoreErrors(AddonModForum.canAddDiscussionToAll(forum.id, options)); return; } @@ -291,11 +291,11 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe const result = await CoreGroups.getActivityAllowedGroups(forum.cmid, undefined, siteId); await Promise.all( result.groups.map( - async (group) => CoreUtils.ignoreErrors( + async (group) => CorePromiseUtils.ignoreErrors( AddonModForum.canAddDiscussion(forum.id, group.id, options), ), ).concat( - CoreUtils.ignoreErrors(AddonModForum.canAddDiscussionToAll(forum.id, options)), + CorePromiseUtils.ignoreErrors(AddonModForum.canAddDiscussionToAll(forum.id, options)), ), ); } catch (error) { diff --git a/src/addons/mod/forum/services/handlers/push-click.ts b/src/addons/mod/forum/services/handlers/push-click.ts index 1b17316fc..5923e1142 100644 --- a/src/addons/mod/forum/services/handlers/push-click.ts +++ b/src/addons/mod/forum/services/handlers/push-click.ts @@ -25,6 +25,7 @@ import { makeSingleton } from '@singletons'; import { isSafeNumber } from '@/core/utils/types'; import { ADDON_MOD_FORUM_PAGE_NAME } from '../../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler for forum push notifications clicks. @@ -75,7 +76,7 @@ export class AddonModForumPushClickHandlerService implements CorePushNotificatio pageParams.postId = Number(data.postid || contextUrlParams.urlHash.replace('p', '')); } - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( AddonModForum.invalidateDiscussionPosts(discussionId, undefined, notification.site), ); diff --git a/src/addons/mod/glossary/pages/entry/entry.ts b/src/addons/mod/glossary/pages/entry/entry.ts index 1286b4e00..5c0425525 100644 --- a/src/addons/mod/glossary/pages/entry/entry.ts +++ b/src/addons/mod/glossary/pages/entry/entry.ts @@ -27,7 +27,7 @@ import { FileEntry } from '@awesome-cordova-plugins/file/ngx'; import { CoreNavigator } from '@services/navigator'; import { CoreNetwork } from '@services/network'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { AddonModGlossaryEntriesSource, AddonModGlossaryEntryItem } from '../../classes/glossary-entries-source'; @@ -86,7 +86,7 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { return; } - await CoreUtils.ignoreErrors(AddonModGlossary.logEntryView(this.onlineEntry.id, this.componentId)); + await CorePromiseUtils.ignoreErrors(AddonModGlossary.logEntryView(this.onlineEntry.id, this.componentId)); this.analyticsLogEvent('mod_glossary_get_entry_by_id', `/mod/glossary/showentry.php?eid=${this.onlineEntry.id}`); }); @@ -184,7 +184,7 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { ); const glossaryId = this.glossary?.id; - const cancelled = await CoreUtils.promiseFails( + const cancelled = await CorePromiseUtils.promiseFails( CoreDomUtils.showConfirm(Translate.instant('addon.mod_glossary.areyousuredelete')), ); @@ -200,13 +200,13 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { await AddonModGlossary.deleteEntry(glossaryId, entryId); await Promise.all([ - CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntry(entryId)), - CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByLetter(glossaryId)), - CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByAuthor(glossaryId)), - CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByCategory(glossaryId)), - CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByDate(glossaryId, 'CREATION')), - CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByDate(glossaryId, 'UPDATE')), - CoreUtils.ignoreErrors(this.entries.getSource().invalidateCache(false)), + CorePromiseUtils.ignoreErrors(AddonModGlossary.invalidateEntry(entryId)), + CorePromiseUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByLetter(glossaryId)), + CorePromiseUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByAuthor(glossaryId)), + CorePromiseUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByCategory(glossaryId)), + CorePromiseUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByDate(glossaryId, 'CREATION')), + CorePromiseUtils.ignoreErrors(AddonModGlossary.invalidateEntriesByDate(glossaryId, 'UPDATE')), + CorePromiseUtils.ignoreErrors(this.entries.getSource().invalidateCache(false)), ]); } else if (this.offlineEntry) { const concept = this.offlineEntry.concept; @@ -239,12 +239,12 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { async doRefresh(refresher?: HTMLIonRefresherElement): Promise { if (this.onlineEntry && this.glossary?.allowcomments && this.onlineEntry.id > 0 && this.commentsEnabled && this.comments) { // Refresh comments asynchronously (without blocking the current promise). - CoreUtils.ignoreErrors(this.comments.doRefresh()); + CorePromiseUtils.ignoreErrors(this.comments.doRefresh()); } try { if (this.onlineEntry) { - await CoreUtils.ignoreErrors(AddonModGlossary.invalidateEntry(this.onlineEntry.id)); + await CorePromiseUtils.ignoreErrors(AddonModGlossary.invalidateEntry(this.onlineEntry.id)); await this.loadOnlineEntry(this.onlineEntry.id); } else if (this.offlineEntry) { const timecreated = Number(this.entrySlug.slice(4)); diff --git a/src/addons/mod/glossary/services/glossary-helper.ts b/src/addons/mod/glossary/services/glossary-helper.ts index e4f9e3067..1067ad606 100644 --- a/src/addons/mod/glossary/services/glossary-helper.ts +++ b/src/addons/mod/glossary/services/glossary-helper.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { FileEntry } from '@awesome-cordova-plugins/file/ngx'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreFile } from '@services/file'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModGlossaryOffline } from './glossary-offline'; import { makeSingleton } from '@singletons'; import { CoreFileEntry } from '@services/file-helper'; @@ -39,7 +39,7 @@ export class AddonModGlossaryHelperProvider { async deleteStoredFiles(glossaryId: number, entryName: string, timeCreated: number, siteId?: string): Promise { const folderPath = await AddonModGlossaryOffline.getEntryFolder(glossaryId, entryName, timeCreated, siteId); - await CoreUtils.ignoreErrors(CoreFile.removeDir(folderPath)); + await CorePromiseUtils.ignoreErrors(CoreFile.removeDir(folderPath)); } /** diff --git a/src/addons/mod/glossary/services/glossary-sync.ts b/src/addons/mod/glossary/services/glossary-sync.ts index 3155ca28a..ab33c570f 100644 --- a/src/addons/mod/glossary/services/glossary-sync.ts +++ b/src/addons/mod/glossary/services/glossary-sync.ts @@ -31,6 +31,7 @@ import { AddonModGlossaryOffline, AddonModGlossaryOfflineEntry } from './glossar import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreFileEntry } from '@services/file-helper'; import { ADDON_MOD_GLOSSARY_COMPONENT, GLOSSARY_AUTO_SYNCED } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync glossaries. @@ -172,17 +173,17 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv const syncId = this.getGlossarySyncId(glossaryId, userId); // Sync offline logs. - await CoreUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_GLOSSARY_COMPONENT, glossaryId, siteId)); + await CorePromiseUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_GLOSSARY_COMPONENT, glossaryId, siteId)); // Get offline responses to be sent. - const entries = await CoreUtils.ignoreErrors( + const entries = await CorePromiseUtils.ignoreErrors( AddonModGlossaryOffline.getGlossaryOfflineEntries(glossaryId, siteId, userId), [], ); if (!entries.length) { // Nothing to sync. - await CoreUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); return result; } else if (!CoreNetwork.isOnline()) { @@ -233,7 +234,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv } // Sync finished, set sync time. - await CoreUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); return result; } @@ -254,7 +255,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv let updated = false; const warnings: string[] = []; - await CoreUtils.allPromises(results.map(async (result) => { + await CorePromiseUtils.allPromises(results.map(async (result) => { if (result.updated.length) { updated = true; @@ -308,7 +309,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv if (entry.attachments.offline) { // Has offline files. - const storedFiles = await CoreUtils.ignoreErrors( + const storedFiles = await CorePromiseUtils.ignoreErrors( AddonModGlossaryHelper.getStoredFiles(glossaryId, entry.concept, entry.timecreated, siteId), [], // Folder not found, no files to add. ); diff --git a/src/addons/mod/glossary/services/glossary.ts b/src/addons/mod/glossary/services/glossary.ts index ce8323b42..d7e3777e2 100644 --- a/src/addons/mod/glossary/services/glossary.ts +++ b/src/addons/mod/glossary/services/glossary.ts @@ -38,6 +38,7 @@ import { ADDON_MOD_GLOSSARY_LIMIT_ENTRIES, } from '../constants'; import { CoreCacheUpdateFrequency } from '@/core/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service that provides some features for glossaries. @@ -320,7 +321,7 @@ export class AddonModGlossaryProvider { if (limit === ADDON_MOD_GLOSSARY_LIMIT_ENTRIES) { // Store entries in background, don't block the user for this. - CoreUtils.ignoreErrors(this.storeEntries(glossaryId, result.entries, from, site.getId())); + CorePromiseUtils.ignoreErrors(this.storeEntries(glossaryId, result.entries, from, site.getId())); } return result; @@ -529,7 +530,7 @@ export class AddonModGlossaryProvider { const data = await this.getStoredDataForEntry(entryId, site.getId()); if (data.from !== undefined) { - const response = await CoreUtils.ignoreErrors( + const response = await CorePromiseUtils.ignoreErrors( this.getEntryFromList(data.glossaryId, entryId, data.from, false, options), ); @@ -703,9 +704,9 @@ export class AddonModGlossaryProvider { async invalidateContent(moduleId: number, courseId: number): Promise { const glossary = await this.getGlossary(courseId, moduleId); - await CoreUtils.ignoreErrors(this.invalidateGlossaryEntries(glossary)); + await CorePromiseUtils.ignoreErrors(this.invalidateGlossaryEntries(glossary)); - await CoreUtils.allPromises([ + await CorePromiseUtils.allPromises([ this.invalidateCourseGlossaries(courseId), this.invalidateCategories(glossary.id), ]); @@ -751,7 +752,7 @@ export class AddonModGlossaryProvider { } }); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/glossary/services/handlers/prefetch.ts b/src/addons/mod/glossary/services/handlers/prefetch.ts index 7e5a6b8d3..9ca88889b 100644 --- a/src/addons/mod/glossary/services/handlers/prefetch.ts +++ b/src/addons/mod/glossary/services/handlers/prefetch.ts @@ -20,7 +20,7 @@ import { CoreCourses } from '@features/courses/services/courses'; import { CoreUser } from '@features/user/services/user'; import { CoreFilepool } from '@services/filepool'; import { CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModGlossary, AddonModGlossaryEntry, AddonModGlossaryGlossary } from '../glossary'; @@ -191,7 +191,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr promises.push(CoreCourse.getModuleBasicInfoByInstance(glossary.id, 'glossary', { siteId })); // Get course data, needed to determine upload max size if it's configured to be course limit. - promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + promises.push(CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); await Promise.all(promises); } diff --git a/src/addons/mod/h5pactivity/components/index/index.ts b/src/addons/mod/h5pactivity/components/index/index.ts index f202bacb8..9fcc02cd2 100644 --- a/src/addons/mod/h5pactivity/components/index/index.ts +++ b/src/addons/mod/h5pactivity/components/index/index.ts @@ -45,7 +45,7 @@ import { } from '../../services/h5pactivity-sync'; import { CoreFileHelper } from '@services/file-helper'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ADDON_MOD_H5PACTIVITY_AUTO_SYNCED, ADDON_MOD_H5PACTIVITY_COMPONENT, @@ -699,7 +699,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv return; } - await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, { + await CorePromiseUtils.ignoreErrors(CoreXAPIOffline.deleteStates(ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, { itemId: this.h5pActivity.context, })); } diff --git a/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts b/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts index 8906f1e40..dd74688b5 100644 --- a/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts +++ b/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts @@ -17,7 +17,7 @@ import { Component, OnInit } from '@angular/core'; import { CoreUser, CoreUserProfile } from '@features/user/services/user'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModH5PActivity, AddonModH5PActivityData, @@ -54,7 +54,7 @@ export class AddonModH5PActivityAttemptResultsPage implements OnInit { return; } - await CoreUtils.ignoreErrors(AddonModH5PActivity.logViewReport( + await CorePromiseUtils.ignoreErrors(AddonModH5PActivity.logViewReport( this.h5pActivity.id, { attemptId: this.attemptId }, )); @@ -153,7 +153,7 @@ export class AddonModH5PActivityAttemptResultsPage implements OnInit { promises.push(AddonModH5PActivity.invalidateAttemptResults(this.h5pActivity.id, this.attemptId)); } - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); await this.fetchData(); } diff --git a/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts b/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts index 7eed14e63..7edad6991 100644 --- a/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts +++ b/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts @@ -18,7 +18,7 @@ import { CoreUser, CoreUserProfile } from '@features/user/services/user'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModH5PActivity, AddonModH5PActivityAttempt, @@ -55,7 +55,7 @@ export class AddonModH5PActivityUserAttemptsPage implements OnInit { return; } - await CoreUtils.ignoreErrors(AddonModH5PActivity.logViewReport( + await CorePromiseUtils.ignoreErrors(AddonModH5PActivity.logViewReport( this.h5pActivity.id, { userId: this.userId }, )); @@ -167,7 +167,7 @@ export class AddonModH5PActivityUserAttemptsPage implements OnInit { promises.push(AddonModH5PActivity.invalidateUserAttempts(this.h5pActivity.id, this.userId)); } - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); await this.fetchData(); } diff --git a/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts b/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts index aee723c13..8c7d0b889 100644 --- a/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts +++ b/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts @@ -17,7 +17,7 @@ import { CoreUser, CoreUserProfile } from '@features/user/services/user'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AddonModH5PActivity, AddonModH5PActivityData, @@ -54,7 +54,7 @@ export class AddonModH5PActivityUsersAttemptsPage implements OnInit { return; } - await CoreUtils.ignoreErrors(AddonModH5PActivity.logViewReport(this.h5pActivity.id)); + await CorePromiseUtils.ignoreErrors(AddonModH5PActivity.logViewReport(this.h5pActivity.id)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM_LIST, @@ -214,7 +214,7 @@ export class AddonModH5PActivityUsersAttemptsPage implements OnInit { promises.push(AddonModH5PActivity.invalidateAllUsersAttempts(this.h5pActivity.id)); } - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); await this.fetchData(true); } diff --git a/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts b/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts index b719ddd27..93bb9c0c8 100644 --- a/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts +++ b/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts @@ -41,6 +41,7 @@ import { ADDON_MOD_H5PACTIVITY_COMPONENT, ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync H5P activities. @@ -208,7 +209,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP } // Sync offline logs. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreCourseLogHelper.syncActivity(ADDON_MOD_H5PACTIVITY_COMPONENT, h5pActivity.id, siteId), ); @@ -268,7 +269,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP if (result.updated) { // Data has been sent to server, invalidate attempts. - await CoreUtils.ignoreErrors(AddonModH5PActivity.invalidateUserAttempts(id, undefined, siteId)); + await CorePromiseUtils.ignoreErrors(AddonModH5PActivity.invalidateUserAttempts(id, undefined, siteId)); } return result; diff --git a/src/addons/mod/h5pactivity/services/handlers/prefetch.ts b/src/addons/mod/h5pactivity/services/handlers/prefetch.ts index 9463f41cf..2985e7d0f 100644 --- a/src/addons/mod/h5pactivity/services/handlers/prefetch.ts +++ b/src/addons/mod/h5pactivity/services/handlers/prefetch.ts @@ -25,7 +25,7 @@ import { CoreXAPI } from '@features/xapi/services/xapi'; import { CoreFileHelper } from '@services/file-helper'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { @@ -149,7 +149,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit const fileState = await CoreFilepool.getFileStateByUrl(siteId, CoreFileHelper.getFileUrl(deployedFile)); if (fileState !== DownloadStatus.DOWNLOADED) { - await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, { + await CorePromiseUtils.ignoreErrors(CoreXAPIOffline.deleteStates(ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, { itemId: h5pActivity.context, siteId, })); diff --git a/src/addons/mod/h5pactivity/services/handlers/report-link.ts b/src/addons/mod/h5pactivity/services/handlers/report-link.ts index 8c2ee7aed..1d70bfe31 100644 --- a/src/addons/mod/h5pactivity/services/handlers/report-link.ts +++ b/src/addons/mod/h5pactivity/services/handlers/report-link.ts @@ -20,7 +20,7 @@ import { CoreCourse } from '@features/course/services/course'; import { CoreNavigator } from '@services/navigator'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { AddonModH5PActivity } from '../h5pactivity'; import { ADDON_MOD_H5PACTIVITY_PAGE_NAME } from '../../constants'; @@ -115,7 +115,7 @@ export class AddonModH5PActivityReportLinkHandlerService extends CoreContentLink canViewAllAttempts = await AddonModH5PActivity.canGetUsersAttempts(siteId); if (canViewAllAttempts) { - const accessInfo = await CoreUtils.ignoreErrors(AddonModH5PActivity.getAccessInformation(id, { + const accessInfo = await CorePromiseUtils.ignoreErrors(AddonModH5PActivity.getAccessInformation(id, { cmId, siteId, })); diff --git a/src/addons/mod/imscp/components/index/index.ts b/src/addons/mod/imscp/components/index/index.ts index 67b1151c2..a2d438487 100644 --- a/src/addons/mod/imscp/components/index/index.ts +++ b/src/addons/mod/imscp/components/index/index.ts @@ -18,7 +18,7 @@ import { CoreCourseContentsPage } from '@features/course/pages/contents/contents import { CoreCourse } from '@features/course/services/course'; import { CoreNavigator } from '@services/navigator'; import { AddonModImscp, AddonModImscpTocItem } from '../../services/imscp'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ADDON_MOD_IMSCP_COMPONENT, ADDON_MOD_IMSCP_PAGE_NAME } from '../../constants'; /** @@ -103,7 +103,7 @@ export class AddonModImscpIndexComponent extends CoreCourseModuleMainResourceCom * @inheritdoc */ protected async logActivity(): Promise { - await CoreUtils.ignoreErrors(AddonModImscp.logView(this.module.instance)); + await CorePromiseUtils.ignoreErrors(AddonModImscp.logView(this.module.instance)); this.analyticsLogEvent('mod_imscp_view_imscp'); } diff --git a/src/addons/mod/imscp/pages/view/view.ts b/src/addons/mod/imscp/pages/view/view.ts index 354dabe01..ad4e232ad 100644 --- a/src/addons/mod/imscp/pages/view/view.ts +++ b/src/addons/mod/imscp/pages/view/view.ts @@ -24,7 +24,7 @@ import { CoreNetwork } from '@services/network'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreErrorHelper } from '@services/error-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { AddonModImscp, AddonModImscpImscp, AddonModImscpTocItem } from '../../services/imscp'; import { CoreModals } from '@services/modals'; @@ -214,12 +214,12 @@ export class AddonModImscpViewPage implements OnInit { * @returns Promise resolved when done. */ async doRefresh(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ AddonModImscp.invalidateContent(this.cmId, this.courseId), CoreCourseModulePrefetchDelegate.invalidateCourseUpdates(this.courseId), // To detect if IMSCP was updated. ])); - await CoreUtils.ignoreErrors(this.fetchContent(true)); + await CorePromiseUtils.ignoreErrors(this.fetchContent(true)); refresher?.complete(); } diff --git a/src/addons/mod/imscp/services/handlers/prefetch.ts b/src/addons/mod/imscp/services/handlers/prefetch.ts index 5aa83b35a..765784bad 100644 --- a/src/addons/mod/imscp/services/handlers/prefetch.ts +++ b/src/addons/mod/imscp/services/handlers/prefetch.ts @@ -22,7 +22,7 @@ import { import { CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModImscp } from '../imscp'; @@ -61,7 +61,7 @@ export class AddonModImscpPrefetchHandlerService extends CoreCourseResourcePrefe */ async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { // If not found, use undefined so module description is used. - const imscp = await CoreUtils.ignoreErrors(AddonModImscp.getImscp(courseId, module.id)); + const imscp = await CorePromiseUtils.ignoreErrors(AddonModImscp.getImscp(courseId, module.id)); return this.getIntroFilesFromInstance(module, imscp); } diff --git a/src/addons/mod/imscp/services/imscp.ts b/src/addons/mod/imscp/services/imscp.ts index 01b5b090a..fa2a3c289 100644 --- a/src/addons/mod/imscp/services/imscp.ts +++ b/src/addons/mod/imscp/services/imscp.ts @@ -21,7 +21,7 @@ import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreSitesCommonWSOptions, CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { CorePath } from '@singletons/path'; @@ -228,7 +228,7 @@ export class AddonModImscpProvider { promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_IMSCP_COMPONENT, moduleId)); promises.push(CoreCourse.invalidateModule(moduleId, siteId)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/label/services/handlers/prefetch.ts b/src/addons/mod/label/services/handlers/prefetch.ts index bd65a972c..1b6db26bb 100644 --- a/src/addons/mod/label/services/handlers/prefetch.ts +++ b/src/addons/mod/label/services/handlers/prefetch.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModLabel } from '../label'; @@ -60,7 +60,7 @@ export class AddonModLabelPrefetchHandlerService extends CoreCourseResourcePrefe promises.push(AddonModLabel.invalidateLabelData(courseId)); promises.push(CoreCourse.invalidateModule(module.id)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/label/services/label.ts b/src/addons/mod/label/services/label.ts index c440210ee..caf828f3c 100644 --- a/src/addons/mod/label/services/label.ts +++ b/src/addons/mod/label/services/label.ts @@ -17,7 +17,7 @@ import { CoreError } from '@classes/errors/error'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { ADDON_MOD_LABEL_COMPONENT } from '../constants'; @@ -133,7 +133,7 @@ export class AddonModLabelProvider { promises.push(this.invalidateLabelData(courseId, siteId)); promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_LABEL_COMPONENT, moduleId, true)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } } diff --git a/src/addons/mod/lesson/components/index/index.ts b/src/addons/mod/lesson/components/index/index.ts index d89a3cc3f..350bbcd82 100644 --- a/src/addons/mod/lesson/components/index/index.ts +++ b/src/addons/mod/lesson/components/index/index.ts @@ -25,7 +25,7 @@ import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreForms } from '@singletons/form'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { AddonModLessonRetakeFinishedInSyncDBRecord } from '../../services/database/lesson'; import { AddonModLessonPrefetchHandler } from '../../services/handlers/prefetch'; @@ -375,7 +375,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo return; } - await CoreUtils.ignoreErrors(AddonModLesson.logViewLesson(this.lesson.id, this.password)); + await CorePromiseUtils.ignoreErrors(AddonModLesson.logViewLesson(this.lesson.id, this.password)); } /** @@ -562,10 +562,10 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo if (formattedData.students) { // Get the user data for each student returned. - await CoreUtils.allPromises(formattedData.students.map(async (student) => { + await CorePromiseUtils.allPromises(formattedData.students.map(async (student) => { student.bestgrade = CoreText.roundToDecimals(student.bestgrade, 2); - const user = await CoreUtils.ignoreErrors(CoreUser.getProfile(student.id, this.courseId, true)); + const user = await CorePromiseUtils.ignoreErrors(CoreUser.getProfile(student.id, this.courseId, true)); if (user) { student.profileimageurl = user.profileimageurl; } @@ -672,7 +672,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo if (!result.updated && this.dataSent && this.isPrefetched()) { // The user sent data to server, but not in the sync process. Check if we need to fetch data. - await CoreUtils.ignoreErrors(AddonModLessonSync.prefetchAfterUpdate( + await CorePromiseUtils.ignoreErrors(AddonModLessonSync.prefetchAfterUpdate( AddonModLessonPrefetchHandler.instance, this.module, this.courseId, diff --git a/src/addons/mod/lesson/pages/player/player.ts b/src/addons/mod/lesson/pages/player/player.ts index 160cd3512..fd5b2be34 100644 --- a/src/addons/mod/lesson/pages/player/player.ts +++ b/src/addons/mod/lesson/pages/player/player.ts @@ -55,6 +55,7 @@ import { CoreFormFields, CoreForms } from '@singletons/form'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { ADDON_MOD_LESSON_COMPONENT, AddonModLessonJumpTo } from '../../constants'; import { CoreModals } from '@services/modals'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that allows attempting and reviewing a lesson. @@ -384,7 +385,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave { if (this.offline && CoreNetwork.isOnline()) { // Offline mode but the app is online. Try to sync the data. - const result = await CoreUtils.ignoreErrors( + const result = await CorePromiseUtils.ignoreErrors( AddonModLessonSync.syncLesson(lesson.id, true, true), ); diff --git a/src/addons/mod/lesson/pages/user-retake/user-retake.ts b/src/addons/mod/lesson/pages/user-retake/user-retake.ts index 090df40d8..a76fdd9a1 100644 --- a/src/addons/mod/lesson/pages/user-retake/user-retake.ts +++ b/src/addons/mod/lesson/pages/user-retake/user-retake.ts @@ -35,6 +35,7 @@ import { AddonModLessonAnswerData, AddonModLessonHelper } from '../../services/l import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { ADDON_MOD_LESSON_COMPONENT } from '../../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays a retake made by a certain user. @@ -161,7 +162,7 @@ export class AddonModLessonUserRetakePage implements OnInit { } // Get the profile image of the user. - const user = await CoreUtils.ignoreErrors(CoreUser.getProfile(student.id, this.courseId, true)); + const user = await CorePromiseUtils.ignoreErrors(CoreUser.getProfile(student.id, this.courseId, true)); this.student = student; this.student.profileimageurl = user?.profileimageurl; @@ -188,7 +189,7 @@ export class AddonModLessonUserRetakePage implements OnInit { promises.push(AddonModLesson.invalidateUserRetakesForUser(this.lesson.id, this.userId)); } - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); await this.fetchData(); } diff --git a/src/addons/mod/lesson/services/handlers/index-link.ts b/src/addons/mod/lesson/services/handlers/index-link.ts index 39fd3d9c3..adb07e876 100644 --- a/src/addons/mod/lesson/services/handlers/index-link.ts +++ b/src/addons/mod/lesson/services/handlers/index-link.ts @@ -20,7 +20,7 @@ import { CoreCourse } from '@features/course/services/course'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreSitesReadingStrategy } from '@services/sites'; import { CoreLoadings } from '@services/loadings'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { AddonModLesson } from '../lesson'; @@ -95,7 +95,7 @@ export class AddonModLessonIndexLinkHandlerService extends CoreContentLinksModul ); // Store the password so it's automatically used. - await CoreUtils.ignoreErrors(AddonModLesson.storePassword(module.instance, password, siteId)); + await CorePromiseUtils.ignoreErrors(AddonModLesson.storePassword(module.instance, password, siteId)); await CoreCourseHelper.navigateToModule(moduleId, { courseId: module.course, diff --git a/src/addons/mod/lesson/services/handlers/prefetch.ts b/src/addons/mod/lesson/services/handlers/prefetch.ts index 6df58a118..853d3550c 100644 --- a/src/addons/mod/lesson/services/handlers/prefetch.ts +++ b/src/addons/mod/lesson/services/handlers/prefetch.ts @@ -22,7 +22,7 @@ import { CoreGroups } from '@services/groups'; import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreModals } from '@services/modals'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { @@ -119,7 +119,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref } // The lesson requires a password. Check if there is one in DB. - let password = await CoreUtils.ignoreErrors(AddonModLesson.getStoredPassword(lessonId)); + let password = await CorePromiseUtils.ignoreErrors(AddonModLesson.getStoredPassword(lessonId)); if (password) { try { @@ -294,7 +294,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref await AddonModLesson.launchRetake(lessonId, password, undefined, false, siteId); const results = await Promise.all([ - CoreUtils.ignoreErrors(CoreFilepool.updatePackageDownloadTime(siteId, this.component, module.id)), + CorePromiseUtils.ignoreErrors(CoreFilepool.updatePackageDownloadTime(siteId, this.component, module.id)), AddonModLesson.getAccessInformation(lessonId, modOptions), ]); @@ -324,7 +324,7 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref await Promise.all([ this.prefetchPagesData(lesson, passwordOptions), // Prefetch user timers to be able to calculate timemodified in offline. - CoreUtils.ignoreErrors(AddonModLesson.getTimers(lesson.id, modOptions)), + CorePromiseUtils.ignoreErrors(AddonModLesson.getTimers(lesson.id, modOptions)), // Prefetch viewed pages in last retake to calculate progress. AddonModLesson.getContentPagesViewedOnline(lesson.id, retake, modOptions), // Prefetch question attempts in last retake for offline calculations. diff --git a/src/addons/mod/lesson/services/lesson-offline.ts b/src/addons/mod/lesson/services/lesson-offline.ts index daf5b656c..b7cd842cf 100644 --- a/src/addons/mod/lesson/services/lesson-offline.ts +++ b/src/addons/mod/lesson/services/lesson-offline.ts @@ -28,6 +28,7 @@ import { import { AddonModLessonPageWSData } from './lesson'; import { AddonModLessonPageType } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to handle offline lesson. @@ -144,8 +145,8 @@ export class AddonModLessonOfflineProvider { const lessons: Record = {}; const [pageAttempts, retakes] = await Promise.all([ - CoreUtils.ignoreErrors(this.getAllAttempts(siteId)), - CoreUtils.ignoreErrors(this.getAllRetakes(siteId)), + CorePromiseUtils.ignoreErrors(this.getAllAttempts(siteId)), + CorePromiseUtils.ignoreErrors(this.getAllRetakes(siteId)), ]); this.getLessonsFromEntries(lessons, pageAttempts || []); @@ -420,8 +421,8 @@ export class AddonModLessonOfflineProvider { */ async hasOfflineData(lessonId: number, siteId?: string): Promise { const [retake, attempts] = await Promise.all([ - CoreUtils.ignoreErrors(this.getRetake(lessonId, siteId)), - CoreUtils.ignoreErrors(this.getLessonAttempts(lessonId, siteId)), + CorePromiseUtils.ignoreErrors(this.getRetake(lessonId, siteId)), + CorePromiseUtils.ignoreErrors(this.getLessonAttempts(lessonId, siteId)), ]); return !!retake || !!attempts?.length; diff --git a/src/addons/mod/lesson/services/lesson-sync.ts b/src/addons/mod/lesson/services/lesson-sync.ts index 304eb227f..303f8df81 100644 --- a/src/addons/mod/lesson/services/lesson-sync.ts +++ b/src/addons/mod/lesson/services/lesson-sync.ts @@ -32,6 +32,7 @@ import { AddonModLessonGetPasswordResult, AddonModLessonPrefetchHandler } from ' import { AddonModLesson, AddonModLessonLessonWSData } from './lesson'; import { AddonModLessonOffline, AddonModLessonPageAttemptRecord } from './lesson-offline'; import { ADDON_MOD_LESSON_AUTO_SYNCED, ADDON_MOD_LESSON_COMPONENT } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync lesson. @@ -56,7 +57,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid const site = await CoreSites.getSite(siteId); // Ignore errors, maybe there is none. - await CoreUtils.ignoreErrors(site.getDb().deleteRecords(RETAKES_FINISHED_SYNC_TABLE_NAME, { lessonid: lessonId })); + await CorePromiseUtils.ignoreErrors(site.getDb().deleteRecords(RETAKES_FINISHED_SYNC_TABLE_NAME, { lessonid: lessonId })); } /** @@ -72,7 +73,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid ): Promise { const site = await CoreSites.getSite(siteId); - return CoreUtils.ignoreErrors(site.getDb().getRecord(RETAKES_FINISHED_SYNC_TABLE_NAME, { lessonid: lessonId })); + return CorePromiseUtils.ignoreErrors(site.getDb().getRecord(RETAKES_FINISHED_SYNC_TABLE_NAME, { lessonid: lessonId })); } /** @@ -86,8 +87,8 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid async hasDataToSync(lessonId: number, retake: number, siteId?: string): Promise { const [hasAttempts, hasFinished] = await Promise.all([ - CoreUtils.ignoreErrors(AddonModLessonOffline.hasRetakeAttempts(lessonId, retake, siteId)), - CoreUtils.ignoreErrors(AddonModLessonOffline.hasFinishedRetake(lessonId, siteId)), + CorePromiseUtils.ignoreErrors(AddonModLessonOffline.hasRetakeAttempts(lessonId, retake, siteId)), + CorePromiseUtils.ignoreErrors(AddonModLessonOffline.hasFinishedRetake(lessonId, siteId)), ]); return !!(hasAttempts || hasFinished); @@ -224,7 +225,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid siteId?: string, ): Promise { // Sync offline logs. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreCourseLogHelper.syncActivity(ADDON_MOD_LESSON_COMPONENT, lessonId, siteId), ); @@ -250,7 +251,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid } // Sync finished, set sync time. - await CoreUtils.ignoreErrors(this.setSyncTime(lessonId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(lessonId, siteId)); // All done, return the result. return result; @@ -302,7 +303,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid } // Attempt doesn't belong to current retake, delete. - promises.push(CoreUtils.ignoreErrors(AddonModLessonOffline.deleteAttempt( + promises.push(CorePromiseUtils.ignoreErrors(AddonModLessonOffline.deleteAttempt( lesson.id, attempt.retake, attempt.pageid, @@ -337,7 +338,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid blocking: true, })); - await CoreUtils.executeOrderedPromises(promisesData); + await CorePromiseUtils.executeOrderedPromises(promisesData); return passwordData; } @@ -408,7 +409,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid siteId?: string, ): Promise { // Attempts sent or there was none. If there is a finished retake, send it. - const retake = await CoreUtils.ignoreErrors(AddonModLessonOffline.getRetake(lessonId, siteId)); + const retake = await CorePromiseUtils.ignoreErrors(AddonModLessonOffline.getRetake(lessonId, siteId)); if (!retake) { // No retake to sync. diff --git a/src/addons/mod/lesson/services/lesson.ts b/src/addons/mod/lesson/services/lesson.ts index 8628d7e7c..ddb6340e9 100644 --- a/src/addons/mod/lesson/services/lesson.ts +++ b/src/addons/mod/lesson/services/lesson.ts @@ -36,6 +36,7 @@ import { } from '../constants'; import { CoreGradeType } from '@features/grades/constants'; import { CoreCacheUpdateFrequency } from '@/core/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; declare module '@singletons/events' { @@ -1013,7 +1014,7 @@ export class AddonModLessonProvider { siteId: options.siteId, }; - const gradeInfo = await CoreUtils.ignoreErrors(this.lessonGrade(lesson, retake, newOptions)); + const gradeInfo = await CorePromiseUtils.ignoreErrors(this.lessonGrade(lesson, retake, newOptions)); // Retake marked, now return the response. return this.processEolPage(lesson, courseId, options, gradeInfo); @@ -1193,7 +1194,7 @@ export class AddonModLessonProvider { const [online, offline] = await Promise.all([ this.getContentPagesViewedOnline(lessonId, retake, options), - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( AddonModLessonOffline.getRetakeAttemptsForType(lessonId, retake, type, options.siteId), ), ]); @@ -1485,7 +1486,7 @@ export class AddonModLessonProvider { if (validatePassword) { // Invalidate the data and reject. - await CoreUtils.ignoreErrors(this.invalidateLessonWithPassword(lessonId, site.id)); + await CorePromiseUtils.ignoreErrors(this.invalidateLessonWithPassword(lessonId, site.id)); throw new CoreError(Translate.instant('addon.mod_lesson.loginfail')); } @@ -1885,7 +1886,7 @@ export class AddonModLessonProvider { // Tell student how many questions they have seen, how many are required and their grade. const retake = accessInfo.attemptscount; - const gradeInfo = await CoreUtils.ignoreErrors(this.lessonGrade(lesson, retake, options)); + const gradeInfo = await CorePromiseUtils.ignoreErrors(this.lessonGrade(lesson, retake, options)); if (gradeInfo?.attempts) { if (gradeInfo.nquestions < lesson.minquestions) { this.addMessage(messages, 'addon.mod_lesson.numberofpagesviewednotice', { @@ -1943,7 +1944,7 @@ export class AddonModLessonProvider { const [online, offline] = await Promise.all([ this.getQuestionsAttemptsOnline(lessonId, retake, options), - CoreUtils.ignoreErrors(AddonModLessonOffline.getQuestionsAttempts( + CorePromiseUtils.ignoreErrors(AddonModLessonOffline.getQuestionsAttempts( lessonId, retake, options.correct, diff --git a/src/addons/mod/page/components/index/index.ts b/src/addons/mod/page/components/index/index.ts index ad368ca1f..4e63ead7b 100644 --- a/src/addons/mod/page/components/index/index.ts +++ b/src/addons/mod/page/components/index/index.ts @@ -20,6 +20,7 @@ import { CoreUtils } from '@services/utils/utils'; import { AddonModPagePage, AddonModPage } from '../../services/page'; import { AddonModPageHelper } from '../../services/page-helper'; import { ADDON_MOD_PAGE_COMPONENT } from '../../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component that displays a page. @@ -107,7 +108,7 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp * @inheritdoc */ protected async logActivity(): Promise { - await CoreUtils.ignoreErrors(AddonModPage.logView(this.module.instance)); + await CorePromiseUtils.ignoreErrors(AddonModPage.logView(this.module.instance)); this.analyticsLogEvent('mod_page_view_page'); } diff --git a/src/addons/mod/page/services/handlers/prefetch.ts b/src/addons/mod/page/services/handlers/prefetch.ts index f00fceb80..15f06c290 100644 --- a/src/addons/mod/page/services/handlers/prefetch.ts +++ b/src/addons/mod/page/services/handlers/prefetch.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourseModuleData } from '@features/course/services/course-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { AddonModPage } from '../page'; import { ADDON_MOD_PAGE_COMPONENT } from '../../constants'; @@ -73,7 +73,7 @@ export class AddonModPagePrefetchHandlerService extends CoreCourseResourcePrefet promises.push(AddonModPage.invalidatePageData(courseId)); promises.push(CoreCourse.invalidateModule(module.id)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/page/services/page.ts b/src/addons/mod/page/services/page.ts index ccedacf02..87cc04221 100644 --- a/src/addons/mod/page/services/page.ts +++ b/src/addons/mod/page/services/page.ts @@ -18,7 +18,7 @@ import { CoreWSExternalWarning, CoreWSExternalFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { CoreFilepool } from '@services/filepool'; import { CoreCourse } from '@features/course/services/course'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreError } from '@classes/errors/error'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; @@ -109,7 +109,7 @@ export class AddonModPageProvider { promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_PAGE_COMPONENT, moduleId)); promises.push(CoreCourse.invalidateModule(moduleId, siteId)); - return CoreUtils.allPromises(promises); + return CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/quiz/accessrules/password/services/handlers/password.ts b/src/addons/mod/quiz/accessrules/password/services/handlers/password.ts index b2328c887..7e0fec67f 100644 --- a/src/addons/mod/quiz/accessrules/password/services/handlers/password.ts +++ b/src/addons/mod/quiz/accessrules/password/services/handlers/password.ts @@ -20,7 +20,7 @@ import { AddonModQuizAttemptWSData, AddonModQuizQuizWSData } from '@addons/mod/q import { CoreSites } from '@services/sites'; import { AddonModQuizAccessPasswordDBRecord, PASSWORD_TABLE_NAME } from '../database/password'; import { AddonModQuizAccessPasswordComponent } from '../../component/password'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler to support password access rule. @@ -111,7 +111,7 @@ export class AddonModQuizAccessPasswordHandlerService implements AddonModQuizAcc siteId?: string, ): Promise { // If there's a password stored don't require the preflight since we'll use the stored one. - const entry = await CoreUtils.ignoreErrors(this.getPasswordEntry(quiz.id, siteId)); + const entry = await CorePromiseUtils.ignoreErrors(this.getPasswordEntry(quiz.id, siteId)); return !entry; } diff --git a/src/addons/mod/quiz/components/index/index.ts b/src/addons/mod/quiz/components/index/index.ts index 9b9ab34a6..453d459ba 100644 --- a/src/addons/mod/quiz/components/index/index.ts +++ b/src/addons/mod/quiz/components/index/index.ts @@ -23,7 +23,7 @@ import { IonContent } from '@ionic/angular'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { AddonModQuizPrefetchHandler } from '../../services/handlers/prefetch'; @@ -200,7 +200,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp if (AddonModQuiz.isQuizOffline(quiz)) { if (sync) { // Try to sync the quiz. - await CoreUtils.ignoreErrors(this.syncActivity(showErrors)); + await CorePromiseUtils.ignoreErrors(this.syncActivity(showErrors)); } } else { this.showStatusSpinner = false; @@ -375,7 +375,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp return; // Shouldn't happen. } - await CoreUtils.ignoreErrors(AddonModQuiz.logViewQuiz(this.quiz.id)); + await CorePromiseUtils.ignoreErrors(AddonModQuiz.logViewQuiz(this.quiz.id)); this.analyticsLogEvent('mod_quiz_view_quiz'); } @@ -440,7 +440,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp this.showLoading = true; this.content?.scrollToTop(); - await CoreUtils.ignoreErrors(this.refreshContent(true)); + await CorePromiseUtils.ignoreErrors(this.refreshContent(true)); this.showLoading = false; this.autoReview = undefined; diff --git a/src/addons/mod/quiz/pages/player/player.ts b/src/addons/mod/quiz/pages/player/player.ts index b3b6db147..b15811d56 100644 --- a/src/addons/mod/quiz/pages/player/player.ts +++ b/src/addons/mod/quiz/pages/player/player.ts @@ -28,7 +28,7 @@ import { CoreNavigator } from '@services/navigator'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ModalController, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { AddonModQuizAutoSave } from '../../classes/auto-save'; @@ -617,7 +617,7 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave { return; } - await CoreUtils.ignoreErrors(AddonModQuiz.logViewAttempt(this.attempt.id, page, this.preflightData, this.offline)); + await CorePromiseUtils.ignoreErrors(AddonModQuiz.logViewAttempt(this.attempt.id, page, this.preflightData, this.offline)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, @@ -636,7 +636,7 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave { return; } - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( AddonModQuiz.logViewAttemptSummary(this.attempt.id, this.preflightData, this.quiz.id), ); @@ -735,7 +735,7 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave { // Some data has changed, reload the navigation. const modal = await CoreLoadings.show(); - await CoreUtils.ignoreErrors(this.loadNavigation()); + await CorePromiseUtils.ignoreErrors(this.loadNavigation()); modal.dismiss(); this.reloadNavigation = false; diff --git a/src/addons/mod/quiz/pages/review/review.ts b/src/addons/mod/quiz/pages/review/review.ts index 653475dce..da4db89ae 100644 --- a/src/addons/mod/quiz/pages/review/review.ts +++ b/src/addons/mod/quiz/pages/review/review.ts @@ -18,7 +18,7 @@ import { CoreQuestionHelper } from '@features/question/services/question-helper' import { IonContent } from '@ionic/angular'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreDom } from '@singletons/dom'; import { CoreTime } from '@singletons/time'; import { @@ -231,7 +231,7 @@ export class AddonModQuizReviewPage implements OnInit { promises.push(AddonModQuiz.invalidateCombinedReviewOptionsForUser(this.quiz.id)); } - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); try { await this.fetchData(); @@ -299,7 +299,7 @@ export class AddonModQuizReviewPage implements OnInit { } if (logInLMS) { - await CoreUtils.ignoreErrors(AddonModQuiz.logViewAttemptReview(this.attemptId, this.quiz.id)); + await CorePromiseUtils.ignoreErrors(AddonModQuiz.logViewAttemptReview(this.attemptId, this.quiz.id)); } let url = `/mod/quiz/review.php?attempt=${this.attemptId}&cmid=${this.cmId}`; diff --git a/src/addons/mod/quiz/services/access-rules-delegate.ts b/src/addons/mod/quiz/services/access-rules-delegate.ts index dc666d800..40b5f0c01 100644 --- a/src/addons/mod/quiz/services/access-rules-delegate.ts +++ b/src/addons/mod/quiz/services/access-rules-delegate.ts @@ -15,7 +15,7 @@ import { Injectable, Type } from '@angular/core'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { AddonModQuizAttemptWSData, AddonModQuizQuizWSData } from './quiz'; import { CoreSites } from '@services/sites'; @@ -171,9 +171,9 @@ export class AddonModQuizAccessRuleDelegateService extends CoreDelegate { rules = rules || []; - await CoreUtils.ignoreErrors(CoreUtils.allPromises(rules.map(async (rule) => { + await CorePromiseUtils.allPromisesIgnoringErrors(rules.map(async (rule) => { await this.executeFunctionOnEnabled(rule, 'getFixedPreflightData', [quiz, preflightData, attempt, prefetch, siteId]); - }))); + })); } /** @@ -216,11 +216,11 @@ export class AddonModQuizAccessRuleDelegateService extends CoreDelegate { + await CorePromiseUtils.allPromisesIgnoringErrors(rules.map(async (rule) => { const ruleRequired = await this.isPreflightCheckRequiredForRule(rule, quiz, attempt, prefetch, siteId); isRequired = isRequired || ruleRequired; - }))); + })); return isRequired; } @@ -268,13 +268,13 @@ export class AddonModQuizAccessRuleDelegateService extends CoreDelegate { rules = rules || []; - await CoreUtils.ignoreErrors(CoreUtils.allPromises(rules.map(async (rule) => { + await CorePromiseUtils.allPromisesIgnoringErrors(rules.map(async (rule) => { await this.executeFunctionOnEnabled( rule, 'notifyPreflightCheckPassed', [quiz, attempt, preflightData, prefetch, siteId], ); - }))); + })); } /** @@ -298,13 +298,13 @@ export class AddonModQuizAccessRuleDelegateService extends CoreDelegate { rules = rules || []; - await CoreUtils.ignoreErrors(CoreUtils.allPromises(rules.map(async (rule) => { + await CorePromiseUtils.allPromisesIgnoringErrors(rules.map(async (rule) => { await this.executeFunctionOnEnabled( rule, 'notifyPreflightCheckFailed', [quiz, attempt, preflightData, prefetch, siteId], ); - }))); + })); } /** diff --git a/src/addons/mod/quiz/services/handlers/prefetch.ts b/src/addons/mod/quiz/services/handlers/prefetch.ts index 14fd3ad8e..bb51503b2 100644 --- a/src/addons/mod/quiz/services/handlers/prefetch.ts +++ b/src/addons/mod/quiz/services/handlers/prefetch.ts @@ -24,7 +24,7 @@ import { CoreQuestionHelper } from '@features/question/services/question-helper' import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModQuizAccessRuleDelegate } from '../access-rules-delegate'; @@ -358,7 +358,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet })); // Update the download time to prevent detecting the new attempt as an update. - promises.push(CoreUtils.ignoreErrors( + promises.push(CorePromiseUtils.ignoreErrors( CoreFilepool.updatePackageDownloadTime(siteId, ADDON_MOD_QUIZ_COMPONENT, module.id), )); } else { @@ -374,7 +374,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet promises.push(AddonModQuiz.getAttemptAccessInformation(quiz.id, 0, modOptions)); // Last attempt. // Get course data, needed to determine upload max size if it's configured to be course limit. - promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + promises.push(CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); await Promise.all(promises); @@ -493,7 +493,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet // Get the review for each page. pages.forEach((page) => { - promises.push(CoreUtils.ignoreErrors(AddonModQuiz.getAttemptReview(attempt.id, { + promises.push(CorePromiseUtils.ignoreErrors(AddonModQuiz.getAttemptReview(attempt.id, { page, ...modOptions, // Include all options. }))); @@ -519,7 +519,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet modOptions: CoreCourseCommonModWSOptions, ): Promise { // Get the review for all questions in same page. - const data = await CoreUtils.ignoreErrors(AddonModQuiz.getAttemptReview(attempt.id, { + const data = await CorePromiseUtils.ignoreErrors(AddonModQuiz.getAttemptReview(attempt.id, { page: -1, ...modOptions, // Include all options. })); diff --git a/src/addons/mod/quiz/services/handlers/push-click.ts b/src/addons/mod/quiz/services/handlers/push-click.ts index 22e7e10e4..54e71a1aa 100644 --- a/src/addons/mod/quiz/services/handlers/push-click.ts +++ b/src/addons/mod/quiz/services/handlers/push-click.ts @@ -24,6 +24,7 @@ import { AddonModQuiz } from '../quiz'; import { AddonModQuizHelper } from '../quiz-helper'; import { isSafeNumber } from '@/core/utils/types'; import { ADDON_MOD_QUIZ_FEATURE_NAME } from '../../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler for quiz push notifications clicks. @@ -81,7 +82,7 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification return; } - await CoreUtils.ignoreErrors(AddonModQuiz.invalidateContent(moduleId, courseId, notification.site)); + await CorePromiseUtils.ignoreErrors(AddonModQuiz.invalidateContent(moduleId, courseId, notification.site)); return CoreCourseHelper.navigateToModule(moduleId, { courseId, diff --git a/src/addons/mod/quiz/services/quiz-helper.ts b/src/addons/mod/quiz/services/quiz-helper.ts index d1461a886..8e9ae6d2c 100644 --- a/src/addons/mod/quiz/services/quiz-helper.ts +++ b/src/addons/mod/quiz/services/quiz-helper.ts @@ -43,6 +43,7 @@ import { CoreTimeUtils } from '@services/utils/time'; import { CoreModals } from '@services/modals'; import { CoreLoadings } from '@services/loadings'; import { convertTextToHTMLElement } from '@/core/utils/create-html-element'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Helper service that provides some features for quiz. @@ -474,7 +475,7 @@ export class AddonModQuizHelperProvider { if (options.offline) { // Get current page stored in local. - const storedAttempt = await CoreUtils.ignoreErrors( + const storedAttempt = await CorePromiseUtils.ignoreErrors( AddonModQuizOffline.getAttemptById(attempt.id), ); diff --git a/src/addons/mod/quiz/services/quiz-offline.ts b/src/addons/mod/quiz/services/quiz-offline.ts index 94354859b..ff98e646a 100644 --- a/src/addons/mod/quiz/services/quiz-offline.ts +++ b/src/addons/mod/quiz/services/quiz-offline.ts @@ -19,7 +19,7 @@ import { CoreQuestionAnswerDBRecord } from '@features/question/services/database import { CoreQuestion, CoreQuestionQuestionParsed, CoreQuestionsAnswers } from '@features/question/services/question'; import { CoreSites } from '@services/sites'; import { CoreTimeUtils } from '@services/utils/time'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton, Translate } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { AddonModQuizAttemptDBRecord, ATTEMPTS_TABLE_NAME } from './database/quiz'; @@ -149,7 +149,7 @@ export class AddonModQuizOfflineProvider { ): Promise { await Promise.all(questions.map(async (question) => { - const dbQuestion = await CoreUtils.ignoreErrors( + const dbQuestion = await CorePromiseUtils.ignoreErrors( CoreQuestion.getQuestion(ADDON_MOD_QUIZ_COMPONENT, attemptId, question.slot, siteId), ); @@ -192,7 +192,7 @@ export class AddonModQuizOfflineProvider { const db = await CoreSites.getSiteDb(siteId); // Check if an attempt already exists. Return a new one if it doesn't. - let entry = await CoreUtils.ignoreErrors(this.getAttemptById(attempt.id, siteId)); + let entry = await CorePromiseUtils.ignoreErrors(this.getAttemptById(attempt.id, siteId)); if (entry) { entry.timemodified = now; @@ -329,7 +329,7 @@ export class AddonModQuizOfflineProvider { try { // Answers have been saved, now we can save the questions with the states. - await CoreUtils.allPromises(Object.keys(newStates).map(async (slot) => { + await CorePromiseUtils.allPromises(Object.keys(newStates).map(async (slot) => { const question = questionsWithAnswers[Number(slot)]; await CoreQuestion.saveQuestion( diff --git a/src/addons/mod/quiz/services/quiz-sync.ts b/src/addons/mod/quiz/services/quiz-sync.ts index 370a8c81f..400dedbaa 100644 --- a/src/addons/mod/quiz/services/quiz-sync.ts +++ b/src/addons/mod/quiz/services/quiz-sync.ts @@ -24,7 +24,7 @@ import { CoreQuestionDelegate } from '@features/question/services/question-deleg import { CoreNetwork } from '@services/network'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync, CoreSyncResult } from '@services/sync'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { AddonModQuizAttemptDBRecord } from './database/quiz'; @@ -65,7 +65,7 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider options = options || {}; // Invalidate the data for the quiz and attempt. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( AddonModQuiz.invalidateAllQuizData(quiz.id, courseId, options.attemptId, siteId), ); @@ -99,7 +99,7 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider } } - await CoreUtils.ignoreErrors(this.setSyncTime(quiz.id, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(quiz.id, siteId)); // Check if online attempt was finished because of the sync. let attemptFinished = false; @@ -298,7 +298,7 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider this.logger.debug('Try to sync quiz ' + quiz.id + ' in site ' + siteId); // Sync offline logs. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreCourseLogHelper.syncActivity(ADDON_MOD_QUIZ_COMPONENT, quiz.id, siteId), ); @@ -403,7 +403,7 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider if (!finish) { // Answers sent, now set the current page. - await CoreUtils.ignoreErrors(AddonModQuiz.logViewAttempt( + await CorePromiseUtils.ignoreErrors(AddonModQuiz.logViewAttempt( onlineAttempt.id, offlineAttempt.currentpage, preflightData, diff --git a/src/addons/mod/resource/components/index/index.ts b/src/addons/mod/resource/components/index/index.ts index b392828a4..1af37bd5a 100644 --- a/src/addons/mod/resource/components/index/index.ts +++ b/src/addons/mod/resource/components/index/index.ts @@ -35,6 +35,7 @@ import { import { AddonModResourceHelper } from '../../services/resource-helper'; import { CorePlatform } from '@services/platform'; import { ADDON_MOD_RESOURCE_COMPONENT } from '../../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component that displays a resource. @@ -191,7 +192,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource * @inheritdoc */ protected async logActivity(): Promise { - await CoreUtils.ignoreErrors(AddonModResource.logView(this.module.instance)); + await CorePromiseUtils.ignoreErrors(AddonModResource.logView(this.module.instance)); this.analyticsLogEvent('mod_resource_view_resource'); } diff --git a/src/addons/mod/resource/services/handlers/module.ts b/src/addons/mod/resource/services/handlers/module.ts index f94293609..8c97dd531 100644 --- a/src/addons/mod/resource/services/handlers/module.ts +++ b/src/addons/mod/resource/services/handlers/module.ts @@ -24,7 +24,7 @@ import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { makeSingleton, Translate } from '@singletons'; import { AddonModResource } from '../resource'; import { AddonModResourceHelper } from '../resource-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ADDON_MOD_RESOURCE_PAGE_NAME } from '../../constants'; /** @@ -92,8 +92,8 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase }; const [hideButton, extraBadge] = await Promise.all([ - CoreUtils.ignoreErrors(this.hideOpenButton(module)), - CoreUtils.ignoreErrors(AddonModResourceHelper.getAfterLinkDetails(module, courseId)), + CorePromiseUtils.ignoreErrors(this.hideOpenButton(module)), + CorePromiseUtils.ignoreErrors(AddonModResourceHelper.getAfterLinkDetails(module, courseId)), ]); // Check if the button needs to be shown or not. diff --git a/src/addons/mod/resource/services/resource.ts b/src/addons/mod/resource/services/resource.ts index 302a77170..ef5702d95 100644 --- a/src/addons/mod/resource/services/resource.ts +++ b/src/addons/mod/resource/services/resource.ts @@ -19,7 +19,7 @@ import { CoreCourse } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { ADDON_MOD_RESOURCE_COMPONENT } from '../constants'; @@ -114,7 +114,7 @@ export class AddonModResourceProvider { promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_RESOURCE_COMPONENT, moduleId)); promises.push(CoreCourse.invalidateModule(moduleId, siteId, 'resource')); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/scorm/components/index/index.ts b/src/addons/mod/scorm/components/index/index.ts index 3c2e7026a..15ce952c3 100644 --- a/src/addons/mod/scorm/components/index/index.ts +++ b/src/addons/mod/scorm/components/index/index.ts @@ -50,6 +50,7 @@ import { ADDON_MOD_SCORM_PAGE_NAME, } from '../../constants'; import { CoreWait } from '@singletons/wait'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component that displays a SCORM entry page. @@ -188,7 +189,7 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom if (sync) { // Try to synchronize the SCORM. - await CoreUtils.ignoreErrors(this.syncActivity(showErrors)); + await CorePromiseUtils.ignoreErrors(this.syncActivity(showErrors)); } const [syncTime, accessInfo] = await Promise.all([ @@ -363,7 +364,7 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom return; // Shouldn't happen. } - await CoreUtils.ignoreErrors(AddonModScorm.logView(this.scorm.id)); + await CorePromiseUtils.ignoreErrors(AddonModScorm.logView(this.scorm.id)); this.analyticsLogEvent('mod_scorm_view_scorm'); } @@ -516,7 +517,7 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom await AddonModScormHelper.confirmDownload(scorm, isOutdated); // Invalidate WS data if SCORM is outdated. if (isOutdated) { - await CoreUtils.ignoreErrors(AddonModScorm.invalidateAllScormData(scorm.id)); + await CorePromiseUtils.ignoreErrors(AddonModScorm.invalidateAllScormData(scorm.id)); } try { @@ -626,7 +627,7 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom if (!result.updated && this.dataSent) { // The user sent data to server, but not in the sync process. Check if we need to fetch data. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( AddonModScormSync.prefetchAfterUpdate(AddonModScormPrefetchHandler.instance, this.module, this.courseId), ); } diff --git a/src/addons/mod/scorm/pages/player/player.ts b/src/addons/mod/scorm/pages/player/player.ts index e3d29384d..7d6cd920a 100644 --- a/src/addons/mod/scorm/pages/player/player.ts +++ b/src/addons/mod/scorm/pages/player/player.ts @@ -20,7 +20,7 @@ import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreTimeUtils } from '@services/utils/time'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { AddonModScormDataModel12 } from '../../classes/data-model-12'; import { @@ -540,7 +540,7 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy { */ protected async refreshToc(): Promise { try { - await CoreUtils.ignoreErrors(AddonModScorm.invalidateAllScormData(this.scorm.id)); + await CorePromiseUtils.ignoreErrors(AddonModScorm.invalidateAllScormData(this.scorm.id)); await this.fetchToc(); } catch (error) { @@ -571,7 +571,7 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy { } // New online attempt created, update cached data about online attempts. - await CoreUtils.ignoreErrors(AddonModScorm.getAttemptCount(this.scorm.id, { + await CorePromiseUtils.ignoreErrors(AddonModScorm.getAttemptCount(this.scorm.id, { cmId: this.cmId, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, })); @@ -581,7 +581,7 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy { * Log event. */ protected async logEvent(scoId: number): Promise { - await CoreUtils.ignoreErrors(AddonModScorm.logLaunchSco(this.scorm.id, scoId)); + await CorePromiseUtils.ignoreErrors(AddonModScorm.logLaunchSco(this.scorm.id, scoId)); let url = '/mod/scorm/player.php'; if (this.scorm.popup) { diff --git a/src/addons/mod/scorm/services/handlers/prefetch.ts b/src/addons/mod/scorm/services/handlers/prefetch.ts index eb5b03f81..bd31f7e15 100644 --- a/src/addons/mod/scorm/services/handlers/prefetch.ts +++ b/src/addons/mod/scorm/services/handlers/prefetch.ts @@ -21,7 +21,7 @@ import { CoreFilepool } from '@services/filepool'; import { CorePlatform } from '@services/platform'; import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { AddonModScorm, AddonModScormScorm } from '../scorm'; @@ -84,9 +84,11 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe this.downloadOrPrefetchMainFileIfNeeded(scorm, prefetch, onProgress, siteId), // Download WS data. If it fails we don't want to fail the whole download, so we'll ignore the error for now. // @todo Implement a warning system so the user knows which SCORMs have failed. - CoreUtils.ignoreErrors(this.fetchWSData(scorm, siteId)), + CorePromiseUtils.ignoreErrors(this.fetchWSData(scorm, siteId)), // Download intro files, ignoring errors. - CoreUtils.ignoreErrors(CoreFilepool.downloadOrPrefetchFiles(siteId, files, prefetch, false, this.component, module.id)), + CorePromiseUtils.ignoreErrors( + CoreFilepool.downloadOrPrefetchFiles(siteId, files, prefetch, false, this.component, module.id), + ), ]); // Success, return the hash. @@ -154,7 +156,7 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe (event: ProgressEvent) => this.downloadProgress(false, onProgress, event), ); - await CoreUtils.ignoreErrors(CoreFilepool.removeFileByUrl(siteId, packageUrl)); + await CorePromiseUtils.ignoreErrors(CoreFilepool.removeFileByUrl(siteId, packageUrl)); } /** @@ -238,7 +240,7 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe */ async fetchAttempts(scorm: AddonModScormScorm, modOptions: CoreCourseCommonModWSOptions): Promise { // If it fails, assume we have no attempts. - const numAttempts = await CoreUtils.ignoreErrors(AddonModScorm.getAttemptCountOnline(scorm.id, modOptions), 0); + const numAttempts = await CorePromiseUtils.ignoreErrors(AddonModScorm.getAttemptCountOnline(scorm.id, modOptions), 0); if (numAttempts <= 0) { // No attempts. We'll still try to get user data to be able to identify SCOs not visible and so. diff --git a/src/addons/mod/scorm/services/scorm-helper.ts b/src/addons/mod/scorm/services/scorm-helper.ts index 2986d3b99..c624f808c 100644 --- a/src/addons/mod/scorm/services/scorm-helper.ts +++ b/src/addons/mod/scorm/services/scorm-helper.ts @@ -33,6 +33,7 @@ import { } from './scorm'; import { AddonModScormOffline } from './scorm-offline'; import { AddonModScormMode } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; // List of elements we want to ignore when copying attempts (they're calculated). const elementsToIgnore = [ @@ -86,7 +87,7 @@ export class AddonModScormHelperProvider { siteId = siteId || CoreSites.getCurrentSiteId(); // Get data from the online attempt. - const onlineData = await CoreUtils.ignoreErrors( + const onlineData = await CorePromiseUtils.ignoreErrors( AddonModScorm.getScormUserData(scorm.id, attempt, { cmId: scorm.coursemodule, siteId }), ); @@ -97,7 +98,7 @@ export class AddonModScormHelperProvider { // The SCORM API might have written some data to the offline attempt already. // We don't want to override it with cached online data. - const offlineData = await CoreUtils.ignoreErrors( + const offlineData = await CorePromiseUtils.ignoreErrors( AddonModScormOffline.getScormUserData(scorm.id, attempt, undefined, siteId), ); @@ -143,7 +144,7 @@ export class AddonModScormHelperProvider { siteId = siteId || CoreSites.getCurrentSiteId(); // Try to get data from online attempts. - const userData = await CoreUtils.ignoreErrors( + const userData = await CorePromiseUtils.ignoreErrors( this.searchOnlineAttemptUserData(scorm.id, lastOnline, { cmId: scorm.coursemodule, siteId }), ); diff --git a/src/addons/mod/scorm/services/scorm-offline.ts b/src/addons/mod/scorm/services/scorm-offline.ts index 9ba1aa1f5..6fa4a36ed 100644 --- a/src/addons/mod/scorm/services/scorm-offline.ts +++ b/src/addons/mod/scorm/services/scorm-offline.ts @@ -45,6 +45,7 @@ import { asyncInstance, AsyncInstance } from '@/core/utils/async-instance'; import { CoreDatabaseTable } from '@classes/database/database-table'; import { CoreDatabaseCachingStrategy } from '@classes/database/database-table-proxy'; import { ADDON_MOD_SCORM_COMPONENT } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to handle offline SCORM. @@ -508,7 +509,7 @@ export class AddonModScormOfflineProvider { fullName = site.getInfo()?.fullname || ''; userName = site.getInfo()?.username || ''; } else { - const profile = await CoreUtils.ignoreErrors(CoreUser.getProfile(userId)); + const profile = await CorePromiseUtils.ignoreErrors(CoreUser.getProfile(userId)); fullName = profile?.fullname || ''; userName = profile?.username || ''; diff --git a/src/addons/mod/scorm/services/scorm-sync.ts b/src/addons/mod/scorm/services/scorm-sync.ts index 02e53d0fe..5a40a0f35 100644 --- a/src/addons/mod/scorm/services/scorm-sync.ts +++ b/src/addons/mod/scorm/services/scorm-sync.ts @@ -19,7 +19,7 @@ import { CoreCourse } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync, CoreSyncResult } from '@services/sync'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { AddonModScormPrefetchHandler } from './handlers/prefetch'; @@ -91,7 +91,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide // It can't be added because the last offline attempt is incomplete, delete it. this.logger.debug(`Try to delete attempt ${attempt} because it cannot be created as a new attempt.`); - await CoreUtils.ignoreErrors(AddonModScormOffline.deleteAttempt(scormId, attempt, siteId)); + await CorePromiseUtils.ignoreErrors(AddonModScormOffline.deleteAttempt(scormId, attempt, siteId)); // eslint-disable-next-line id-blacklist warnings.push(Translate.instant('addon.mod_scorm.warningofflinedatadeleted', { number: attempt })); @@ -159,7 +159,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide return; } - await CoreUtils.allPromises(times.map((time, index) => { + await CorePromiseUtils.allPromises(times.map((time, index) => { const attempt = newAttempts[time]; return AddonModScormOffline.changeAttemptNumber(scormId, attempt, lastOffline + index + 1, siteId); @@ -204,7 +204,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide } } - await CoreUtils.ignoreErrors(this.setSyncTime(scorm.id, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(scorm.id, siteId)); if (!initialCount) { return result; @@ -324,7 +324,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide } catch (error) { // Moving the new attempts failed (it shouldn't happen). Let's undo the new attempts move. - await CoreUtils.allPromises(successful.map((attempt) => { + await CorePromiseUtils.allPromises(successful.map((attempt) => { const newNumber = lastOnline + newAttempts.indexOf(attempt) + 1; return AddonModScormOffline.changeAttemptNumber(scormId, newNumber, attempt, siteId); @@ -369,7 +369,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide } catch { // Error getting user data from the site. We'll have to build it ourselves. // Let's try to get cached data about the attempt. - userData = await CoreUtils.ignoreErrors( + userData = await CorePromiseUtils.ignoreErrors( AddonModScorm.getScormUserData(scormId, attempt, { cmId, siteId }), {}, ); @@ -528,12 +528,12 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide await AddonModScorm.saveTracksOnline(scormId, scoId, attempt, tracks, siteId); // Sco data successfully sent. Mark them as synced. This is needed because some SCOs sync might fail. - await CoreUtils.ignoreErrors(AddonModScormOffline.markAsSynced(scormId, attempt, scoId, siteId)); + await CorePromiseUtils.ignoreErrors(AddonModScormOffline.markAsSynced(scormId, attempt, scoId, siteId)); somethingSynced = true; }); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } catch (error) { if (somethingSynced) { // Some SCOs have been synced and some not. @@ -549,7 +549,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide } // Attempt has been sent. Let's delete it from local. - await CoreUtils.ignoreErrors(AddonModScormOffline.deleteAttempt(scormId, attempt, siteId)); + await CorePromiseUtils.ignoreErrors(AddonModScormOffline.deleteAttempt(scormId, attempt, siteId)); } /** @@ -610,7 +610,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide let lastOnlineWasFinished = false; // Sync offline logs. - await CoreUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_SCORM_COMPONENT, scorm.id, siteId)); + await CorePromiseUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_SCORM_COMPONENT, scorm.id, siteId)); // Get attempts data. We ignore cache for online attempts, so this call will fail if offline or server down. const attemptsData = await AddonModScorm.getAttemptCount(scorm.id, { @@ -761,7 +761,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide if (!hasDataToSend) { // Nothing to sync, delete the attempt. - return CoreUtils.ignoreErrors(AddonModScormOffline.deleteAttempt(scormId, attempt, siteId)); + return CorePromiseUtils.ignoreErrors(AddonModScormOffline.deleteAttempt(scormId, attempt, siteId)); } // There are elements to sync. We need to check if it's possible to sync them or not. diff --git a/src/addons/mod/scorm/services/scorm.ts b/src/addons/mod/scorm/services/scorm.ts index 06ea99b1e..bdd236bbb 100644 --- a/src/addons/mod/scorm/services/scorm.ts +++ b/src/addons/mod/scorm/services/scorm.ts @@ -42,6 +42,7 @@ import { ADDON_MOD_SCORM_LAUNCH_PREV_SCO_EVENT, ADDON_MOD_SCORM_UPDATE_TOC_EVENT, } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; // Private constants. const VALID_STATUSES = ['notattempted', 'passed', 'completed', 'failed', 'incomplete', 'browsed', 'suspend']; @@ -1635,7 +1636,7 @@ export class AddonModScormProvider { if (isOutdated === undefined) { // Calculate if it's outdated. - const data = await CoreUtils.ignoreErrors(CoreFilepool.getPackageData(siteId, component, scorm.coursemodule)); + const data = await CorePromiseUtils.ignoreErrors(CoreFilepool.getPackageData(siteId, component, scorm.coursemodule)); if (!data) { // Package not found, not downloaded. @@ -1650,7 +1651,7 @@ export class AddonModScormProvider { } else if (isOutdated) { // The package is outdated, but maybe the file hasn't changed. - const extra = await CoreUtils.ignoreErrors(CoreFilepool.getPackageExtra(siteId, component, scorm.coursemodule)); + const extra = await CorePromiseUtils.ignoreErrors(CoreFilepool.getPackageExtra(siteId, component, scorm.coursemodule)); if (!extra) { // Package not found, not downloaded. diff --git a/src/addons/mod/survey/components/index/index.ts b/src/addons/mod/survey/components/index/index.ts index 4dea07acd..ab9bf61ed 100644 --- a/src/addons/mod/survey/components/index/index.ts +++ b/src/addons/mod/survey/components/index/index.ts @@ -36,7 +36,7 @@ import { AddonModSurveySync, AddonModSurveySyncResult, } from '../../services/survey-sync'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ADDON_MOD_SURVEY_AUTO_SYNCED, ADDON_MOD_SURVEY_COMPONENT } from '../../constants'; import { CoreLoadings } from '@services/loadings'; @@ -169,7 +169,7 @@ export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityCo return; // Shouldn't happen. } - await CoreUtils.ignoreErrors(AddonModSurvey.logView(this.survey.id)); + await CorePromiseUtils.ignoreErrors(AddonModSurvey.logView(this.survey.id)); this.analyticsLogEvent('mod_survey_view_survey'); } diff --git a/src/addons/mod/survey/services/handlers/prefetch-lazy.ts b/src/addons/mod/survey/services/handlers/prefetch-lazy.ts index 32b8120c9..cd7ea7a6e 100644 --- a/src/addons/mod/survey/services/handlers/prefetch-lazy.ts +++ b/src/addons/mod/survey/services/handlers/prefetch-lazy.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreFilepool } from '@services/filepool'; import { CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModSurvey } from '../survey'; @@ -34,7 +34,7 @@ export class AddonModSurveyPrefetchHandlerLazyService extends AddonModSurveyPref * @inheritdoc */ async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise { - const survey = await CoreUtils.ignoreErrors(AddonModSurvey.getSurvey(courseId, module.id)); + const survey = await CorePromiseUtils.ignoreErrors(AddonModSurvey.getSurvey(courseId, module.id)); return this.getIntroFilesFromInstance(module, survey); } diff --git a/src/addons/mod/survey/services/survey-sync.ts b/src/addons/mod/survey/services/survey-sync.ts index ff8d8d208..e814a7427 100644 --- a/src/addons/mod/survey/services/survey-sync.ts +++ b/src/addons/mod/survey/services/survey-sync.ts @@ -27,6 +27,7 @@ import { getPrefetchHandlerInstance } from './handlers/prefetch'; import { AddonModSurvey } from './survey'; import { AddonModSurveyAnswersDBRecordFormatted, AddonModSurveyOffline } from './survey-offline'; import { ADDON_MOD_SURVEY_AUTO_SYNCED, ADDON_MOD_SURVEY_COMPONENT } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync surveys. @@ -154,7 +155,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid }; // Sync offline logs. - CoreUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_SURVEY_COMPONENT, surveyId, siteId)); + CorePromiseUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_SURVEY_COMPONENT, surveyId, siteId)); let answersNumber = 0; let data: AddonModSurveyAnswersDBRecordFormatted | undefined; @@ -204,7 +205,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid // Data has been sent to server, update survey data. const module = await CoreCourse.getModuleBasicInfoByInstance(surveyId, 'survey', { siteId }); - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( this.prefetchAfterUpdate(getPrefetchHandlerInstance(), module, result.courseId, undefined, siteId), ); } @@ -212,7 +213,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid const syncId = this.getSyncId(surveyId, userId); // Sync finished, set sync time. - CoreUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); + CorePromiseUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); return result; } diff --git a/src/addons/mod/survey/services/survey.ts b/src/addons/mod/survey/services/survey.ts index 803012146..d781bdd4e 100644 --- a/src/addons/mod/survey/services/survey.ts +++ b/src/addons/mod/survey/services/survey.ts @@ -26,6 +26,7 @@ import { AddonModSurveyOffline } from './survey-offline'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { ADDON_MOD_SURVEY_COMPONENT } from '../constants'; import { CoreCacheUpdateFrequency } from '@/core/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service that provides some features for surveys. @@ -175,7 +176,7 @@ export class AddonModSurveyProvider { promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_SURVEY_COMPONENT, moduleId)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/url/services/handlers/module.ts b/src/addons/mod/url/services/handlers/module.ts index 1b35ed386..27512cf62 100644 --- a/src/addons/mod/url/services/handlers/module.ts +++ b/src/addons/mod/url/services/handlers/module.ts @@ -21,7 +21,7 @@ import { CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate'; import { CoreNavigationOptions } from '@services/navigator'; import { CoreLoadings } from '@services/loadings'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { AddonModUrl } from '../url'; import { AddonModUrlHelper } from '../url-helper'; @@ -215,7 +215,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple return true; } else { // Not handled by the app, check the display type. - const url = await CoreUtils.ignoreErrors(AddonModUrl.getUrl(module.course, module.id)); + const url = await CorePromiseUtils.ignoreErrors(AddonModUrl.getUrl(module.course, module.id)); const displayType = AddonModUrl.getFinalDisplayType(url); return displayType === CoreConstants.RESOURCELIB_DISPLAY_OPEN || diff --git a/src/addons/mod/url/services/url.ts b/src/addons/mod/url/services/url.ts index 0e3ba3b3c..6dc4f4390 100644 --- a/src/addons/mod/url/services/url.ts +++ b/src/addons/mod/url/services/url.ts @@ -19,7 +19,7 @@ import { makeSingleton, Translate } from '@singletons'; import { CoreCacheUpdateFrequency, CoreConstants } from '@/core/constants'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreCourse } from '@features/course/services/course'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreError } from '@classes/errors/error'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; @@ -189,7 +189,7 @@ export class AddonModUrlProvider { promises.push(this.invalidateUrlData(courseId, siteId)); promises.push(CoreCourse.invalidateModule(moduleId, siteId, 'url')); - return CoreUtils.allPromises(promises); + return CorePromiseUtils.allPromises(promises); } /** diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index 62e99a9b5..77bef4766 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -26,7 +26,7 @@ import { CoreGroup, CoreGroups } from '@services/groups'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate, NgZone } from '@singletons'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CorePath } from '@singletons/path'; @@ -228,7 +228,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp if (sync) { // Try to synchronize the wiki. - await CoreUtils.ignoreErrors(this.syncActivity(showErrors)); + await CorePromiseUtils.ignoreErrors(this.syncActivity(showErrors)); } if (this.pageWarning) { @@ -496,7 +496,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp return; // Shouldn't happen. } - await CoreUtils.ignoreErrors(AddonModWiki.logPageView(pageId, this.wiki.id)); + await CorePromiseUtils.ignoreErrors(AddonModWiki.logPageView(pageId, this.wiki.id)); this.analyticsLogEvent('mod_wiki_view_page', { name: this.currentPageObj?.title, diff --git a/src/addons/mod/wiki/pages/edit/edit.ts b/src/addons/mod/wiki/pages/edit/edit.ts index c9d11962f..daf0e2d40 100644 --- a/src/addons/mod/wiki/pages/edit/edit.ts +++ b/src/addons/mod/wiki/pages/edit/edit.ts @@ -22,7 +22,7 @@ import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; @@ -224,7 +224,7 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave { } // Check if there's already some offline data for this page. - const page = await CoreUtils.ignoreErrors( + const page = await CorePromiseUtils.ignoreErrors( AddonModWikiOffline.getNewPage(pageTitle, this.subwikiId, this.wikiId, this.userId, this.groupId), ); @@ -396,7 +396,7 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave { if (!this.editOffline) { // Check if the user has an offline page with the same title. - const page = await CoreUtils.ignoreErrors( + const page = await CorePromiseUtils.ignoreErrors( AddonModWikiOffline.getNewPage(title, this.subwikiId, this.wikiId, this.userId, this.groupId), ); @@ -442,7 +442,7 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave { this.userId = pageContents.userid; this.groupId = pageContents.groupid; - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); // Notify page created. CoreEvents.trigger(ADDON_MOD_WIKI_PAGE_CREATED_EVENT, { diff --git a/src/addons/mod/wiki/services/handlers/prefetch-lazy.ts b/src/addons/mod/wiki/services/handlers/prefetch-lazy.ts index d3629b3b9..97c50fee6 100644 --- a/src/addons/mod/wiki/services/handlers/prefetch-lazy.ts +++ b/src/addons/mod/wiki/services/handlers/prefetch-lazy.ts @@ -18,7 +18,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreGroups } from '@services/groups'; import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; import { AddonModWiki, AddonModWikiSubwikiPage } from '../wiki'; @@ -128,7 +128,7 @@ export class AddonModWikiPrefetchHandlerLazyService extends AddonModWikiPrefetch // Get the download time of the package before starting the download (otherwise we'd always get current time). const siteId = CoreSites.getCurrentSiteId(); - const data = await CoreUtils.ignoreErrors(CoreFilepool.getPackageData(siteId, this.component, module.id)); + const data = await CorePromiseUtils.ignoreErrors(CoreFilepool.getPackageData(siteId, this.component, module.id)); const downloadTime = data?.downloadTime || 0; diff --git a/src/addons/mod/wiki/services/wiki-sync.ts b/src/addons/mod/wiki/services/wiki-sync.ts index 79ab18dbd..82ab78842 100644 --- a/src/addons/mod/wiki/services/wiki-sync.ts +++ b/src/addons/mod/wiki/services/wiki-sync.ts @@ -27,6 +27,7 @@ import { AddonModWikiPageDBRecord } from './database/wiki'; import { AddonModWiki } from './wiki'; import { AddonModWikiOffline } from './wiki-offline'; import { ADDON_MOD_WIKI_AUTO_SYNCED, ADDON_MOD_WIKI_COMPONENT, ADDON_MOD_WIKI_MANUAL_SYNCED } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync wikis. @@ -210,14 +211,14 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider [], ); if (!pages || !pages.length) { // Nothing to sync. - await CoreUtils.ignoreErrors(this.setSyncTime(subwikiBlockId, siteId)); + await CorePromiseUtils.ignoreErrors(this.setSyncTime(subwikiBlockId, siteId)); return result; } @@ -270,7 +271,7 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider => { if (options.wikiId && options.subwikiId) { // We have wiki ID, check if there's already an online page with this title and subwiki. - const used = await CoreUtils.ignoreErrors(this.isTitleUsed(options.wikiId, options.subwikiId, title, { + const used = await CorePromiseUtils.ignoreErrors(this.isTitleUsed(options.wikiId, options.subwikiId, title, { cmId: options.cmId, readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE, siteId: options.siteId, diff --git a/src/addons/mod/workshop/components/assessment-strategy/assessment-strategy.ts b/src/addons/mod/workshop/components/assessment-strategy/assessment-strategy.ts index 2ae834566..cbb5f7696 100644 --- a/src/addons/mod/workshop/components/assessment-strategy/assessment-strategy.ts +++ b/src/addons/mod/workshop/components/assessment-strategy/assessment-strategy.ts @@ -43,6 +43,7 @@ import { } from '@addons/mod/workshop/constants'; import { toBoolean } from '@/core/transforms/boolean'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component that displays workshop assessment strategy form. @@ -384,7 +385,7 @@ export class AddonModWorkshopAssessmentStrategyComponent implements OnInit, OnDe promises.push(AddonModWorkshop.invalidateAssessmentData(this.workshop.id, this.assessmentId)); } - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); CoreEvents.trigger(ADDON_MOD_WORKSHOP_ASSESSMENT_SAVED, { workshopId: this.workshop.id, diff --git a/src/addons/mod/workshop/components/index/index.ts b/src/addons/mod/workshop/components/index/index.ts index ee4337778..173989eb7 100644 --- a/src/addons/mod/workshop/components/index/index.ts +++ b/src/addons/mod/workshop/components/index/index.ts @@ -57,6 +57,7 @@ import { ADDON_MOD_WORKSHOP_SUBMISSION_CHANGED, AddonModWorkshopPhase, } from '@addons/mod/workshop/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component that displays a workshop index page. @@ -259,7 +260,7 @@ export class AddonModWorkshopIndexComponent extends CoreCourseModuleMainActivity return; // Shouldn't happen. } - await CoreUtils.ignoreErrors(AddonModWorkshop.logView(this.workshop.id)); + await CorePromiseUtils.ignoreErrors(AddonModWorkshop.logView(this.workshop.id)); this.analyticsLogEvent('mod_workshop_view_workshop'); } diff --git a/src/addons/mod/workshop/services/handlers/prefetch-lazy.ts b/src/addons/mod/workshop/services/handlers/prefetch-lazy.ts index 0e69b40aa..d31b1492b 100644 --- a/src/addons/mod/workshop/services/handlers/prefetch-lazy.ts +++ b/src/addons/mod/workshop/services/handlers/prefetch-lazy.ts @@ -33,6 +33,7 @@ import { AddonModWorkshopHelper } from '../workshop-helper'; import { AddonModWorkshopSync } from '../workshop-sync'; import { AddonModWorkshopPrefetchHandlerService } from '@addons/mod/workshop/services/handlers/prefetch'; import { AddonModWorkshopPhase } from '../../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler to prefetch workshops. @@ -379,7 +380,7 @@ export class AddonModWorkshopPrefetchHandlerLazyService extends AddonModWorkshop promises.push(CoreCourse.getModuleBasicGradeInfo(module.id, siteId)); // Get course data, needed to determine upload max size if it's configured to be course limit. - promises.push(CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); + promises.push(CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', courseId, siteId))); await Promise.all(promises); diff --git a/src/addons/mod/workshop/services/workshop-helper.ts b/src/addons/mod/workshop/services/workshop-helper.ts index b05349d08..e78f9c61a 100644 --- a/src/addons/mod/workshop/services/workshop-helper.ts +++ b/src/addons/mod/workshop/services/workshop-helper.ts @@ -44,6 +44,7 @@ import { AddonModWorkshopOverallFeedbackMode, AddonModWorkshopPhase, } from '@addons/mod/workshop/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Helper to gather some common functions for workshop. @@ -241,7 +242,7 @@ export class AddonModWorkshopHelperProvider { const folderPath = await AddonModWorkshopOffline.getSubmissionFolder(workshopId, siteId); // Ignore any errors, CoreFile.removeDir fails if folder doesn't exists. - await CoreUtils.ignoreErrors(CoreFile.removeDir(folderPath)); + await CorePromiseUtils.ignoreErrors(CoreFile.removeDir(folderPath)); } /** @@ -312,7 +313,7 @@ export class AddonModWorkshopHelperProvider { const folderPath = await AddonModWorkshopOffline.getSubmissionFolder(workshopId, siteId); // Ignore not found files. - return CoreUtils.ignoreErrors(CoreFileUploader.getStoredFiles(folderPath), []); + return CorePromiseUtils.ignoreErrors(CoreFileUploader.getStoredFiles(folderPath), []); } /** @@ -345,7 +346,7 @@ export class AddonModWorkshopHelperProvider { const folderPath = await AddonModWorkshopOffline.getAssessmentFolder(workshopId, assessmentId, siteId); // Ignore any errors, CoreFile.removeDir fails if folder doesn't exists. - await CoreUtils.ignoreErrors(CoreFile.removeDir(folderPath)); + await CorePromiseUtils.ignoreErrors(CoreFile.removeDir(folderPath)); } /** @@ -420,7 +421,7 @@ export class AddonModWorkshopHelperProvider { const folderPath = await AddonModWorkshopOffline.getAssessmentFolder(workshopId, assessmentId, siteId); // Ignore not found files. - return CoreUtils.ignoreErrors(CoreFileUploader.getStoredFiles(folderPath), []); + return CorePromiseUtils.ignoreErrors(CoreFileUploader.getStoredFiles(folderPath), []); } /** diff --git a/src/addons/mod/workshop/services/workshop-sync.ts b/src/addons/mod/workshop/services/workshop-sync.ts index d7c7f9420..c949cb5c1 100644 --- a/src/addons/mod/workshop/services/workshop-sync.ts +++ b/src/addons/mod/workshop/services/workshop-sync.ts @@ -41,6 +41,7 @@ import { AddonModWorkshopAction, AddonModWorkshopSubmissionType, } from '@addons/mod/workshop/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync workshops. @@ -163,18 +164,18 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider { - await CoreUtils.ignoreErrors(AddonNotes.logView(this.courseId, this.userId)); + await CorePromiseUtils.ignoreErrors(AddonNotes.logView(this.courseId, this.userId)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM_LIST, diff --git a/src/addons/notes/services/notes-sync.ts b/src/addons/notes/services/notes-sync.ts index b02557293..1491360cc 100644 --- a/src/addons/notes/services/notes-sync.ts +++ b/src/addons/notes/services/notes-sync.ts @@ -28,6 +28,7 @@ import { CoreArray } from '@singletons/array'; import { CoreAnyError } from '@classes/errors/error'; import { CoreErrorHelper } from '@services/error-helper'; import { ADDON_NOTES_AUTO_SYNCED } from './constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync notes. @@ -223,13 +224,13 @@ export class AddonNotesSyncProvider extends CoreSyncBaseProvider Translate.instant('addon.notes.warningnotenotsent', { diff --git a/src/addons/notes/services/notes.ts b/src/addons/notes/services/notes.ts index 453cefdb2..89e935bad 100644 --- a/src/addons/notes/services/notes.ts +++ b/src/addons/notes/services/notes.ts @@ -23,6 +23,7 @@ import { makeSingleton, Translate } from '@singletons'; import { AddonNotesOffline } from './notes-offline'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { CoreCacheUpdateFrequency } from '@/core/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; const ROOT_CACHE_KEY = 'mmaNotes:'; @@ -111,7 +112,7 @@ export class AddonNotesProvider { throw new CoreWSError({ message: response[0].errormessage }); } - await CoreUtils.ignoreErrors(this.invalidateNotes(courseId, undefined, siteId)); + await CorePromiseUtils.ignoreErrors(this.invalidateNotes(courseId, undefined, siteId)); } /** @@ -199,7 +200,7 @@ export class AddonNotesProvider { await site.write('core_notes_delete_notes', params); - CoreUtils.ignoreErrors(this.invalidateNotes(courseId, undefined, siteId)); + CorePromiseUtils.ignoreErrors(this.invalidateNotes(courseId, undefined, siteId)); } /** @@ -246,7 +247,7 @@ export class AddonNotesProvider { // Use .read to cache data and be able to check it in offline. This means that, if a user loses the capabilities // to add notes, he'll still see the option in the app. - return CoreUtils.promiseWorks(site.read('core_notes_create_notes', params, preSets)); + return CorePromiseUtils.promiseWorks(site.read('core_notes_create_notes', params, preSets)); } /** @@ -257,7 +258,7 @@ export class AddonNotesProvider { * @returns Promise resolved with true if enabled, resolved with false or rejected otherwise. */ isPluginViewNotesEnabledForCourse(courseId: number, siteId?: string): Promise { - return CoreUtils.promiseWorks(this.getNotes(courseId, undefined, false, true, siteId)); + return CorePromiseUtils.promiseWorks(this.getNotes(courseId, undefined, false, true, siteId)); } /** diff --git a/src/addons/notifications/pages/list/list.ts b/src/addons/notifications/pages/list/list.ts index 79602218e..9eb6ac843 100644 --- a/src/addons/notifications/pages/list/list.ts +++ b/src/addons/notifications/pages/list/list.ts @@ -34,6 +34,7 @@ import { CoreLocalNotifications } from '@services/local-notifications'; import { CoreConfig } from '@services/config'; import { CoreConstants } from '@/core/constants'; import { CorePlatform } from '@services/platform'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays the list of notifications. @@ -192,7 +193,7 @@ export class AddonNotificationsListPage implements AfterViewInit, OnDestroy { async markAllNotificationsAsRead(): Promise { this.loadingMarkAllNotificationsAsRead = true; - await CoreUtils.ignoreErrors(AddonNotifications.markAllNotificationsAsRead()); + await CorePromiseUtils.ignoreErrors(AddonNotifications.markAllNotificationsAsRead()); CoreEvents.trigger(AddonNotificationsProvider.READ_CHANGED_EVENT, { time: CoreTimeUtils.timestamp(), @@ -225,8 +226,8 @@ export class AddonNotificationsListPage implements AfterViewInit, OnDestroy { * @param refresher Refresher. */ async refreshNotifications(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(AddonNotifications.invalidateNotificationsList()); - await CoreUtils.ignoreErrors(this.fetchNotifications(true)); + await CorePromiseUtils.ignoreErrors(AddonNotifications.invalidateNotificationsList()); + await CorePromiseUtils.ignoreErrors(this.fetchNotifications(true)); refresher?.complete(); } diff --git a/src/addons/notifications/pages/settings/settings.ts b/src/addons/notifications/pages/settings/settings.ts index 59bc38a6e..f8729db9a 100644 --- a/src/addons/notifications/pages/settings/settings.ts +++ b/src/addons/notifications/pages/settings/settings.ts @@ -18,7 +18,7 @@ import { CoreConfig } from '@services/config'; import { CoreLocalNotifications } from '@services/local-notifications'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreUser } from '@features/user/services/user'; import { AddonMessageOutputDelegate, AddonMessageOutputHandlerData } from '@addons/messageoutput/services/messageoutput-delegate'; import { CoreConstants } from '@/core/constants'; @@ -179,7 +179,7 @@ export class AddonNotificationsSettingsPage implements OnInit, OnDestroy { * @returns Promise resolved when done. */ protected async updatePreferences(): Promise { - await CoreUtils.ignoreErrors(AddonNotifications.invalidateNotificationPreferences()); + await CorePromiseUtils.ignoreErrors(AddonNotifications.invalidateNotificationPreferences()); await AddonNotifications.getNotificationPreferences(); } @@ -204,7 +204,7 @@ export class AddonNotificationsSettingsPage implements OnInit, OnDestroy { */ async refreshPreferences(refresher?: HTMLIonRefresherElement): Promise { try { - await CoreUtils.ignoreErrors(AddonNotifications.invalidateNotificationPreferences()); + await CorePromiseUtils.ignoreErrors(AddonNotifications.invalidateNotificationPreferences()); await this.fetchPreferences(); } finally { @@ -334,7 +334,7 @@ export class AddonNotificationsSettingsPage implements OnInit, OnDestroy { * @param enabled True to enable the notification sound, false to disable it. */ async changeNotificationSound(enabled: boolean): Promise { - await CoreUtils.ignoreErrors(CoreConfig.set(CoreConstants.SETTINGS_NOTIFICATION_SOUND, enabled ? 1 : 0)); + await CorePromiseUtils.ignoreErrors(CoreConfig.set(CoreConstants.SETTINGS_NOTIFICATION_SOUND, enabled ? 1 : 0)); const siteId = CoreSites.getCurrentSiteId(); CoreEvents.trigger(CoreEvents.NOTIFICATION_SOUND_CHANGED, { enabled }, siteId); diff --git a/src/addons/notifications/services/handlers/push-click.ts b/src/addons/notifications/services/handlers/push-click.ts index 322c029a3..42a890f5d 100644 --- a/src/addons/notifications/services/handlers/push-click.ts +++ b/src/addons/notifications/services/handlers/push-click.ts @@ -25,6 +25,7 @@ import { AddonNotificationsMainMenuHandlerService } from './mainmenu'; import { AddonNotificationsHelper } from '../notifications-helper'; import { CoreViewer } from '@features/viewer/services/viewer'; import { CoreInAppBrowser } from '@singletons/iab'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler for non-messaging push notifications clicks. @@ -65,7 +66,7 @@ export class AddonNotificationsPushClickHandlerService implements CorePushNotifi * @returns Promise resolved when done. */ protected async markAsRead(notification: AddonNotificationsPushNotification): Promise { - await CoreUtils.ignoreErrors(AddonNotificationsHelper.markNotificationAsRead(notification)); + await CorePromiseUtils.ignoreErrors(AddonNotificationsHelper.markNotificationAsRead(notification)); } /** @@ -117,7 +118,7 @@ export class AddonNotificationsPushClickHandlerService implements CorePushNotifi } // No contexturl or cannot be handled by the app. Open the notifications page. - await CoreUtils.ignoreErrors(AddonNotifications.invalidateNotificationsList(notification.site)); + await CorePromiseUtils.ignoreErrors(AddonNotifications.invalidateNotificationsList(notification.site)); await CoreNavigator.navigateToSitePath( `${AddonNotificationsMainMenuHandlerService.PAGE_NAME}/list`, diff --git a/src/addons/notifications/services/notifications-helper.ts b/src/addons/notifications/services/notifications-helper.ts index bcf4305f7..288f3bf69 100644 --- a/src/addons/notifications/services/notifications-helper.ts +++ b/src/addons/notifications/services/notifications-helper.ts @@ -30,6 +30,7 @@ import { import { CoreEvents } from '@singletons/events'; import { AddonNotificationsPushNotification } from './handlers/push-click'; import { CoreTimeUtils } from '@services/utils/time'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service that provides some helper functions for notifications. @@ -119,7 +120,7 @@ export class AddonNotificationsHelperProvider { siteId = 'site' in notification ? notification.site : siteId; - await CoreUtils.ignoreErrors(AddonNotifications.markNotificationRead(notifId, siteId)); + await CorePromiseUtils.ignoreErrors(AddonNotifications.markNotificationRead(notifId, siteId)); const time = CoreTimeUtils.timestamp(); if ('read' in notification) { @@ -127,7 +128,7 @@ export class AddonNotificationsHelperProvider { notification.timeread = time; } - await CoreUtils.ignoreErrors(AddonNotifications.invalidateNotificationsList()); + await CorePromiseUtils.ignoreErrors(AddonNotifications.invalidateNotificationsList()); CoreEvents.trigger(AddonNotificationsProvider.READ_CHANGED_EVENT, { id: notifId, diff --git a/src/addons/privatefiles/pages/index/index.ts b/src/addons/privatefiles/pages/index/index.ts index 0b4606a66..1e4668a65 100644 --- a/src/addons/privatefiles/pages/index/index.ts +++ b/src/addons/privatefiles/pages/index/index.ts @@ -29,7 +29,7 @@ import { AddonPrivateFilesGetFilesWSParams, } from '@addons/privatefiles/services/privatefiles'; import { AddonPrivateFilesHelper } from '@addons/privatefiles/services/privatefiles-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreNavigator } from '@services/navigator'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; @@ -192,7 +192,7 @@ export class AddonPrivateFilesIndexPage implements OnInit, OnDestroy { // File uploaded, refresh the list. this.filesLoaded = false; - await CoreUtils.ignoreErrors(this.refreshFiles()); + await CorePromiseUtils.ignoreErrors(this.refreshFiles()); this.filesLoaded = true; } catch (error) { diff --git a/src/addons/qtype/ddmarker/classes/ddmarker.ts b/src/addons/qtype/ddmarker/classes/ddmarker.ts index 112353571..05e0b8fd7 100644 --- a/src/addons/qtype/ddmarker/classes/ddmarker.ts +++ b/src/addons/qtype/ddmarker/classes/ddmarker.ts @@ -19,7 +19,7 @@ import { CoreEventObserver } from '@singletons/events'; import { CoreLogger } from '@singletons/logger'; import { AddonQtypeDdMarkerQuestionData } from '../component/ddmarker'; import { AddonQtypeDdMarkerGraphicsApi } from './graphics_api'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreDirectivesRegistry } from '@singletons/directives-registry'; import { CoreExternalContentDirective } from '@directives/external-content'; import { CoreLinkDirective } from '@directives/link'; @@ -715,7 +715,7 @@ export class AddonQtypeDdMarkerQuestion { // Wait for image to be visible, otherwise the calculated positions are wrong. const visiblePromise = CoreDom.waitToBeVisible(bgImg); - await CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(visiblePromise, 500)); + await CorePromiseUtils.ignoreErrors(CorePromiseUtils.timeoutPromise(visiblePromise, 500)); visiblePromise.cancel(); // In case of timeout, cancel the promise. this.redrawDragsAndDrops(); diff --git a/src/addons/remotethemes/services/remotethemes-handler.ts b/src/addons/remotethemes/services/remotethemes-handler.ts index 16b48f126..1b6c337c5 100644 --- a/src/addons/remotethemes/services/remotethemes-handler.ts +++ b/src/addons/remotethemes/services/remotethemes-handler.ts @@ -22,7 +22,7 @@ import { CoreWS } from '@services/ws'; import { makeSingleton } from '@singletons'; import { CoreStyleHandler, CoreStylesService } from '@features/styles/services/styles'; import { CoreLogger } from '@singletons/logger'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; const COMPONENT = 'mmaRemoteStyles'; @@ -89,7 +89,7 @@ export class AddonRemoteThemesHandlerService implements CoreStyleHandler { if (style != '') { // Treat the CSS. - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( CoreFilepool.treatCSSCode(siteId, infos.mobilecssurl, style, COMPONENT, 1), ); } diff --git a/src/core/classes/items-management/list-items-manager.ts b/src/core/classes/items-management/list-items-manager.ts index 4761374d7..a0de7591d 100644 --- a/src/core/classes/items-management/list-items-manager.ts +++ b/src/core/classes/items-management/list-items-manager.ts @@ -24,6 +24,7 @@ import { CoreRoutedItemsManagerSource } from './routed-items-manager-source'; import { CoreRoutedItemsManager } from './routed-items-manager'; import { CoreDom } from '@singletons/dom'; import { CoreTime } from '@singletons/time'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Helper class to manage the state and routing of a list of items in a page. @@ -45,7 +46,7 @@ export class CoreListItemsManager< this.pageRouteLocator = pageRouteLocator; this.addListener({ onSelectedItemUpdated: debouncedScrollToCurrentElement }); - this.finishSuccessfulFetch = CoreTime.once(() => CoreUtils.ignoreErrors(this.logActivity())); + this.finishSuccessfulFetch = CoreTime.once(() => CorePromiseUtils.ignoreErrors(this.logActivity())); } get items(): Item[] { diff --git a/src/core/classes/page-load-watcher.ts b/src/core/classes/page-load-watcher.ts index 2bc2ef7aa..29671b547 100644 --- a/src/core/classes/page-load-watcher.ts +++ b/src/core/classes/page-load-watcher.ts @@ -13,7 +13,7 @@ // limitations under the License. import { CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Subscription } from 'rxjs'; import { AsyncDirective } from './async-directive'; import { PageLoadsManager } from './page-loads-manager'; @@ -130,7 +130,7 @@ export class PageLoadWatcher { return; } - this.hasChangesPromises.push(CoreUtils.ignoreErrors(hasMeaningfulChanges(firstValue, value), false)); + this.hasChangesPromises.push(CorePromiseUtils.ignoreErrors(hasMeaningfulChanges(firstValue, value), false)); }, error: (error) => { promisedValue.reject(error); diff --git a/src/core/classes/sites/authenticated-site.ts b/src/core/classes/sites/authenticated-site.ts index b12b1f04d..3f4858920 100644 --- a/src/core/classes/sites/authenticated-site.ts +++ b/src/core/classes/sites/authenticated-site.ts @@ -42,6 +42,7 @@ import { Md5 } from 'ts-md5'; import { CoreSiteWSCacheRecord } from '@services/database/sites'; import { CoreErrorLogs } from '@singletons/error-logs'; import { CoreWait } from '@singletons/wait'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Class that represents a site (combination of site + user) where the user has authenticated but the site hasn't been validated @@ -720,7 +721,7 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite { if (preSets.deleteCacheIfWSError && CoreUtils.isWebServiceError(error)) { // Delete the cache entry and return the entry. Don't block the user with the delete. - CoreUtils.ignoreErrors(this.deleteFromCache(method, data, preSets)); + CorePromiseUtils.ignoreErrors(this.deleteFromCache(method, data, preSets)); throw new CoreWSError(error); } @@ -1148,7 +1149,7 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite { protected async saveToCache(method: string, data: any, response: any, preSets: CoreSiteWSPreSets): Promise { if (preSets.uniqueCacheKey) { // Cache key must be unique, delete all entries with same cache key. - await CoreUtils.ignoreErrors(this.deleteFromCache(method, data, preSets, true)); + await CorePromiseUtils.ignoreErrors(this.deleteFromCache(method, data, preSets, true)); } // Since 3.7, the expiration time contains the time the entry is modified instead of the expiration time. diff --git a/src/core/classes/sites/site.ts b/src/core/classes/sites/site.ts index 135d4beed..c8ae21dd9 100644 --- a/src/core/classes/sites/site.ts +++ b/src/core/classes/sites/site.ts @@ -56,6 +56,7 @@ import { firstValueFrom } from 'rxjs'; import { CorePlatform } from '@services/platform'; import { CoreLoadings } from '@services/loadings'; import { CoreInAppBrowser } from '@singletons/iab'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Class that represents a site (combination of site + user). @@ -406,7 +407,7 @@ export class CoreSite extends CoreAuthenticatedSite { const siteFolder = CoreFile.getSiteFolder(this.id); // Ignore any errors, removeDir fails if folder doesn't exists. - await CoreUtils.ignoreErrors(CoreFile.removeDir(siteFolder)); + await CorePromiseUtils.ignoreErrors(CoreFile.removeDir(siteFolder)); } /** @@ -414,14 +415,14 @@ export class CoreSite extends CoreAuthenticatedSite { * * @returns Promise resolved with the site space usage (size). */ - getSpaceUsage(): Promise { + async getSpaceUsage(): Promise { if (CoreFile.isAvailable() && this.id) { const siteFolderPath = CoreFile.getSiteFolder(this.id); return CoreFile.getDirectorySize(siteFolderPath).catch(() => 0); - } else { - return Promise.resolve(0); } + + return 0; } /** @@ -885,7 +886,7 @@ export class CoreSite extends CoreAuthenticatedSite { * @returns Time between requests. */ async getAutoLoginMinTimeBetweenRequests(): Promise { - const timeBetweenRequests = await CoreUtils.ignoreErrors( + const timeBetweenRequests = await CorePromiseUtils.ignoreErrors( this.getConfig('tool_mobile_autologinmintimebetweenreq'), CoreConstants.SECONDS_MINUTE * 6, ); diff --git a/src/core/components/attachments/attachments.ts b/src/core/components/attachments/attachments.ts index 7abcc61f9..1996d62ec 100644 --- a/src/core/components/attachments/attachments.ts +++ b/src/core/components/attachments/attachments.ts @@ -24,7 +24,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper'; import { CoreFileEntry } from '@services/file-helper'; import { CoreCourses } from '@features/courses/services/courses'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { toBoolean } from '@/core/transforms/boolean'; /** @@ -106,7 +106,7 @@ export class CoreAttachmentsComponent implements OnInit { protected async getMaxSizeOfArea(): Promise { if (this.courseId) { // Check course max size. - const course = await CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', this.courseId)); + const course = await CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', this.courseId)); if (course?.maxbytes) { this.maxSize = course.maxbytes; diff --git a/src/core/components/file/file.ts b/src/core/components/file/file.ts index 574a138e2..fedc1f106 100644 --- a/src/core/components/file/file.ts +++ b/src/core/components/file/file.ts @@ -28,6 +28,7 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreWSFile } from '@services/ws'; import { CorePlatform } from '@services/platform'; import { toBoolean } from '@/core/transforms/boolean'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component to handle a remote file. Shows the file name, icon (depending on mimetype) and a button @@ -226,7 +227,7 @@ export class CoreFileComponent implements OnInit, OnDestroy { // User confirmed, add the file to queue. // @todo Is the invalidate really needed? - await CoreUtils.ignoreErrors(CoreFilepool.invalidateFileByUrl(this.siteId, this.fileUrl)); + await CorePromiseUtils.ignoreErrors(CoreFilepool.invalidateFileByUrl(this.siteId, this.fileUrl)); this.isDownloading = true; diff --git a/src/core/components/show-password/show-password.ts b/src/core/components/show-password/show-password.ts index 12ca321ca..b36e0bf04 100644 --- a/src/core/components/show-password/show-password.ts +++ b/src/core/components/show-password/show-password.ts @@ -16,7 +16,7 @@ import { Component, AfterViewInit, Input, ContentChild, ViewEncapsulation } from import { IonInput } from '@ionic/angular'; import { convertTextToHTMLElement } from '@/core/utils/create-html-element'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreLogger } from '@singletons/logger'; /** @@ -79,7 +79,7 @@ export class CoreShowPasswordComponent implements AfterViewInit { } // eslint-disable-next-line deprecation/deprecation - const input = await CoreUtils.ignoreErrors(this.ionInput.getInputElement()); + const input = await CorePromiseUtils.ignoreErrors(this.ionInput.getInputElement()); if (!input) { return; } diff --git a/src/core/components/site-picker/site-picker.ts b/src/core/components/site-picker/site-picker.ts index 3bcb7d08e..7e644b2fa 100644 --- a/src/core/components/site-picker/site-picker.ts +++ b/src/core/components/site-picker/site-picker.ts @@ -16,7 +16,7 @@ import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core'; import { CoreFilter } from '@features/filter/services/filter'; import { CoreSiteBasicInfo, CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; /** @@ -56,7 +56,7 @@ export class CoreSitePickerComponent implements OnInit { await Promise.all(sites.map(async (site: SiteInfo) => { // Format the site name. const options = { clean: true, singleLine: true, filter: false }; - const siteName = await CoreUtils.ignoreErrors( + const siteName = await CorePromiseUtils.ignoreErrors( CoreFilter.formatText(site.siteName || '', options, [], site.id), site.siteName || '', ); diff --git a/src/core/directives/external-content.ts b/src/core/directives/external-content.ts index 4ed81c8a4..4ed754f72 100644 --- a/src/core/directives/external-content.ts +++ b/src/core/directives/external-content.ts @@ -27,7 +27,7 @@ import { CoreFile, CoreFileProvider } from '@services/file'; import { CoreFilepool, CoreFilepoolFileActions, CoreFilepoolFileEventData } from '@services/filepool'; import { CoreSites } from '@services/sites'; import { CoreUrl } from '@singletons/url'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreLogger } from '@singletons/logger'; import { CoreError } from '@classes/errors/error'; import { CoreSite } from '@classes/sites/site'; @@ -203,7 +203,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O this.handleVideoSubtitles( this.element); } - const site = await CoreUtils.ignoreErrors(CoreSites.getSite(this.siteId)); + const site = await CorePromiseUtils.ignoreErrors(CoreSites.getSite(this.siteId)); const isSiteFile = site?.isSitePluginFileUrl(url); if (!url || !url.match(/^https?:\/\//i) || CoreUrl.isLocalFileUrl(url) || @@ -305,7 +305,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O }); try { - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); this.element.setAttribute('style', inlineStyles); } catch (error) { diff --git a/src/core/directives/format-text.ts b/src/core/directives/format-text.ts index e5086623c..47896df27 100644 --- a/src/core/directives/format-text.ts +++ b/src/core/directives/format-text.ts @@ -58,6 +58,7 @@ import { ContextLevel } from '../constants'; import { CoreWait } from '@singletons/wait'; import { toBoolean } from '../transforms/boolean'; import { CoreViewer } from '@features/viewer/services/viewer'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Directive to format text rendered. It renders the HTML and treats all links and media, using CoreLinkDirective @@ -422,7 +423,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec */ protected async formatContents(): Promise { // Retrieve the site since it might be needed later. - const site = await CoreUtils.ignoreErrors(CoreSites.getSite(this.siteId)); + const site = await CorePromiseUtils.ignoreErrors(CoreSites.getSite(this.siteId)); const siteId = site?.getId(); @@ -612,7 +613,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec if (externalImages.length) { // Wait for images to load. - const promise = CoreUtils.allPromises(externalImages.map((externalImage) => { + const promise = CorePromiseUtils.allPromises(externalImages.map((externalImage) => { if (externalImage.loaded) { // Image has already been loaded, no need to wait. return Promise.resolve(); @@ -622,7 +623,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec })); // Automatically reject the promise after 5 seconds to prevent blocking the user forever. - promises.push(CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(promise, 5000))); + promises.push(CorePromiseUtils.ignoreErrors(CorePromiseUtils.timeoutPromise(promise, 5000))); } // Run asynchronous operations in the background to avoid blocking rendering. diff --git a/src/core/directives/tests/format-text.test.ts b/src/core/directives/tests/format-text.test.ts index e041ea7ce..1c1f34550 100644 --- a/src/core/directives/tests/format-text.test.ts +++ b/src/core/directives/tests/format-text.test.ts @@ -23,7 +23,7 @@ import { CoreFilterHelper } from '@features/filter/services/filter-helper'; import { CoreFormatTextDirective } from '@directives/format-text'; import { CoreSite } from '@classes/sites/site'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { mock, mockSingleton, RenderConfig, renderTemplate, renderWrapperComponent } from '@/testing/utils'; import { ContextLevel } from '@/core/constants'; @@ -135,7 +135,7 @@ describe('CoreFormatTextDirective', () => { }); // @todo this is done because we cannot mock image being loaded, we should find an alternative... - CoreUtils.instance.timeoutPromise = () => Promise.resolve(null as unknown as T); + CorePromiseUtils.timeoutPromise = () => Promise.resolve(null as unknown as T); mockSingleton(CoreFilepool, { getSrcByUrl: () => Promise.resolve('file://local-path') }); mockSingleton(CoreSites, { diff --git a/src/core/features/block/components/side-blocks/side-blocks.ts b/src/core/features/block/components/side-blocks/side-blocks.ts index 92b20b1b8..eabb1e33f 100644 --- a/src/core/features/block/components/side-blocks/side-blocks.ts +++ b/src/core/features/block/components/side-blocks/side-blocks.ts @@ -18,7 +18,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreCourse, CoreCourseBlock } from '@features/course/services/course'; import { CoreBlockHelper } from '../../services/block-helper'; import { CoreBlockComponent } from '../block/block'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreCoursesDashboard } from '@features/courses/services/dashboard'; import { CoreDom } from '@singletons/dom'; import { ContextLevel } from '@/core/constants'; @@ -118,7 +118,7 @@ export class CoreBlockSideBlocksComponent implements OnInit { * @param refresher Refresher. */ async doRefresh(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(this.invalidateBlocks()); + await CorePromiseUtils.ignoreErrors(this.invalidateBlocks()); await this.loadContent().finally(() => { refresher?.complete(); diff --git a/src/core/features/comments/components/comments/comments.ts b/src/core/features/comments/components/comments/comments.ts index 9e9f44828..b15171df7 100644 --- a/src/core/features/comments/components/comments/comments.ts +++ b/src/core/features/comments/components/comments/comments.ts @@ -20,7 +20,7 @@ import { import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; import { CoreNavigator } from '@services/navigator'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ContextLevel } from '@/core/constants'; import { toBoolean } from '@/core/transforms/boolean'; @@ -76,7 +76,7 @@ export class CoreCommentsCommentsComponent implements OnInit, OnChanges, OnDestr this.undefinedOrEqual(data, 'component') && this.undefinedOrEqual(data, 'itemId') && this.undefinedOrEqual(data, 'area')) { - CoreUtils.ignoreErrors(this.doRefresh()); + CorePromiseUtils.ignoreErrors(this.doRefresh()); } }, CoreSites.getCurrentSiteId(), diff --git a/src/core/features/comments/pages/viewer/viewer.ts b/src/core/features/comments/pages/viewer/viewer.ts index 8f0a211a9..e063f3678 100644 --- a/src/core/features/comments/pages/viewer/viewer.ts +++ b/src/core/features/comments/pages/viewer/viewer.ts @@ -29,7 +29,7 @@ import { IonContent } from '@ionic/angular'; import { ContextLevel, CoreConstants } from '@/core/constants'; import { CoreNavigator } from '@services/navigator'; import { NgZone, Translate } from '@singletons'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUser } from '@features/user/services/user'; import { CoreText } from '@singletons/text'; @@ -161,7 +161,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy { this.loadMoreError = false; if (sync) { - await CoreUtils.ignoreErrors(this.syncComments(showErrors)); + await CorePromiseUtils.ignoreErrors(this.syncComments(showErrors)); } try { @@ -256,7 +256,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy { this.refreshIcon = CoreConstants.ICON_LOADING; this.syncIcon = CoreConstants.ICON_LOADING; - await CoreUtils.ignoreErrors(this.invalidateComments()); + await CorePromiseUtils.ignoreErrors(this.invalidateComments()); this.page = 0; this.comments = []; @@ -623,7 +623,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy { * Refresh cached data in background. */ protected async refreshInBackground(): Promise { - await CoreUtils.ignoreErrors(this.invalidateComments()); + await CorePromiseUtils.ignoreErrors(this.invalidateComments()); const promises: Promise[] = []; diff --git a/src/core/features/comments/services/comments-sync.ts b/src/core/features/comments/services/comments-sync.ts index 649d375da..d7e5df636 100644 --- a/src/core/features/comments/services/comments-sync.ts +++ b/src/core/features/comments/services/comments-sync.ts @@ -26,6 +26,7 @@ import { CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/co import { CoreSyncResult } from '@services/sync'; import { ContextLevel } from '@/core/constants'; import { CORE_COMMENTS_AUTO_SYNCED } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync omments. @@ -274,10 +275,10 @@ export class CoreCommentsSyncProvider extends CoreSyncBaseProvider { const site = await CoreSites.getSite(siteId); - await CoreUtils.allPromises([ + await CorePromiseUtils.allPromises([ // This is done with starting with to avoid conflicts with previous keys that were including page. site.invalidateWsCacheForKeyStartingWith(this.getCommentsCacheKey( contextLevel, diff --git a/src/core/features/compile/components/compile-html/compile-html.ts b/src/core/features/compile/components/compile-html/compile-html.ts index c55156abe..9176d4990 100644 --- a/src/core/features/compile/components/compile-html/compile-html.ts +++ b/src/core/features/compile/components/compile-html/compile-html.ts @@ -43,7 +43,7 @@ import { CorePromisedValue } from '@classes/promised-value'; import { CoreCompile } from '@features/compile/services/compile'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWS } from '@services/ws'; import { CoreDom } from '@singletons/dom'; @@ -192,7 +192,7 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck { } if (this.stylesPath && !this.cssCode) { - this.cssCode = await CoreUtils.ignoreErrors(CoreWS.getText(this.stylesPath)); + this.cssCode = await CorePromiseUtils.ignoreErrors(CoreWS.getText(this.stylesPath)); } // Prepend all CSS rules with :host to avoid conflicts. diff --git a/src/core/features/contentlinks/services/contentlinks-delegate.ts b/src/core/features/contentlinks/services/contentlinks-delegate.ts index c76527243..7e24cc359 100644 --- a/src/core/features/contentlinks/services/contentlinks-delegate.ts +++ b/src/core/features/contentlinks/services/contentlinks-delegate.ts @@ -19,6 +19,7 @@ import { CoreUrl } from '@singletons/url'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { CoreText } from '@singletons/text'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Interface that all handlers must implement. @@ -193,7 +194,7 @@ export class CoreContentLinksDelegateService { return; } - const actions = await CoreUtils.ignoreErrors( + const actions = await CorePromiseUtils.ignoreErrors( Promise.resolve(handler.getActions(siteIds, relativeUrl, params, courseId, data)), [], ); @@ -240,7 +241,7 @@ export class CoreContentLinksDelegateService { })); } try { - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } catch { // Ignore errors. } diff --git a/src/core/features/course/classes/main-activity-component.ts b/src/core/features/course/classes/main-activity-component.ts index 02f2e8127..e24f336a9 100644 --- a/src/core/features/course/classes/main-activity-component.ts +++ b/src/core/features/course/classes/main-activity-component.ts @@ -18,7 +18,7 @@ import { IonContent } from '@ionic/angular'; import { CoreCourseModuleMainResourceComponent } from './main-resource-component'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreCourse } from '../services/course'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreCourseContentsPage } from '../pages/contents/contents'; import { CoreSites } from '@services/sites'; @@ -100,7 +100,7 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR return; } - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ this.invalidateContent(), this.showCompletion ? CoreCourse.invalidateModule(this.module.id) : undefined, ])); @@ -165,7 +165,7 @@ export class CoreCourseModuleMainActivityComponent extends CoreCourseModuleMainR try { if (refresh && this.showCompletion) { - await CoreUtils.ignoreErrors(this.fetchModule()); + await CorePromiseUtils.ignoreErrors(this.fetchModule()); } await this.fetchContent(refresh, sync, showErrors); diff --git a/src/core/features/course/classes/main-resource-component.ts b/src/core/features/course/classes/main-resource-component.ts index 6e67b5d1e..ae434cd44 100644 --- a/src/core/features/course/classes/main-resource-component.ts +++ b/src/core/features/course/classes/main-resource-component.ts @@ -35,6 +35,7 @@ import { CoreTime } from '@singletons/time'; import { CoreText } from '@singletons/text'; import { CoreModals } from '@services/modals'; import { CoreErrorHelper, CoreErrorObject } from '@services/error-helper'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Result of a resource download. @@ -131,10 +132,10 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, // If it's a single activity course and the refresher is displayed within the component, // call doRefresh on the section page to refresh the course data. if (this.courseContentsPage && !CoreCourseModuleDelegate.displayRefresherInSingleActivity(this.module.modname)) { - await CoreUtils.ignoreErrors(this.courseContentsPage.doRefresh()); + await CorePromiseUtils.ignoreErrors(this.courseContentsPage.doRefresh()); } - await CoreUtils.ignoreErrors(this.refreshContent(true, showErrors)); + await CorePromiseUtils.ignoreErrors(this.refreshContent(true, showErrors)); refresher?.complete(); } @@ -153,7 +154,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, return; } - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ this.invalidateContent(), this.showCompletion ? CoreCourse.invalidateModule(this.module.id) : undefined, ])); @@ -315,7 +316,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, } if (refresh) { - await CoreUtils.ignoreErrors(CoreCourseModulePrefetchDelegate.invalidateCourseUpdates(this.courseId)); + await CorePromiseUtils.ignoreErrors(CoreCourseModulePrefetchDelegate.invalidateCourseUpdates(this.courseId)); } // Also, get the current status. @@ -420,7 +421,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, // @todo: Temporary fix to update course page completion. This should be refactored in MOBILE-4326. if (previousCompletion && module.completiondata && previousCompletion.state !== module.completiondata.state) { - await CoreUtils.ignoreErrors(CoreCourse.invalidateSections(this.courseId)); + await CorePromiseUtils.ignoreErrors(CoreCourse.invalidateSections(this.courseId)); CoreEvents.trigger(CoreEvents.COMPLETION_MODULE_VIEWED, { courseId: this.courseId, diff --git a/src/core/features/course/components/course-format/course-format.ts b/src/core/features/course/components/course-format/course-format.ts index 9f088a956..d0ef9749f 100644 --- a/src/core/features/course/components/course-format/course-format.ts +++ b/src/core/features/course/components/course-format/course-format.ts @@ -40,7 +40,7 @@ import { import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { AccordionGroupChangeEventDetail, IonContent } from '@ionic/angular'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreCourseIndexSectionWithModule } from '../course-index/course-index'; import { CoreBlockHelper } from '@features/block/services/block-helper'; import { CoreNavigator } from '@services/navigator'; @@ -739,7 +739,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * @param firstLoad Whether it's the first load when opening the course. */ async logView(sectionNumber?: number, firstLoad = false): Promise { - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreCourse.logView(this.course.id, sectionNumber), ); @@ -801,7 +801,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * Initializes the expanded sections for the course. */ protected async initializeExpandedSections(): Promise { - const expandedSections = await CoreUtils.ignoreErrors( + const expandedSections = await CorePromiseUtils.ignoreErrors( this.currentSite?.getLocalSiteConfig(`${CORE_COURSE_EXPANDED_SECTIONS_PREFIX}${this.course.id}`), ); diff --git a/src/core/features/course/components/module-navigation/module-navigation.ts b/src/core/features/course/components/module-navigation/module-navigation.ts index 86a57cbed..d831d2fd2 100644 --- a/src/core/features/course/components/module-navigation/module-navigation.ts +++ b/src/core/features/course/components/module-navigation/module-navigation.ts @@ -21,7 +21,7 @@ import { CoreLoadings } from '@services/loadings'; import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; /** @@ -170,7 +170,7 @@ export class CoreCourseModuleNavigationComponent implements OnInit, OnDestroy { const modal = await CoreLoadings.show(); // Re-calculate module in case a new module was made visible. - await CoreUtils.ignoreErrors(this.setNextAndPreviousModules(CoreSitesReadingStrategy.PREFER_NETWORK, next, !next)); + await CorePromiseUtils.ignoreErrors(this.setNextAndPreviousModules(CoreSitesReadingStrategy.PREFER_NETWORK, next, !next)); modal.dismiss(); diff --git a/src/core/features/course/components/module-summary/module-summary.ts b/src/core/features/course/components/module-summary/module-summary.ts index f04160241..00353ebd5 100644 --- a/src/core/features/course/components/module-summary/module-summary.ts +++ b/src/core/features/course/components/module-summary/module-summary.ts @@ -35,6 +35,7 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { Subscription } from 'rxjs'; import { CoreSharedModule } from '@/core/shared.module'; import { toBoolean } from '@/core/transforms/boolean'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Component to display a module summary modal. @@ -274,7 +275,7 @@ export class CoreCourseModuleSummaryComponent implements OnInit, OnDestroy { protected async fetchCourse(): Promise { this.course = await CoreCourseHelper.getCourseInfo(this.courseId); - this.isTeacher = await CoreUtils.ignoreErrors(CoreCourseHelper.guessIsTeacher(this.courseId, this.course), false); + this.isTeacher = await CorePromiseUtils.ignoreErrors(CoreCourseHelper.guessIsTeacher(this.courseId, this.course), false); } /** diff --git a/src/core/features/course/pages/contents/contents.ts b/src/core/features/course/pages/contents/contents.ts index b303289a6..0ec34c8de 100644 --- a/src/core/features/course/pages/contents/contents.ts +++ b/src/core/features/course/pages/contents/contents.ts @@ -46,6 +46,7 @@ import { CORE_COURSE_AUTO_SYNCED, CORE_COURSE_PROGRESS_UPDATED_EVENT, } from '@features/course/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays the contents of a course. @@ -108,9 +109,9 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => { if (this.modulesHaveCompletion) { - CoreUtils.ignoreErrors(CoreCourse.getSections(this.course.id, false, true)); + CorePromiseUtils.ignoreErrors(CoreCourse.getSections(this.course.id, false, true)); } else { - CoreUtils.ignoreErrors(CoreCourse.getActivitiesCompletionStatus( + CorePromiseUtils.ignoreErrors(CoreCourse.getActivitiesCompletionStatus( this.course.id, undefined, undefined, @@ -179,7 +180,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon */ protected async loadData(refresh?: boolean, sync?: boolean): Promise { // First of all, get the course because the data might have changed. - const result = await CoreUtils.ignoreErrors(CoreCourseHelper.getCourse(this.course.id)); + const result = await CorePromiseUtils.ignoreErrors(CoreCourseHelper.getCourse(this.course.id)); if (result) { if (this.course.id === result.course.id && 'displayname' in this.course && !('displayname' in result.course)) { @@ -191,7 +192,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon if (sync) { // Try to synchronize the course data. // For now we don't allow manual syncing, so ignore errors. - const result = await CoreUtils.ignoreErrors(CoreCourseSync.syncCourse( + const result = await CorePromiseUtils.ignoreErrors(CoreCourseSync.syncCourse( this.course.id, this.course.displayname || this.course.fullname, )); @@ -240,9 +241,9 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon // The module already has completion (3.6 onwards). Load the offline completion. this.modulesHaveCompletion = true; - await CoreUtils.ignoreErrors(CoreCourseHelper.loadOfflineCompletion(this.course.id, sections)); + await CorePromiseUtils.ignoreErrors(CoreCourseHelper.loadOfflineCompletion(this.course.id, sections)); } else { - const fetchedData = await CoreUtils.ignoreErrors( + const fetchedData = await CorePromiseUtils.ignoreErrors( CoreCourse.getActivitiesCompletionStatus(this.course.id), ); @@ -288,7 +289,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon return; } - const course = await CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', this.course.id)); + const course = await CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', this.course.id)); course && Object.assign(this.course, course); @@ -304,7 +305,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon * @returns Promise resolved when done. */ async doRefresh(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(this.invalidateData()); + await CorePromiseUtils.ignoreErrors(this.invalidateData()); try { await this.loadData(true, true); @@ -312,7 +313,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon // Do not call doRefresh on the format component if the refresher is defined in the format component // to prevent an infinite loop. if (this.displayRefresher && this.formatComponent) { - await CoreUtils.ignoreErrors(this.formatComponent.doRefresh(refresher)); + await CorePromiseUtils.ignoreErrors(this.formatComponent.doRefresh(refresher)); } refresher?.complete(); @@ -354,10 +355,10 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon } } - await CoreUtils.ignoreErrors(this.invalidateData()); + await CorePromiseUtils.ignoreErrors(this.invalidateData()); this.debouncedUpdateCachedCompletion?.(); } else { - await CoreUtils.ignoreErrors(this.invalidateData()); + await CorePromiseUtils.ignoreErrors(this.invalidateData()); await this.showLoadingAndRefresh(true, false); } @@ -398,7 +399,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon */ protected async showLoadingAndRefresh(sync = false, invalidateData = true): Promise { // Try to keep current scroll position. - const scrollElement = await CoreUtils.ignoreErrors(this.content?.getScrollElement()); + const scrollElement = await CorePromiseUtils.ignoreErrors(this.content?.getScrollElement()); const scrollTop = scrollElement?.scrollTop ?? -1; this.updatingData = true; @@ -406,7 +407,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon try { if (invalidateData) { - await CoreUtils.ignoreErrors(this.invalidateData()); + await CorePromiseUtils.ignoreErrors(this.invalidateData()); } await this.loadData(true, sync); diff --git a/src/core/features/course/pages/course-summary/course-summary.page.ts b/src/core/features/course/pages/course-summary/course-summary.page.ts index 546485f14..4585d7cb6 100644 --- a/src/core/features/course/pages/course-summary/course-summary.page.ts +++ b/src/core/features/course/pages/course-summary/course-summary.page.ts @@ -30,7 +30,7 @@ import { import { CoreCourseHelper } from '@features/course/services/course-helper'; import { ActionSheetController, ModalController, NgZone, Translate } from '@singletons'; import { CoreNavigator } from '@services/navigator'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreCoursesHelper, CoreCourseWithImageAndColor } from '@features/courses/services/courses-helper'; import { Subscription } from 'rxjs'; import { CoreColors } from '@singletons/colors'; @@ -174,7 +174,7 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy { await this.loadMenuHandlers(refresh); // After loading menu handlers, admOptions should be available. - this.isTeacher = await CoreUtils.ignoreErrors(CoreCourseHelper.guessIsTeacher(this.courseId, this.course), false); + this.isTeacher = await CorePromiseUtils.ignoreErrors(CoreCourseHelper.guessIsTeacher(this.courseId, this.course), false); this.dataLoaded = true; } @@ -204,7 +204,7 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy { // Ignore errors. } - const courseByField = await CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', this.courseId)); + const courseByField = await CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', this.courseId)); if (courseByField) { if (this.course) { this.course.customfields = courseByField.customfields; @@ -440,7 +440,7 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy { } // Check if user is enrolled in the course. - await CoreUtils.ignoreErrors(CoreCourses.invalidateUserCourses()); + await CorePromiseUtils.ignoreErrors(CoreCourses.invalidateUserCourses()); try { await CoreCourses.getUserCourse(this.courseId); diff --git a/src/core/features/course/pages/index/index.ts b/src/core/features/course/pages/index/index.ts index 463689768..99a3a1c62 100644 --- a/src/core/features/course/pages/index/index.ts +++ b/src/core/features/course/pages/index/index.ts @@ -22,7 +22,7 @@ import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreCourse, CoreCourseWSSection } from '@features/course/services/course'; import { CoreCourseHelper, CoreCourseModuleData } from '@features/course/services/course-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; import { CORE_COURSE_CONTENTS_PAGE_NAME, CORE_COURSE_PROGRESS_UPDATED_EVENT } from '@features/course/constants'; import { CoreDomUtils } from '@services/utils/dom'; @@ -234,7 +234,7 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy { this.updateProgress(); // Load sections. - this.sections = await CoreUtils.ignoreErrors(CoreCourse.getSections(this.course.id, false, true), []); + this.sections = await CorePromiseUtils.ignoreErrors(CoreCourse.getSections(this.course.id, false, true), []); if (!this.sections) { return; diff --git a/src/core/features/course/pages/list-mod-type/list-mod-type.ts b/src/core/features/course/pages/list-mod-type/list-mod-type.ts index d4626e320..5cdad52e0 100644 --- a/src/core/features/course/pages/list-mod-type/list-mod-type.ts +++ b/src/core/features/course/pages/list-mod-type/list-mod-type.ts @@ -20,7 +20,7 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg import { CoreCourseHelper, CoreCourseSection } from '@features/course/services/course-helper'; import { CoreNavigator } from '@services/navigator'; import { CoreConstants } from '@/core/constants'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; @@ -190,7 +190,7 @@ export class CoreCourseListModTypePage implements OnInit { * @param refresher Refresher. */ async refreshData(refresher: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(CoreCourse.invalidateSections(this.courseId)); + await CorePromiseUtils.ignoreErrors(CoreCourse.invalidateSections(this.courseId)); try { await this.fetchData(); diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 8cba6bc00..189669b15 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -82,6 +82,7 @@ import { CORE_COURSE_STEALTH_MODULES_SECTION_ID, CORE_COURSE_COMPONENT, } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Prefetch info of a module. @@ -443,7 +444,7 @@ export class CoreCourseHelperProvider { options.onProgress({ count: 0, total: total, success: true }); } - return CoreUtils.allPromises(promises); + return CorePromiseUtils.allPromises(promises); } /** @@ -1302,7 +1303,7 @@ export class CoreCourseHelperProvider { // If this function is changed to do more actions if invalidateCache=true, please review those modules. CoreCourseModulePrefetchDelegate.invalidateModuleStatusCache(module); - await CoreUtils.ignoreErrors(CoreCourseModulePrefetchDelegate.invalidateCourseUpdates(courseId)); + await CorePromiseUtils.ignoreErrors(CoreCourseModulePrefetchDelegate.invalidateCourseUpdates(courseId)); } const [size, status, packageData] = await Promise.all([ @@ -1355,7 +1356,7 @@ export class CoreCourseHelperProvider { component = '', ): Promise { const siteId = CoreSites.getCurrentSiteId(); - const packageData = await CoreUtils.ignoreErrors(CoreFilepool.getPackageData(siteId, component, module.id)); + const packageData = await CorePromiseUtils.ignoreErrors(CoreFilepool.getPackageData(siteId, component, module.id)); // Treat download time. if ( @@ -1600,7 +1601,7 @@ export class CoreCourseHelperProvider { promises.push(CoreFilterHelper.getFilters(ContextLevel.COURSE, course.id)); - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); // Download success, mark the course as downloaded. return CoreCourse.setCourseStatus(course.id, DownloadStatus.DOWNLOADED, requiredSiteId); @@ -1639,7 +1640,7 @@ export class CoreCourseHelperProvider { // Invalidate content if refreshing and download the data. if (refresh) { - await CoreUtils.ignoreErrors(handler.invalidateContent(module.id, courseId)); + await CorePromiseUtils.ignoreErrors(handler.invalidateContent(module.id, courseId)); } await CoreCourseModulePrefetchDelegate.prefetchModule(module, courseId, true); @@ -1687,7 +1688,7 @@ export class CoreCourseHelperProvider { }); try { - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); // Set "All sections" data. if (allSectionsSection) { @@ -1724,7 +1725,7 @@ export class CoreCourseHelperProvider { // Download the files in the section description. const introFiles = CoreFilepool.extractDownloadableFilesFromHtmlAsFakeFileObjects(section.summary); - promises.push(CoreUtils.ignoreErrors( + promises.push(CorePromiseUtils.ignoreErrors( CoreFilepool.addFilesToQueue(siteId, introFiles, CORE_COURSE_COMPONENT, courseId), )); @@ -1862,11 +1863,11 @@ export class CoreCourseHelperProvider { */ async userHasAccessToCourse(courseId: number): Promise { if (CoreNetwork.isOnline()) { - return CoreUtils.promiseWorks( + return CorePromiseUtils.promiseWorks( CoreCourse.getSections(courseId, true, true, { getFromCache: false, emergencyCache: false }, undefined, false), ); } else { - return CoreUtils.promiseWorks( + return CorePromiseUtils.promiseWorks( CoreCourse.getSections(courseId, true, true, { getCacheUsingCacheKey: true }, undefined, false), ); } diff --git a/src/core/features/course/services/course-options-delegate.ts b/src/core/features/course/services/course-options-delegate.ts index 77c3325e2..949f113a0 100644 --- a/src/core/features/course/services/course-options-delegate.ts +++ b/src/core/features/course/services/course-options-delegate.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreDelegate, CoreDelegateHandler, CoreDelegateToDisplay } from '@classes/delegate'; import { CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreCourseAnyCourseData, CoreCourseAnyCourseDataWithOptions, @@ -573,7 +573,7 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate { // Run the handler the app is open to keep user in online status. setTimeout(() => { - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( CoreCronDelegate.forceCronHandlerExecution(CoreCourseLogCronHandler.name), ); }, 1000); @@ -184,7 +185,7 @@ export class CoreCourseProvider { CoreEvents.on(CoreEvents.LOGIN, () => { setTimeout(() => { // Ignore errors here, since probably login is not complete: it happens on token invalid. - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( CoreCronDelegate.forceCronHandlerExecution(CoreCourseLogCronHandler.name), ); }, 1000); @@ -1319,7 +1320,7 @@ export class CoreCourseProvider { const result = await this.markCompletedManuallyOnline(cmId, completed, siteId); // Data sent to server, if there is some offline data delete it now. - await CoreUtils.ignoreErrors(CoreCourseOffline.deleteManualCompletion(cmId, siteId)); + await CorePromiseUtils.ignoreErrors(CoreCourseOffline.deleteManualCompletion(cmId, siteId)); // Invalidate module now, completion has changed. await this.invalidateModule(cmId, siteId); @@ -1430,7 +1431,7 @@ export class CoreCourseProvider { const loading = await CoreLoadings.show(); // Wait for site plugins to be fetched. - await CoreUtils.ignoreErrors(CoreSitePlugins.waitFetchPlugins()); + await CorePromiseUtils.ignoreErrors(CoreSitePlugins.waitFetchPlugins()); if (!('format' in course) || course.format === undefined) { const result = await CoreCourseHelper.getCourse(course.id); diff --git a/src/core/features/course/services/handlers/default-format.ts b/src/core/features/course/services/handlers/default-format.ts index 383a645fc..a9bf0eca3 100644 --- a/src/core/features/course/services/handlers/default-format.ts +++ b/src/core/features/course/services/handlers/default-format.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreCourseAnyCourseData, CoreCourses } from '@features/courses/services/courses'; import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { CoreCourseSection } from '../course-helper'; import { CoreCourseFormatCurrentSectionData, CoreCourseFormatHandler } from '../format-delegate'; @@ -86,7 +86,7 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler { marker = course.marker; } else { // Try to retrieve the marker. - const courseData = await CoreUtils.ignoreErrors(CoreCourses.getCourseByField('id', course.id)); + const courseData = await CorePromiseUtils.ignoreErrors(CoreCourses.getCourseByField('id', course.id)); marker = courseData?.marker; } diff --git a/src/core/features/course/services/log-helper.ts b/src/core/features/course/services/log-helper.ts index 41deadb21..20ee04f29 100644 --- a/src/core/features/course/services/log-helper.ts +++ b/src/core/features/course/services/log-helper.ts @@ -23,6 +23,7 @@ import { makeSingleton } from '@singletons'; import { ACTIVITY_LOG_TABLE, CoreCourseActivityLogDBRecord } from './database/log'; import { CoreStatusWithWarningsWSResponse } from '@services/ws'; import { CoreWSError } from '@classes/errors/wserror'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Helper to manage logging to Moodle. @@ -345,7 +346,7 @@ export class CoreCourseLogHelperProvider { } catch (error) { if (CoreUtils.isWebServiceError(error)) { // The WebService has thrown an error, this means that responses cannot be submitted. - await CoreUtils.ignoreErrors(this.deleteWSLogs(log.ws, data, siteId)); + await CorePromiseUtils.ignoreErrors(this.deleteWSLogs(log.ws, data, siteId)); } throw error; diff --git a/src/core/features/course/services/module-prefetch-delegate.ts b/src/core/features/course/services/module-prefetch-delegate.ts index 330de8d0a..4c8a63204 100644 --- a/src/core/features/course/services/module-prefetch-delegate.ts +++ b/src/core/features/course/services/module-prefetch-delegate.ts @@ -34,6 +34,7 @@ import { CoreWSFile, CoreWSExternalWarning } from '@services/ws'; import { CHECK_UPDATES_TIMES_TABLE, CoreCourseCheckUpdatesDBRecord } from './database/module-prefetch'; import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreCourseHelper, CoreCourseModuleData } from './course-helper'; +import { CorePromiseUtils } from '@singletons/promise-utils'; const ROOT_CACHE_KEY = 'mmCourse:'; @@ -286,7 +287,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate this.syncModule(module, courseId))); } finally { // Invalidate course updates. - await CoreUtils.ignoreErrors(this.invalidateCourseUpdates(courseId)); + await CorePromiseUtils.ignoreErrors(this.invalidateCourseUpdates(courseId)); } } @@ -1138,7 +1139,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { - await CoreUtils.ignoreErrors(CoreFilepool.removeFileByUrl(siteId, CoreFileHelper.getFileUrl(file))); + await CorePromiseUtils.ignoreErrors(CoreFilepool.removeFileByUrl(siteId, CoreFileHelper.getFileUrl(file))); })); } diff --git a/src/core/features/course/services/sync.ts b/src/core/features/course/services/sync.ts index b7eabf17c..ec51dd5e5 100644 --- a/src/core/features/course/services/sync.ts +++ b/src/core/features/course/services/sync.ts @@ -30,6 +30,7 @@ import { makeSingleton, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { CoreCourses } from '@features/courses/services/courses'; import { CORE_COURSE_AUTO_SYNCED } from '../constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync course offline data. This only syncs the offline data of the course itself, not the offline data of @@ -82,7 +83,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider { if (courseNames[completion.courseid] === undefined) { - const course = await CoreUtils.ignoreErrors(CoreCourses.getUserCourse(completion.courseid, true, siteId)); + const course = await CorePromiseUtils.ignoreErrors(CoreCourses.getUserCourse(completion.courseid, true, siteId)); courseNames[completion.courseid] = course?.displayname || course?.fullname; } @@ -153,7 +154,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider [], ); diff --git a/src/core/features/courses/pages/dashboard/dashboard.ts b/src/core/features/courses/pages/dashboard/dashboard.ts index 5db3bed54..50789a2c9 100644 --- a/src/core/features/courses/pages/dashboard/dashboard.ts +++ b/src/core/features/courses/pages/dashboard/dashboard.ts @@ -26,7 +26,7 @@ import { CoreBlockDelegate } from '@features/block/services/block-delegate'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { Translate } from '@singletons'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays the dashboard page. @@ -61,7 +61,7 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy { }, CoreSites.getCurrentSiteId()); this.logView = CoreTime.once(async () => { - await CoreUtils.ignoreErrors(CoreCourses.logView('dashboard')); + await CorePromiseUtils.ignoreErrors(CoreCourses.logView('dashboard')); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, diff --git a/src/core/features/courses/pages/my/my.ts b/src/core/features/courses/pages/my/my.ts index 98ab613d3..f7a9379ae 100644 --- a/src/core/features/courses/pages/my/my.ts +++ b/src/core/features/courses/pages/my/my.ts @@ -23,7 +23,7 @@ import { CoreCourseBlock } from '@features/course/services/course'; import { CoreCoursesDashboard, CoreCoursesDashboardProvider } from '@features/courses/services/dashboard'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { Subscription } from 'rxjs'; import { CoreCourses } from '../../services/courses'; @@ -78,7 +78,7 @@ export class CoreCoursesMyPage implements OnInit, OnDestroy, AsyncDirective { }); this.logView = CoreTime.once(async () => { - await CoreUtils.ignoreErrors(CoreCourses.logView('my')); + await CorePromiseUtils.ignoreErrors(CoreCourses.logView('my')); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, @@ -187,7 +187,7 @@ export class CoreCoursesMyPage implements OnInit, OnDestroy, AsyncDirective { // Invalidate the blocks. if (this.myOverviewBlock) { - promises.push(CoreUtils.ignoreErrors(this.myOverviewBlock.invalidateContent())); + promises.push(CorePromiseUtils.ignoreErrors(this.myOverviewBlock.invalidateContent())); } Promise.all(promises).finally(() => { diff --git a/src/core/features/courses/services/handlers/base-link-handler.ts b/src/core/features/courses/services/handlers/base-link-handler.ts index e8cf40720..7e09c897a 100644 --- a/src/core/features/courses/services/handlers/base-link-handler.ts +++ b/src/core/features/courses/services/handlers/base-link-handler.ts @@ -17,7 +17,7 @@ import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourses } from '../courses'; import { Params } from '@angular/router'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreNavigator } from '@services/navigator'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; import { CoreSites } from '@services/sites'; @@ -49,7 +49,7 @@ export class CoreCoursesLinksHandlerBase extends CoreContentLinksHandlerBase { return; } - await CoreUtils.ignoreErrors(this.actionOpen(courseId, url, pageParams)); + await CorePromiseUtils.ignoreErrors(this.actionOpen(courseId, url, pageParams)); return; } @@ -86,7 +86,7 @@ export class CoreCoursesLinksHandlerBase extends CoreContentLinksHandlerBase { if (hasAccess && !guestInfo.guestAccess && !guestInfo.requiresUserInput) { // Direct access. - const course = await CoreUtils.ignoreErrors(CoreCourses.getUserCourse(courseId), { id: courseId }); + const course = await CorePromiseUtils.ignoreErrors(CoreCourses.getUserCourse(courseId), { id: courseId }); CoreCourseHelper.openCourse(course, { params: pageParams }); } else { diff --git a/src/core/features/courses/services/handlers/dashboard-home.ts b/src/core/features/courses/services/handlers/dashboard-home.ts index 343a5c20b..17858c1d3 100644 --- a/src/core/features/courses/services/handlers/dashboard-home.ts +++ b/src/core/features/courses/services/handlers/dashboard-home.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreBlockDelegate } from '@features/block/services/block-delegate'; import { CoreMainMenuHomeHandler, CoreMainMenuHomeHandlerToDisplay } from '@features/mainmenu/services/home-delegate'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { CoreCoursesDashboard } from '../dashboard'; @@ -60,7 +60,7 @@ export class CoreDashboardHomeHandlerService implements CoreMainMenuHomeHandler CoreBlockDelegate.areBlocksDisabled(site.getId()), CoreCoursesDashboard.isDisabled(site.getId()), CoreCoursesDashboard.isAvailable(site.getId()), - CoreUtils.ignoreErrors(site.getConfig('enabledashboard'), '1'), + CorePromiseUtils.ignoreErrors(site.getConfig('enabledashboard'), '1'), ]); const dashboardEnabled = !dashboardDisabled && dashboardConfig !== '0'; diff --git a/src/core/features/courses/services/handlers/request-push-click.ts b/src/core/features/courses/services/handlers/request-push-click.ts index 731589af3..e531ffe1c 100644 --- a/src/core/features/courses/services/handlers/request-push-click.ts +++ b/src/core/features/courses/services/handlers/request-push-click.ts @@ -25,6 +25,7 @@ import { makeSingleton } from '@singletons'; import { CorePath } from '@singletons/path'; import { CoreCourses } from '../courses'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler for course request push notifications clicks. @@ -69,7 +70,7 @@ export class CoreCoursesRequestPushClickHandlerService implements CorePushNotifi // Open the course. const modal = await CoreLoadings.show(); - await CoreUtils.ignoreErrors(CoreCourses.invalidateUserCourses(notification.site)); + await CorePromiseUtils.ignoreErrors(CoreCourses.invalidateUserCourses(notification.site)); try { const result = await CoreCourseHelper.getCourse(courseId, notification.site); diff --git a/src/core/features/courses/services/handlers/section-link.ts b/src/core/features/courses/services/handlers/section-link.ts index 933debb7c..617dc743d 100644 --- a/src/core/features/courses/services/handlers/section-link.ts +++ b/src/core/features/courses/services/handlers/section-link.ts @@ -20,7 +20,7 @@ import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreCourse } from '@features/course/services/course'; import { CoreCoursesLinksHandlerBase } from '@features/courses/services/handlers/base-link-handler'; import { CoreLogger } from '@singletons/logger'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler to treat links to course section. @@ -85,12 +85,12 @@ export class CoreCoursesSectionLinkHandlerService extends CoreCoursesLinksHandle // Given that getting all the courses from a user could be very network intensive, the following // requests will only use cache. - const courses = await CoreUtils.ignoreErrors( + const courses = await CorePromiseUtils.ignoreErrors( CoreCourses.getUserCourses(true, siteId, CoreSitesReadingStrategy.ONLY_CACHE), ) ?? []; for (const course of courses) { - const courseSections = await CoreUtils.ignoreErrors(CoreCourse.getSections( + const courseSections = await CorePromiseUtils.ignoreErrors(CoreCourse.getSections( course.id, true, true, diff --git a/src/core/features/dataprivacy/components/contactdpo/contactdpo.ts b/src/core/features/dataprivacy/components/contactdpo/contactdpo.ts index 467b23340..f9cce9830 100644 --- a/src/core/features/dataprivacy/components/contactdpo/contactdpo.ts +++ b/src/core/features/dataprivacy/components/contactdpo/contactdpo.ts @@ -20,7 +20,7 @@ import { CoreUser } from '@features/user/services/user'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreToasts, ToastDuration } from '@services/toasts'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ModalController } from '@singletons'; import { CoreLoadings } from '@services/loadings'; @@ -62,7 +62,7 @@ export class CoreDataPrivacyContactDPOComponent implements OnInit { // Get current user email. const userId = CoreSites.getCurrentSiteUserId(); - const user = await CoreUtils.ignoreErrors(CoreUser.getProfile(userId)); + const user = await CorePromiseUtils.ignoreErrors(CoreUser.getProfile(userId)); this.email = user?.email || ''; diff --git a/src/core/features/dataprivacy/pages/main/main.ts b/src/core/features/dataprivacy/pages/main/main.ts index 35468473f..3363004b8 100644 --- a/src/core/features/dataprivacy/pages/main/main.ts +++ b/src/core/features/dataprivacy/pages/main/main.ts @@ -24,7 +24,7 @@ import { CoreModals } from '@services/modals'; import { CoreNavigator } from '@services/navigator'; import { CoreScreen } from '@services/screen'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { Subscription } from 'rxjs'; @@ -102,11 +102,11 @@ export class CoreDataPrivacyMainPage implements OnInit { * @param refresher Refresher. */ async refreshContent(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreDataPrivacy.invalidateAll(), ); - await CoreUtils.ignoreErrors(this.fetchContent()); + await CorePromiseUtils.ignoreErrors(this.fetchContent()); refresher?.complete(); } diff --git a/src/core/features/fileuploader/services/fileuploader.ts b/src/core/features/fileuploader/services/fileuploader.ts index a4ca5c9d0..6e6974ea1 100644 --- a/src/core/features/fileuploader/services/fileuploader.ts +++ b/src/core/features/fileuploader/services/fileuploader.ts @@ -33,6 +33,7 @@ import { CoreFileEntry, CoreFileHelper } from '@services/file-helper'; import { CorePath } from '@singletons/path'; import { CorePlatform } from '@services/platform'; import { CoreModals } from '@services/modals'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * File upload options. @@ -401,7 +402,7 @@ export class CoreFileUploaderProvider { } if (filesObject.offline > 0) { - const offlineFiles = await CoreUtils.ignoreErrors(this.getStoredFiles(folderPath)); + const offlineFiles = await CorePromiseUtils.ignoreErrors(this.getStoredFiles(folderPath)); if (offlineFiles) { files = files.concat(offlineFiles); diff --git a/src/core/features/filter/services/filter-helper.ts b/src/core/features/filter/services/filter-helper.ts index 1dfebafc8..104e3be2d 100644 --- a/src/core/features/filter/services/filter-helper.ts +++ b/src/core/features/filter/services/filter-helper.ts @@ -35,7 +35,7 @@ import { CoreSite } from '@classes/sites/site'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { firstValueFrom } from 'rxjs'; import { ContextLevel, CoreCacheUpdateFrequency } from '@/core/constants'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Helper service to provide filter functionalities. @@ -118,7 +118,7 @@ export class CoreFilterHelperProvider { async getCategoryContexts(categoryId: number, siteId?: string): Promise { // Get the categories of courses the user is enrolled in to decrease the number of WS requests. // Using CoreCourses.getCategories would group more categories, but it would require a new WS request. - const courses = await CoreUtils.ignoreErrors(CoreCourses.getUserCourses(true, siteId)); + const courses = await CorePromiseUtils.ignoreErrors(CoreCourses.getUserCourses(true, siteId)); const categoriesIds = (courses ?? []).map(course => course.categoryid) .filter((categoryId): categoryId is number => categoryId !== undefined); diff --git a/src/core/features/grades/pages/course/course.page.ts b/src/core/features/grades/pages/course/course.page.ts index dcad4db9e..085f36489 100644 --- a/src/core/features/grades/pages/course/course.page.ts +++ b/src/core/features/grades/pages/course/course.page.ts @@ -24,7 +24,7 @@ import { CoreGradesHelper, } from '@features/grades/services/grades-helper'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreNavigator } from '@services/navigator'; import { CoreScreen } from '@services/screen'; import { Translate } from '@singletons'; @@ -185,8 +185,8 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { * @param refresher Refresher. */ async refreshGrades(refresher: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(CoreGrades.invalidateCourseGradesData(this.courseId, this.userId)); - await CoreUtils.ignoreErrors(this.fetchGrades()); + await CorePromiseUtils.ignoreErrors(CoreGrades.invalidateCourseGradesData(this.courseId, this.userId)); + await CorePromiseUtils.ignoreErrors(this.fetchGrades()); refresher?.complete(); } @@ -261,7 +261,7 @@ export class CoreGradesCoursePage implements AfterViewInit, OnDestroy { * Log view. */ protected async performLogView(): Promise { - await CoreUtils.ignoreErrors(CoreGrades.logCourseGradesView(this.courseId, this.userId)); + await CorePromiseUtils.ignoreErrors(CoreGrades.logCourseGradesView(this.courseId, this.userId)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, diff --git a/src/core/features/grades/pages/courses/courses.ts b/src/core/features/grades/pages/courses/courses.ts index 91f309cbb..140bc18af 100644 --- a/src/core/features/grades/pages/courses/courses.ts +++ b/src/core/features/grades/pages/courses/courses.ts @@ -22,7 +22,7 @@ import { CoreGrades } from '@features/grades/services/grades'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; /** @@ -66,8 +66,8 @@ export class CoreGradesCoursesPage implements OnDestroy, AfterViewInit { * @param refresher Refresher. */ async refreshCourses(refresher: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(CoreGrades.invalidateCoursesGradesData()); - await CoreUtils.ignoreErrors(this.courses.reload()); + await CorePromiseUtils.ignoreErrors(CoreGrades.invalidateCoursesGradesData()); + await CorePromiseUtils.ignoreErrors(this.courses.reload()); refresher?.complete(); } diff --git a/src/core/features/grades/services/grades-helper.ts b/src/core/features/grades/services/grades-helper.ts index 70da26191..c4884b74e 100644 --- a/src/core/features/grades/services/grades-helper.ts +++ b/src/core/features/grades/services/grades-helper.ts @@ -46,6 +46,7 @@ import { CoreCourseAccess } from '@features/course/services/course-options-deleg import { CoreLoadings } from '@services/loadings'; import { convertTextToHTMLElement } from '@/core/utils/create-html-element'; import { CoreCourseAccessDataType } from '@features/course/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; export const GRADES_PAGE_NAME = 'grades'; export const GRADES_PARTICIPANTS_PAGE_NAME = 'participant-grades'; @@ -469,7 +470,7 @@ export class CoreGradesHelperProvider { // Open the item directly. const gradeId = item.id; - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreNavigator.navigateToSitePath( `/${GRADES_PAGE_NAME}/${courseId}`, { params: { gradeId }, siteId }, @@ -480,7 +481,7 @@ export class CoreGradesHelperProvider { // Cannot get grade items or there's no need to. if (userId && userId != currentUserId) { // View another user grades. Open the grades page directly. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreNavigator.navigateToSitePath(`/${GRADES_PAGE_NAME}/${courseId}`, { siteId }), ); } diff --git a/src/core/features/grades/services/handlers/user.ts b/src/core/features/grades/services/handlers/user.ts index e0d92f668..c295c4c61 100644 --- a/src/core/features/grades/services/handlers/user.ts +++ b/src/core/features/grades/services/handlers/user.ts @@ -26,7 +26,7 @@ import { import { PARTICIPANTS_PAGE_NAME } from '@features/user/constants'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { GRADES_PAGE_NAME } from '../grades-helper'; @@ -68,7 +68,7 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { } if (context === CoreUserDelegateContext.COURSE) { - return CoreUtils.ignoreErrors(CoreGrades.isPluginEnabledForCourse(courseId), false); + return CorePromiseUtils.ignoreErrors(CoreGrades.isPluginEnabledForCourse(courseId), false); } else { return CoreGrades.isCourseGradesEnabled(); } @@ -79,7 +79,7 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { */ async isEnabledForUser(user: CoreUserProfile, context: CoreUserDelegateContext, contextId: number): Promise { if (context === CoreUserDelegateContext.COURSE) { - return CoreUtils.promiseWorks(CoreGrades.getCourseGradesTable(contextId, user.id)); + return CorePromiseUtils.promiseWorks(CoreGrades.getCourseGradesTable(contextId, user.id)); } // All course grades only available for the current user. diff --git a/src/core/features/h5p/classes/file-storage.ts b/src/core/features/h5p/classes/file-storage.ts index 50d1c93ea..3462cd75e 100644 --- a/src/core/features/h5p/classes/file-storage.ts +++ b/src/core/features/h5p/classes/file-storage.ts @@ -17,7 +17,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreSites } from '@services/sites'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CorePath } from '@singletons/path'; import { CoreH5PCore, @@ -154,7 +154,7 @@ export class CoreH5PFileStorage { }); // Ignore errors, maybe there's no cached asset of some type. - await CoreUtils.ignoreErrors(CoreUtils.allPromises(promises)); + await CorePromiseUtils.allPromisesIgnoringErrors(promises); } /** @@ -418,7 +418,7 @@ export class CoreH5PFileStorage { const folderPath = this.getContentFolderPath(folderName, siteId); // Delete existing content for this package. - await CoreUtils.ignoreErrors(CoreFile.removeDir(folderPath)); + await CorePromiseUtils.ignoreErrors(CoreFile.removeDir(folderPath)); // Copy the new one. await CoreFile.moveDir(contentPath, folderPath); diff --git a/src/core/features/h5p/classes/player.ts b/src/core/features/h5p/classes/player.ts index 3dcdadb60..fc104fc98 100644 --- a/src/core/features/h5p/classes/player.ts +++ b/src/core/features/h5p/classes/player.ts @@ -22,6 +22,7 @@ import { CoreH5PCoreSettings, CoreH5PHelper } from './helper'; import { CoreH5PStorage } from './storage'; import { CorePath } from '@singletons/path'; import { CoreXAPIIRI } from '@features/xapi/classes/iri'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Equivalent to Moodle's H5P player class. @@ -175,7 +176,7 @@ export class CoreH5PPlayer { const records = await this.h5pCore.h5pFramework.getAllContentData(siteIdentifier); await Promise.all(records.map(async (record) => { - await CoreUtils.ignoreErrors(this.h5pCore.h5pFS.deleteContentIndex(record.foldername, siteIdentifier)); + await CorePromiseUtils.ignoreErrors(this.h5pCore.h5pFS.deleteContentIndex(record.foldername, siteIdentifier)); })); } @@ -191,7 +192,7 @@ export class CoreH5PPlayer { const data = await this.h5pCore.h5pFramework.getContentDataByUrl(fileUrl, siteId); - await CoreUtils.allPromises([ + await CorePromiseUtils.allPromises([ this.h5pCore.h5pFramework.deleteContentData(data.id, siteId), this.h5pCore.h5pFS.deleteContentFolder(data.foldername, siteId), @@ -298,7 +299,7 @@ export class CoreH5PPlayer { params.state = otherOptions.state; } - const customCssUrl = await CoreUtils.ignoreErrors(CoreH5P.getCustomCssSrc(siteId)); + const customCssUrl = await CorePromiseUtils.ignoreErrors(CoreH5P.getCustomCssSrc(siteId)); if (customCssUrl) { params.customCssUrl = customCssUrl; } diff --git a/src/core/features/h5p/classes/storage.ts b/src/core/features/h5p/classes/storage.ts index 4ddf8a546..968324d8f 100644 --- a/src/core/features/h5p/classes/storage.ts +++ b/src/core/features/h5p/classes/storage.ts @@ -14,7 +14,7 @@ import { CoreFile, CoreFileProvider } from '@services/file'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CorePath } from '@singletons/path'; import { CoreH5PCore, CoreH5PLibraryBasicData } from './core'; import { CoreH5PFramework } from './framework'; @@ -57,7 +57,7 @@ export class CoreH5PStorage { const libraryData: CoreH5PLibraryBeingSaved = librariesJsonData[libString]; // Find local library with same major + minor. - const existingLibrary = await CoreUtils.ignoreErrors(this.h5pFramework.getLibraryByData(libraryData)); + const existingLibrary = await CorePromiseUtils.ignoreErrors(this.h5pFramework.getLibraryByData(libraryData)); if (existingLibrary) { // Library already installed. @@ -100,7 +100,7 @@ export class CoreH5PStorage { await this.h5pCore.h5pFS.deleteCachedAssets(removedEntries, siteId); } - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } })); diff --git a/src/core/features/h5p/services/h5p.ts b/src/core/features/h5p/services/h5p.ts index 32bb9c1c1..d3283b853 100644 --- a/src/core/features/h5p/services/h5p.ts +++ b/src/core/features/h5p/services/h5p.ts @@ -32,7 +32,7 @@ import { CorePath } from '@singletons/path'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { CoreFilepool } from '@services/filepool'; import { CoreCacheUpdateFrequency, DownloadStatus } from '@/core/constants'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to provide H5P functionalities. @@ -103,7 +103,7 @@ export class CoreH5PProvider { const state = await CoreFilepool.getFileStateByUrl(site.getId(), customCssUrl); if (state === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) { // File not downloaded, URL has changed or first time. Delete previously downloaded file. - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreFilepool.removeFilesByComponent(site.getId(), CoreH5PProvider.CUSTOM_CSS_COMPONENT, 1), ); } diff --git a/src/core/features/login/guards/has-sites.ts b/src/core/features/login/guards/has-sites.ts index af2b7f9d8..64075d985 100644 --- a/src/core/features/login/guards/has-sites.ts +++ b/src/core/features/login/guards/has-sites.ts @@ -14,7 +14,7 @@ import { CanActivateFn } from '@angular/router'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Router } from '@singletons'; import { CoreLoginHelper } from '../services/login-helper'; @@ -24,7 +24,7 @@ import { CoreLoginHelper } from '../services/login-helper'; * @returns True if user has sites, redirect route otherwise. */ export const hasSitesGuard: CanActivateFn = async () => { - const sites = await CoreUtils.ignoreErrors(CoreSites.getSites(), []); + const sites = await CorePromiseUtils.ignoreErrors(CoreSites.getSites(), []); if (sites.length > 0) { return true; diff --git a/src/core/features/login/pages/email-signup/email-signup.ts b/src/core/features/login/pages/email-signup/email-signup.ts index 116187045..7c7e1c5ac 100644 --- a/src/core/features/login/pages/email-signup/email-signup.ts +++ b/src/core/features/login/pages/email-signup/email-signup.ts @@ -38,6 +38,7 @@ import { EMAIL_SIGNUP_FEATURE_NAME } from '@features/login/constants'; import { CoreInputErrorsMessages } from '@components/input-errors/input-errors'; import { CoreViewer } from '@features/viewer/services/viewer'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page to signup using email. @@ -189,7 +190,7 @@ export class CoreLoginEmailSignupPage implements OnInit { // Check content verification. if (this.ageDigitalConsentVerification === undefined) { - const result = await CoreUtils.ignoreErrors( + const result = await CorePromiseUtils.ignoreErrors( CoreWS.callAjax( 'core_auth_is_age_digital_consent_verification_enabled', {}, diff --git a/src/core/features/login/pages/reconnect/reconnect.ts b/src/core/features/login/pages/reconnect/reconnect.ts index cb48ce043..684d36a1e 100644 --- a/src/core/features/login/pages/reconnect/reconnect.ts +++ b/src/core/features/login/pages/reconnect/reconnect.ts @@ -18,7 +18,7 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { CoreNetwork } from '@services/network'; import { CoreSiteBasicInfo, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreLoginHelper } from '@features/login/services/login-helper'; import { CoreSite } from '@classes/sites/site'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; @@ -180,7 +180,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy { * Get some data (like identity providers) from the site config. */ protected async checkSiteConfig(): Promise { - this.siteConfig = await CoreUtils.ignoreErrors(this.site.getPublicConfig({ + this.siteConfig = await CorePromiseUtils.ignoreErrors(this.site.getPublicConfig({ readingStrategy: CoreSitesReadingStrategy.PREFER_NETWORK, })); diff --git a/src/core/features/login/pages/site/site.ts b/src/core/features/login/pages/site/site.ts index 586c8761d..90fe27480 100644 --- a/src/core/features/login/pages/site/site.ts +++ b/src/core/features/login/pages/site/site.ts @@ -49,6 +49,7 @@ import { CoreKeyboard } from '@singletons/keyboard'; import { CoreModals } from '@services/modals'; import { CoreQRScan } from '@services/qrscan'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Site (url) chooser when adding a new site. @@ -172,12 +173,15 @@ export class CoreLoginSitePage implements OnInit { * @returns Referrer URL, undefined if no URL to use. */ protected async consumeInstallReferrerUrl(): Promise { - const url = await CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(CoreReferrer.consumeInstallReferrerUrl(), 1000)); + const url = await CorePromiseUtils.ignoreErrors( + CorePromiseUtils.timeoutPromise(CoreReferrer.consumeInstallReferrerUrl(), 1000), + ); + if (!url) { return; } - const hasSites = (await CoreUtils.ignoreErrors(CoreSites.getSites(), [])).length > 0; + const hasSites = (await CorePromiseUtils.ignoreErrors(CoreSites.getSites(), [])).length > 0; if (hasSites) { // There are sites stored already, don't use the referrer URL since it's an update or a backup was restored. return; diff --git a/src/core/features/login/services/handlers/cron.ts b/src/core/features/login/services/handlers/cron.ts index 3b6c53838..f488363f2 100644 --- a/src/core/features/login/services/handlers/cron.ts +++ b/src/core/features/login/services/handlers/cron.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreCronHandler } from '@services/cron'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; /** @@ -39,11 +39,11 @@ export class CoreLoginCronHandlerService implements CoreCronHandler { // Do not check twice in the same 10 minutes. const site = await CoreSites.getSite(siteId); - const config = await CoreUtils.ignoreErrors(site.getPublicConfig({ + const config = await CorePromiseUtils.ignoreErrors(site.getPublicConfig({ readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, })); - CoreUtils.ignoreErrors(CoreSites.checkApplication(config)); + CorePromiseUtils.ignoreErrors(CoreSites.checkApplication(config)); } /** diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts index da13e6556..f25cd3d64 100644 --- a/src/core/features/login/services/login-helper.ts +++ b/src/core/features/login/services/login-helper.ts @@ -63,6 +63,7 @@ import { CoreLoadings } from '@services/loadings'; import { CoreErrorHelper } from '@services/error-helper'; import { CoreSSO } from '@singletons/sso'; import { CoreInAppBrowser } from '@singletons/iab'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Helper provider that provides some common features regarding authentication. @@ -374,7 +375,7 @@ export class CoreLoginHelperProvider { * @returns Valid identity providers. */ async getValidIdentityProvidersForSite(site: CoreUnauthenticatedSite): Promise { - const siteConfig = await CoreUtils.ignoreErrors(site.getPublicConfig()); + const siteConfig = await CorePromiseUtils.ignoreErrors(site.getPublicConfig()); if (!siteConfig) { return []; } @@ -876,7 +877,7 @@ export class CoreLoginHelperProvider { return; } - await CoreUtils.ignoreErrors(CoreNavigator.navigate('/login/reconnect', { + await CorePromiseUtils.ignoreErrors(CoreNavigator.navigate('/login/reconnect', { params: { siteId, ...redirectData, @@ -1332,7 +1333,7 @@ export class CoreLoginHelperProvider { * @returns Promise resolved with account list. */ async getAccountsList(): Promise { - const sites = await CoreUtils.ignoreErrors(CoreSites.getSortedSites(), [] as CoreSiteBasicInfo[]); + const sites = await CorePromiseUtils.ignoreErrors(CoreSites.getSortedSites(), [] as CoreSiteBasicInfo[]); const accountsList: CoreAccountsList = { sameSite: [], @@ -1350,7 +1351,7 @@ export class CoreLoginHelperProvider { // Add site counter and classify sites. await Promise.all(sites.map(async (site) => { - site.badge = await CoreUtils.ignoreErrors(CorePushNotifications.getSiteCounter(site.id)) || 0; + site.badge = await CorePromiseUtils.ignoreErrors(CorePushNotifications.getSiteCounter(site.id)) || 0; if (site.id === currentSiteId) { accountsList.currentSite = site; diff --git a/src/core/features/mainmenu/components/user-menu/user-menu.ts b/src/core/features/mainmenu/components/user-menu/user-menu.ts index 953565fbe..e52071150 100644 --- a/src/core/features/mainmenu/components/user-menu/user-menu.ts +++ b/src/core/features/mainmenu/components/user-menu/user-menu.ts @@ -32,7 +32,7 @@ import { CoreModals } from '@services/modals'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { ModalController, Translate } from '@singletons'; import { Subscription } from 'rxjs'; @@ -141,7 +141,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { return; } - const siteConfig = await CoreUtils.ignoreErrors(currentSite.getPublicConfig()); + const siteConfig = await CorePromiseUtils.ignoreErrors(currentSite.getPublicConfig()); this.siteLogo = currentSite.getLogoUrl(siteConfig); this.siteLogoLoaded = true; } diff --git a/src/core/features/policy/pages/acceptances/acceptances.ts b/src/core/features/policy/pages/acceptances/acceptances.ts index b044ee767..c41bf30dd 100644 --- a/src/core/features/policy/pages/acceptances/acceptances.ts +++ b/src/core/features/policy/pages/acceptances/acceptances.ts @@ -16,7 +16,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { Translate } from '@singletons'; import { CorePolicy, CorePolicySitePolicy, CorePolicyStatus } from '@features/policy/services/policy'; @@ -90,7 +90,7 @@ export class CorePolicyAcceptancesPage implements OnInit, OnDestroy { return; } - this.canContactDPO = await CoreUtils.ignoreErrors(CoreDataPrivacy.isEnabled(), false); + this.canContactDPO = await CorePromiseUtils.ignoreErrors(CoreDataPrivacy.isEnabled(), false); } /** @@ -164,9 +164,9 @@ export class CorePolicyAcceptancesPage implements OnInit, OnDestroy { * @param refresher Refresher. */ async refreshAcceptances(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(CorePolicy.invalidateAcceptances()); + await CorePromiseUtils.ignoreErrors(CorePolicy.invalidateAcceptances()); - await CoreUtils.ignoreErrors(this.fetchAcceptances()); + await CorePromiseUtils.ignoreErrors(this.fetchAcceptances()); refresher?.complete(); } diff --git a/src/core/features/policy/pages/site-policy/site-policy.ts b/src/core/features/policy/pages/site-policy/site-policy.ts index ef61c2edb..da486b70d 100644 --- a/src/core/features/policy/pages/site-policy/site-policy.ts +++ b/src/core/features/policy/pages/site-policy/site-policy.ts @@ -33,6 +33,7 @@ import { CoreDom } from '@singletons/dom'; import { CoreWait } from '@singletons/wait'; import { CoreModals } from '@services/modals'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page to accept a site policy. @@ -83,7 +84,7 @@ export class CorePolicySitePolicyPage implements OnInit, OnDestroy { try { this.currentSite = CoreSites.getRequiredCurrentSite(); - this.siteName = (await CoreUtils.ignoreErrors(this.currentSite.getSiteName(), '')) || ''; + this.siteName = (await CorePromiseUtils.ignoreErrors(this.currentSite.getSiteName(), '')) || ''; } catch { // Not logged in, stop. this.cancel(); @@ -280,7 +281,7 @@ export class CorePolicySitePolicyPage implements OnInit, OnDestroy { * @returns Promise resolved when done. */ async cancel(): Promise { - await CoreUtils.ignoreErrors(CoreSites.logout()); + await CorePromiseUtils.ignoreErrors(CoreSites.logout()); await CoreNavigator.navigate('/login/sites', { reset: true }); } @@ -442,7 +443,7 @@ export class CorePolicySitePolicyPage implements OnInit, OnDestroy { */ protected async finishAcceptingPolicies(): Promise { // Invalidate cache since some WS don't return error if site policy is not accepted. - await CoreUtils.ignoreErrors(this.currentSite.invalidateWsCache()); + await CorePromiseUtils.ignoreErrors(this.currentSite.invalidateWsCache()); CoreEvents.trigger(CoreEvents.SITE_POLICY_AGREED, {}, this.siteId); diff --git a/src/core/features/pushnotifications/services/push-delegate.ts b/src/core/features/pushnotifications/services/push-delegate.ts index af24f47c9..d75e0c9fc 100644 --- a/src/core/features/pushnotifications/services/push-delegate.ts +++ b/src/core/features/pushnotifications/services/push-delegate.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { CorePushNotificationsNotificationBasicData } from './pushnotifications'; @@ -102,7 +102,7 @@ export class CorePushNotificationsDelegateService { } }); - await CoreUtils.ignoreErrors(CoreUtils.allPromises(promises)); + await CorePromiseUtils.allPromisesIgnoringErrors(promises); // Sort by priority. handlers = handlers.sort((a, b) => (a.priority || 0) <= (b.priority || 0) ? 1 : -1); diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index b724407c4..4b151608a 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -56,6 +56,7 @@ import { Push } from '@features/native/plugins'; import { CoreNavigator } from '@services/navigator'; import { CoreWait } from '@singletons/wait'; import { MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT } from '@features/mainmenu/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to handle push notifications. @@ -579,7 +580,7 @@ export class CorePushNotificationsProvider { } catch (error) { if (CoreUtils.isWebServiceError(error) || CoreUtils.isExpiredTokenError(error)) { // Cannot unregister. Don't try again. - await CoreUtils.ignoreErrors(this.pendingUnregistersTable.delete({ + await CorePromiseUtils.ignoreErrors(this.pendingUnregistersTable.delete({ token: site.getToken(), siteid: site.getId(), })); @@ -602,7 +603,7 @@ export class CorePushNotificationsProvider { throw new CoreError('Cannot unregister device'); } - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ // Remove the device from the local DB. this.registeredDevicesTables[site.getId()].delete(this.getRequiredRegisterData()), // Remove pending unregisters for this site. @@ -751,7 +752,7 @@ export class CorePushNotificationsProvider { if (neededActions.unregister) { // Unregister the device first. - await CoreUtils.ignoreErrors(this.unregisterDeviceOnMoodle(site)); + await CorePromiseUtils.ignoreErrors(this.unregisterDeviceOnMoodle(site)); } if (neededActions.register) { @@ -769,7 +770,7 @@ export class CorePushNotificationsProvider { CoreEvents.trigger(CoreEvents.DEVICE_REGISTERED_IN_MOODLE, {}, site.getId()); // Insert the device in the local DB. - await CoreUtils.ignoreErrors(this.registeredDevicesTables[site.getId()].insert(data)); + await CorePromiseUtils.ignoreErrors(this.registeredDevicesTables[site.getId()].insert(data)); } else if (neededActions.updatePublicKey) { // Device already registered, make sure the public key is up to date. const response = await this.updatePublicKeyOnMoodle(site, data); @@ -789,7 +790,7 @@ export class CorePushNotificationsProvider { } } finally { // Remove pending unregisters for this site. - await CoreUtils.ignoreErrors(this.pendingUnregistersTable.deleteByPrimaryKey({ siteid: site.getId() })); + await CorePromiseUtils.ignoreErrors(this.pendingUnregistersTable.deleteByPrimaryKey({ siteid: site.getId() })); } } @@ -930,7 +931,7 @@ export class CorePushNotificationsProvider { } // Check if the device is already registered. - const records = await CoreUtils.ignoreErrors( + const records = await CorePromiseUtils.ignoreErrors( this.registeredDevicesTables[site.getId()].getMany({ appid: data.appid, uuid: data.uuid, diff --git a/src/core/features/question/components/question/question.ts b/src/core/features/question/components/question/question.ts index 79c8fa4d6..e1ac05885 100644 --- a/src/core/features/question/components/question/question.ts +++ b/src/core/features/question/components/question/question.ts @@ -22,7 +22,7 @@ import { CoreQuestionDelegate } from '@features/question/services/question-deleg import { CoreQuestionBehaviourButton, CoreQuestionHelper, CoreQuestionQuestion } from '@features/question/services/question-helper'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { CoreDirectivesRegistry } from '@singletons/directives-registry'; import { CoreLogger } from '@singletons/logger'; @@ -87,7 +87,7 @@ export class CoreQuestionComponent implements OnInit, AsyncDirective { } // Get the component to render the question. - this.componentClass = await CoreUtils.ignoreErrors( + this.componentClass = await CorePromiseUtils.ignoreErrors( CoreQuestionDelegate.getComponentForQuestion(this.question), ); diff --git a/src/core/features/question/services/question-helper.ts b/src/core/features/question/services/question-helper.ts index d8dc0c5fc..00eaf6f5f 100644 --- a/src/core/features/question/services/question-helper.ts +++ b/src/core/features/question/services/question-helper.ts @@ -33,6 +33,7 @@ import { CoreIonicColorNames } from '@singletons/colors'; import { CoreViewer } from '@features/viewer/services/viewer'; import { convertTextToHTMLElement } from '@/core/utils/create-html-element'; import { AddonModQuizNavigationQuestion } from '@addons/mod/quiz/components/navigation-modal/navigation-modal'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service with some common functions to handle questions. @@ -115,7 +116,7 @@ export class CoreQuestionHelperProvider { const folderPath = CoreQuestion.getQuestionFolder(question.type, component, questionComponentId, siteId); // Ignore errors, maybe the folder doesn't exist. - await CoreUtils.ignoreErrors(CoreFile.removeDir(folderPath)); + await CorePromiseUtils.ignoreErrors(CoreFile.removeDir(folderPath)); } /** @@ -570,7 +571,7 @@ export class CoreQuestionHelperProvider { * @returns Promise resolved when done. */ async loadLocalAnswers(question: CoreQuestionQuestion, component: string, attemptId: number): Promise { - const answers = await CoreUtils.ignoreErrors( + const answers = await CorePromiseUtils.ignoreErrors( CoreQuestion.getQuestionAnswers(component, attemptId, question.slot), ); @@ -715,7 +716,7 @@ export class CoreQuestionHelperProvider { componentId: string | number, siteId?: string, ): Promise { - await CoreUtils.allPromises(questions.map(async (question) => { + await CorePromiseUtils.allPromises(questions.map(async (question) => { await CoreQuestionDelegate.prepareAnswersForQuestion( question, answers, diff --git a/src/core/features/rating/services/rating-offline.ts b/src/core/features/rating/services/rating-offline.ts index b4a84aa2f..d848457f5 100644 --- a/src/core/features/rating/services/rating-offline.ts +++ b/src/core/features/rating/services/rating-offline.ts @@ -15,7 +15,7 @@ import { ContextLevel } from '@/core/constants'; import { Injectable } from '@angular/core'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { CoreRatingDBPrimaryData, CoreRatingDBRecord, RATINGS_TABLE } from './database/rating'; @@ -265,7 +265,7 @@ export class CoreRatingOfflineProvider { conditions.itemsetid = itemSetId; } - return CoreUtils.promiseWorks(site.getDb().recordExists(RATINGS_TABLE, conditions)); + return CorePromiseUtils.promiseWorks(site.getDb().recordExists(RATINGS_TABLE, conditions)); } } diff --git a/src/core/features/reminders/services/database/reminders.ts b/src/core/features/reminders/services/database/reminders.ts index 026d9fd7a..1f2763957 100644 --- a/src/core/features/reminders/services/database/reminders.ts +++ b/src/core/features/reminders/services/database/reminders.ts @@ -15,7 +15,7 @@ import { ADDON_CALENDAR_COMPONENT, ADDON_CALENDAR_EVENTS_TABLE } from '@addons/calendar/constants'; import { SQLiteDB } from '@classes/sqlitedb'; import { CoreSiteSchema } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreReminderData } from '../reminders'; import { AddonCalendarEventDBRecord } from '@addons/calendar/services/database/calendar'; import { REMINDERS_DEFAULT_REMINDER_TIMEBEFORE } from '@features/reminders/constants'; @@ -88,7 +88,7 @@ const migrateFromCalendarRemindersV1 = async (db: SQLiteDB): Promise => { // Migrate reminders. New format @since 4.0. const oldTable = 'addon_calendar_reminders'; - const tableExists = await CoreUtils.promiseWorks(db.tableExists(oldTable)); + const tableExists = await CorePromiseUtils.promiseWorks(db.tableExists(oldTable)); if (!tableExists) { return; } @@ -145,7 +145,7 @@ const migrateFromCalendarRemindersV1 = async (db: SQLiteDB): Promise => { const migrateFromCalendarRemindersV2 = async (db: SQLiteDB): Promise => { const oldTable = 'addon_calendar_reminders_2'; - const tableExists = await CoreUtils.promiseWorks(db.tableExists(oldTable)); + const tableExists = await CorePromiseUtils.promiseWorks(db.tableExists(oldTable)); if (!tableExists) { return; } diff --git a/src/core/features/reportbuilder/components/report-detail/report-detail.ts b/src/core/features/reportbuilder/components/report-detail/report-detail.ts index d715b88a7..c681a2081 100644 --- a/src/core/features/reportbuilder/components/report-detail/report-detail.ts +++ b/src/core/features/reportbuilder/components/report-detail/report-detail.ts @@ -32,6 +32,7 @@ import { Translate } from '@singletons'; import { CoreTime } from '@singletons/time'; import { BehaviorSubject, Observable } from 'rxjs'; import { map } from 'rxjs/operators'; +import { CorePromiseUtils } from '@singletons/promise-utils'; @Component({ selector: 'core-report-builder-report-detail', @@ -78,7 +79,7 @@ export class CoreReportBuilderReportDetailComponent implements OnInit { ); this.logView = CoreTime.once(async (report) => { - await CoreUtils.ignoreErrors(CoreReportBuilder.viewReport(this.reportId)); + await CorePromiseUtils.ignoreErrors(CoreReportBuilder.viewReport(this.reportId)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, @@ -171,9 +172,9 @@ export class CoreReportBuilderReportDetailComponent implements OnInit { * @param ionRefresher ionic refresher. */ async refreshReport(ionRefresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(CoreReportBuilder.invalidateReport()); + await CorePromiseUtils.ignoreErrors(CoreReportBuilder.invalidateReport()); this.updateState({ page: 0, canLoadMoreRows: false }); - await CoreUtils.ignoreErrors(this.getReport()); + await CorePromiseUtils.ignoreErrors(this.getReport()); await ionRefresher?.complete(); } diff --git a/src/core/features/reportbuilder/pages/list/list.ts b/src/core/features/reportbuilder/pages/list/list.ts index 6d951d1a9..d0d91aa74 100644 --- a/src/core/features/reportbuilder/pages/list/list.ts +++ b/src/core/features/reportbuilder/pages/list/list.ts @@ -20,7 +20,7 @@ import { CoreReportBuilder, CoreReportBuilderReport, REPORTS_LIST_LIMIT } from ' import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Translate } from '@singletons'; import { CoreTime } from '@singletons/time'; import { BehaviorSubject } from 'rxjs'; @@ -114,8 +114,8 @@ export class CoreReportBuilderListPage implements AfterViewInit, OnDestroy { * @param ionRefresher ionRefresher. */ async refreshReports(ionRefresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(CoreReportBuilder.invalidateReportsList()); - await CoreUtils.ignoreErrors(this.fetchReports(true)); + await CorePromiseUtils.ignoreErrors(CoreReportBuilder.invalidateReportsList()); + await CorePromiseUtils.ignoreErrors(this.fetchReports(true)); await ionRefresher?.complete(); } diff --git a/src/core/features/search/components/global-search-filters/global-search-filters.component.ts b/src/core/features/search/components/global-search-filters/global-search-filters.component.ts index a62bf998b..d704b9d71 100644 --- a/src/core/features/search/components/global-search-filters/global-search-filters.component.ts +++ b/src/core/features/search/components/global-search-filters/global-search-filters.component.ts @@ -22,7 +22,7 @@ import { } from '@features/search/services/global-search'; import { CoreEvents } from '@singletons/events'; import { ModalController } from '@singletons'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreSharedModule } from '@/core/shared.module'; import { toBoolean } from '@/core/transforms/boolean'; @@ -151,7 +151,7 @@ export class CoreSearchGlobalSearchFiltersComponent implements OnInit { * @param refresher Refresher. */ async refreshFilters(refresher?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ CoreSearchGlobalSearch.invalidateSearchAreas(), CoreCourses.invalidateUserCourses(), ])); diff --git a/src/core/features/search/pages/global-search/global-search.ts b/src/core/features/search/pages/global-search/global-search.ts index 00451e924..20aa928db 100644 --- a/src/core/features/search/pages/global-search/global-search.ts +++ b/src/core/features/search/pages/global-search/global-search.ts @@ -30,6 +30,7 @@ import { import { CoreNavigator } from '@services/navigator'; import { CoreSearchBoxComponent } from '@features/search/components/search-box/search-box'; import { CoreModals } from '@services/modals'; +import { CorePromiseUtils } from '@singletons/promise-utils'; @Component({ selector: 'page-core-search-global-search', @@ -104,7 +105,7 @@ export class CoreSearchGlobalSearchPage implements OnInit, OnDestroy, AfterViewI await CoreDomUtils.showOperationModals('core.searching', true, async () => { await this.resultsSource.reload(); - await CoreUtils.ignoreErrors( + await CorePromiseUtils.ignoreErrors( CoreSearchGlobalSearch.logViewResults(this.resultsSource.getQuery(), this.resultsSource.getFilters()), ); diff --git a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts index 6dd819537..d4e0e3ecd 100644 --- a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts +++ b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts @@ -19,7 +19,7 @@ import { Device, Translate, NgZone } from '@singletons'; import { CoreLang } from '@services/lang'; import { CoreFile } from '@services/file'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { Subscription } from 'rxjs'; import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; import { CoreConfig } from '@services/config'; @@ -208,7 +208,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { this.showDevOptions = this.devOptionsForced || showDevOptionsOnConfig == 1; const publicKey = this.deviceInfo.pushId ? - await CoreUtils.ignoreErrors(CorePushNotifications.getPublicKey()) : + await CorePromiseUtils.ignoreErrors(CorePushNotifications.getPublicKey()) : undefined; this.deviceInfo.encryptedPushSupported = publicKey !== undefined; } diff --git a/src/core/features/settings/pages/general/general.ts b/src/core/features/settings/pages/general/general.ts index 9c74259b1..471d6821e 100644 --- a/src/core/features/settings/pages/general/general.ts +++ b/src/core/features/settings/pages/general/general.ts @@ -22,7 +22,7 @@ import { CoreSettingsHelper, CoreColorScheme, CoreZoomLevel } from '../../servic import { CoreIframeUtils } from '@services/utils/iframe'; import { Translate } from '@singletons'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { AlertButton } from '@ionic/angular'; import { CoreNavigator } from '@services/navigator'; import { CorePlatform } from '@services/platform'; @@ -175,7 +175,7 @@ export class CoreSettingsGeneralPage { protected async applyLanguageAndRestart(): Promise { // Invalidate cache for all sites to get the content in the right language. const sites = await CoreSites.getSitesInstances(); - await CoreUtils.ignoreErrors(Promise.all(sites.map((site) => site.invalidateWsCache()))); + await CorePromiseUtils.ignoreErrors(Promise.all(sites.map((site) => site.invalidateWsCache()))); CoreEvents.trigger(CoreEvents.LANGUAGE_CHANGED, this.selectedLanguage); diff --git a/src/core/features/settings/pages/space-usage/space-usage.ts b/src/core/features/settings/pages/space-usage/space-usage.ts index 48afef177..3b410690d 100644 --- a/src/core/features/settings/pages/space-usage/space-usage.ts +++ b/src/core/features/settings/pages/space-usage/space-usage.ts @@ -20,6 +20,7 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSettingsHelper } from '../../services/settings-helper'; import { CoreAccountsList } from '@features/login/services/login-helper'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Page that displays the space usage settings. @@ -94,7 +95,7 @@ export class CoreSettingsSpaceUsagePage implements OnInit, OnDestroy { // Calculate total usage. let totalSize = 0; - const sites = await CoreUtils.ignoreErrors(CoreSites.getSortedSites(), [] as CoreSiteBasicInfo[]); + const sites = await CorePromiseUtils.ignoreErrors(CoreSites.getSortedSites(), [] as CoreSiteBasicInfo[]); const sitesWithUsage = await Promise.all(sites.map((site) => this.getSiteWithUsage(site))); let siteUrl = ''; diff --git a/src/core/features/settings/services/settings-helper.ts b/src/core/features/settings/services/settings-helper.ts index 0936acaca..558c2dead 100644 --- a/src/core/features/settings/services/settings-helper.ts +++ b/src/core/features/settings/services/settings-helper.ts @@ -20,7 +20,7 @@ import { CoreEvents } from '@singletons/events'; import { CoreFilepool } from '@services/filepool'; import { CoreSite } from '@classes/sites/site'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreConstants } from '@/core/constants'; import { CoreConfig } from '@services/config'; import { CoreFilter } from '@features/filter/services/filter'; @@ -249,7 +249,7 @@ export class CoreSettingsHelperProvider { const syncPromise = Promise.all([ // Invalidate all the site files so they are re-downloaded. - CoreUtils.ignoreErrors(CoreFilepool.invalidateAllFiles(siteId)), + CorePromiseUtils.ignoreErrors(CoreFilepool.invalidateAllFiles(siteId)), // Invalidate and synchronize site data. site.invalidateWsCache(), CoreSites.updateSiteInfo(site.getId()), diff --git a/src/core/features/sharedfiles/services/sharedfiles.ts b/src/core/features/sharedfiles/services/sharedfiles.ts index 8e97b4186..1b20acd82 100644 --- a/src/core/features/sharedfiles/services/sharedfiles.ts +++ b/src/core/features/sharedfiles/services/sharedfiles.ts @@ -19,7 +19,7 @@ import { Md5 } from 'ts-md5/dist/md5'; import { CoreLogger } from '@singletons/logger'; import { CoreAppDB } from '@services/app-db'; import { CoreFile } from '@services/file'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreSites } from '@services/sites'; import { CoreEvents } from '@singletons/events'; @@ -74,7 +74,7 @@ export class CoreSharedFilesProvider { async checkIOSNewFiles(): Promise { this.logger.debug('Search for new files on iOS'); - const entries = await CoreUtils.ignoreErrors(CoreFile.getDirectoryContents('Inbox')); + const entries = await CorePromiseUtils.ignoreErrors(CoreFile.getDirectoryContents('Inbox')); if (!entries || !entries.length) { return; @@ -127,7 +127,7 @@ export class CoreSharedFilesProvider { async deleteInboxFile(entry: FileEntry): Promise { this.logger.debug('Delete inbox file: ' + entry.name); - await CoreUtils.ignoreErrors(CoreFile.removeFileByFileEntry(entry)); + await CorePromiseUtils.ignoreErrors(CoreFile.removeFileByFileEntry(entry)); try { await this.unmarkAsTreated(this.getFileId(entry)); diff --git a/src/core/features/sitehome/pages/index/index.ts b/src/core/features/sitehome/pages/index/index.ts index 5ec376299..07672dbe9 100644 --- a/src/core/features/sitehome/pages/index/index.ts +++ b/src/core/features/sitehome/pages/index/index.ts @@ -27,7 +27,7 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; import { CoreBlockHelper } from '@features/block/services/block-helper'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { ContextLevel } from '@/core/constants'; @@ -67,7 +67,7 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { }, CoreSites.getCurrentSiteId()); this.logView = CoreTime.once(async () => { - await CoreUtils.ignoreErrors(CoreCourse.logView(this.siteHomeId)); + await CorePromiseUtils.ignoreErrors(CoreCourse.logView(this.siteHomeId)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM, diff --git a/src/core/features/siteplugins/classes/handlers/module-handler.ts b/src/core/features/siteplugins/classes/handlers/module-handler.ts index a7fc626d4..0eba196bb 100644 --- a/src/core/features/siteplugins/classes/handlers/module-handler.ts +++ b/src/core/features/siteplugins/classes/handlers/module-handler.ts @@ -28,7 +28,7 @@ import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; import { CoreLogger } from '@singletons/logger'; import { CoreSitePluginsBaseHandler } from './base-handler'; import { CoreEvents } from '@singletons/events'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CORE_SITE_PLUGINS_UPDATE_COURSE_CONTENT } from '@features/siteplugins/constants'; /** @@ -184,7 +184,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp }; if (refresh) { - await CoreUtils.ignoreErrors(CoreSitePlugins.invalidateContent(this.plugin.component, method, args)); + await CorePromiseUtils.ignoreErrors(CoreSitePlugins.invalidateContent(this.plugin.component, method, args)); } try { diff --git a/src/core/features/siteplugins/classes/handlers/module-prefetch-handler.ts b/src/core/features/siteplugins/classes/handlers/module-prefetch-handler.ts index 91dde49ee..cf422c31e 100644 --- a/src/core/features/siteplugins/classes/handlers/module-prefetch-handler.ts +++ b/src/core/features/siteplugins/classes/handlers/module-prefetch-handler.ts @@ -18,7 +18,7 @@ import { CoreSitePlugins, CoreSitePluginsCourseModuleHandlerData } from '@featur import { CoreFilepool } from '@services/filepool'; import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Handler to prefetch a module site plugin. @@ -200,7 +200,7 @@ export class CoreSitePluginsModulePrefetchHandler extends CoreCourseActivityPref } } - return CoreUtils.allPromises(promises); + return CorePromiseUtils.allPromises(promises); } /** diff --git a/src/core/features/siteplugins/services/siteplugins-init.ts b/src/core/features/siteplugins/services/siteplugins-init.ts index 5ae83d883..dab2ba531 100644 --- a/src/core/features/siteplugins/services/siteplugins-init.ts +++ b/src/core/features/siteplugins/services/siteplugins-init.ts @@ -37,7 +37,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreLang } from '@services/lang'; import { CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreWS } from '@services/ws'; import { CoreEvents } from '@singletons/events'; import { CoreLogger } from '@singletons/logger'; @@ -119,7 +119,7 @@ export class CoreSitePluginsInitService { // Fetch the plugins on login. CoreEvents.on(CoreEvents.LOGIN, async (data) => { try { - const plugins = await CoreUtils.ignoreErrors(CoreSitePlugins.getPlugins(data.siteId)); + const plugins = await CorePromiseUtils.ignoreErrors(CoreSitePlugins.getPlugins(data.siteId)); // Plugins fetched, check that site hasn't changed. if (data.siteId !== CoreSites.getCurrentSiteId() || !plugins?.length) { @@ -179,14 +179,14 @@ export class CoreSitePluginsInitService { const componentId = uniqueName + '#main'; // Remove the CSS files for this handler that aren't used anymore. Don't block the call for this. - const files = await CoreUtils.ignoreErrors( + const files = await CorePromiseUtils.ignoreErrors( CoreFilepool.getFilesByComponent(site.getId(), CORE_SITE_PLUGINS_COMPONENT, componentId), ); files?.forEach((file) => { if (file.url !== url) { // It's not the current file, delete it. - CoreUtils.ignoreErrors(CoreFilepool.removeFileByUrl(site.getId(), file.url)); + CorePromiseUtils.ignoreErrors(CoreFilepool.removeFileByUrl(site.getId(), file.url)); } }); @@ -363,7 +363,7 @@ export class CoreSitePluginsInitService { if (plugin.parsedHandlers) { // Register all the handlers. const parsedHandlers = plugin.parsedHandlers; - await CoreUtils.allPromises(Object.keys(parsedHandlers).map(async (name) => { + await CorePromiseUtils.allPromises(Object.keys(parsedHandlers).map(async (name) => { await this.registerHandler(plugin, name, parsedHandlers[name]); })); } @@ -377,7 +377,7 @@ export class CoreSitePluginsInitService { protected async loadSitePlugins(plugins: CoreSitePluginsPlugin[]): Promise { this.courseRestrictHandlers = {}; - await CoreUtils.allPromises(plugins.map(async (plugin) => { + await CorePromiseUtils.allPromises(plugins.map(async (plugin) => { const pluginPromise = this.loadSitePlugin(plugin); CoreSitePlugins.registerSitePluginPromise(plugin.component, pluginPromise); @@ -429,7 +429,7 @@ export class CoreSitePluginsInitService { } // Styles have been loaded, now treat the CSS. - CoreUtils.ignoreErrors( + CorePromiseUtils.ignoreErrors( CoreFilepool.treatCSSCode(siteId, fileUrl, cssCode, CORE_SITE_PLUGINS_COMPONENT, uniqueName, version), ); } diff --git a/src/core/features/styles/services/styles.ts b/src/core/features/styles/services/styles.ts index a62ee264e..d83c4774f 100644 --- a/src/core/features/styles/services/styles.ts +++ b/src/core/features/styles/services/styles.ts @@ -17,7 +17,7 @@ import { CoreError } from '@classes/errors/error'; import { CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site'; import { CoreApp } from '@services/app'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { Md5 } from 'ts-md5'; @@ -373,7 +373,7 @@ export class CoreStylesService { this.disableStyleElementByName(siteIdentifier, sourceName, disabled); } - await CoreUtils.allPromises(this.styleHandlers.map(async (handler) => { + await CorePromiseUtils.allPromises(this.styleHandlers.map(async (handler) => { await this.setStyle(siteIdentifier, handler, disabled); })); @@ -392,7 +392,7 @@ export class CoreStylesService { // Create the style and add it to the header. this.createStyleElements(CoreStylesService.TMP_SITE_ID, true); - await CoreUtils.allPromises(this.styleHandlers.map(async (handler) => { + await CorePromiseUtils.allPromises(this.styleHandlers.map(async (handler) => { await this.setStyle(CoreStylesService.TMP_SITE_ID, handler, false, config); })); @@ -405,7 +405,7 @@ export class CoreStylesService { * @returns Promise resolved when loaded. */ protected async preloadCurrentSite(): Promise { - const siteId = await CoreUtils.ignoreErrors(CoreSites.getStoredCurrentSiteId()); + const siteId = await CorePromiseUtils.ignoreErrors(CoreSites.getStoredCurrentSiteId()); if (!siteId) { // No current site stored. @@ -423,7 +423,7 @@ export class CoreStylesService { protected async preloadSites(): Promise { const ids = await CoreSites.getSitesIds(); - await CoreUtils.allPromises(ids.map((siteId) => this.addSite(siteId))); + await CorePromiseUtils.allPromises(ids.map((siteId) => this.addSite(siteId))); } /** diff --git a/src/core/features/tag/pages/search/search.ts b/src/core/features/tag/pages/search/search.ts index e7ef9788f..878ca174b 100644 --- a/src/core/features/tag/pages/search/search.ts +++ b/src/core/features/tag/pages/search/search.ts @@ -15,7 +15,7 @@ import { Component, OnInit } from '@angular/core'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreUrl } from '@singletons/url'; import { CoreTagCloud, CoreTagCollection, CoreTagCloudTag, CoreTag } from '@features/tag/services/tag'; import { Translate } from '@singletons'; @@ -129,7 +129,7 @@ export class CoreTagSearchPage implements OnInit { * @param refresher Refresher event. */ refreshData(refresher?: HTMLIonRefresherElement): void { - CoreUtils.allPromises([ + CorePromiseUtils.allPromises([ CoreTag.invalidateTagCollections(), CoreTag.invalidateTagCloud(this.collectionId, undefined, undefined, this.query), ]).finally(() => this.fetchData().finally(() => { diff --git a/src/core/features/user/classes/support/guest-support-config.ts b/src/core/features/user/classes/support/guest-support-config.ts index f60277e0d..ff43c6cc1 100644 --- a/src/core/features/user/classes/support/guest-support-config.ts +++ b/src/core/features/user/classes/support/guest-support-config.ts @@ -19,7 +19,7 @@ import { } from '@classes/sites/unauthenticated-site'; import { CoreUserNullSupportConfig } from '@features/user/classes/support/null-support-config'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreUserSupportConfig } from './support-config'; import { CoreSitesFactory } from '@services/sites-factory'; @@ -35,7 +35,7 @@ export class CoreUserGuestSupportConfig extends CoreUserSupportConfig { * @returns Support config. */ static async forSite(siteUrl: string): Promise { - const siteConfig = await CoreUtils.ignoreErrors(CoreSites.getPublicSiteConfigByUrl(siteUrl)); + const siteConfig = await CorePromiseUtils.ignoreErrors(CoreSites.getPublicSiteConfigByUrl(siteUrl)); if (!siteConfig) { return new CoreUserNullSupportConfig(); diff --git a/src/core/features/user/pages/about/about.ts b/src/core/features/user/pages/about/about.ts index 465e594f0..a0b3b092d 100644 --- a/src/core/features/user/pages/about/about.ts +++ b/src/core/features/user/pages/about/about.ts @@ -16,7 +16,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreUser, @@ -203,7 +203,7 @@ export class CoreUserAboutPage implements OnInit, OnDestroy { * @returns Promise resolved when done. */ async refreshUser(event?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(CoreUser.invalidateUserCache(this.userId)); + await CorePromiseUtils.ignoreErrors(CoreUser.invalidateUserCache(this.userId)); await this.fetchUser(); diff --git a/src/core/features/user/pages/participants/participants.page.ts b/src/core/features/user/pages/participants/participants.page.ts index c8d93275e..0ec5c1b3a 100644 --- a/src/core/features/user/pages/participants/participants.page.ts +++ b/src/core/features/user/pages/participants/participants.page.ts @@ -19,7 +19,7 @@ import { CoreNavigator } from '@services/navigator'; import { CoreListItemsManager } from '@classes/items-management/list-items-manager'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreUser, CoreUserParticipant, CoreUserData } from '@features/user/services/user'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreUserParticipantsSource } from '@features/user/classes/participants-source'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; @@ -136,8 +136,8 @@ export class CoreUserParticipantsPage implements OnInit, AfterViewInit, OnDestro * @param refresher Refresher. */ async refreshParticipants(refresher: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(CoreUser.invalidateParticipantsList(this.courseId)); - await CoreUtils.ignoreErrors(this.fetchParticipants(true)); + await CorePromiseUtils.ignoreErrors(CoreUser.invalidateParticipantsList(this.courseId)); + await CorePromiseUtils.ignoreErrors(this.fetchParticipants(true)); refresher?.complete(); } @@ -196,7 +196,7 @@ class CoreUserParticipantsManager extends CoreListItemsManager { - await CoreUtils.ignoreErrors(CoreUser.logParticipantsView(this.getSource().COURSE_ID)); + await CorePromiseUtils.ignoreErrors(CoreUser.logParticipantsView(this.getSource().COURSE_ID)); CoreAnalytics.logEvent({ type: CoreAnalyticsEventType.VIEW_ITEM_LIST, diff --git a/src/core/features/user/pages/profile/profile.ts b/src/core/features/user/pages/profile/profile.ts index 00b3972a0..5d623b98d 100644 --- a/src/core/features/user/pages/profile/profile.ts +++ b/src/core/features/user/pages/profile/profile.ts @@ -28,7 +28,7 @@ import { CoreUserProfileHandlerType, CoreUserProfileHandlerData, } from '@features/user/services/user-delegate'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreNavigator } from '@services/navigator'; import { CoreCourses } from '@features/courses/services/courses'; import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager'; @@ -186,7 +186,7 @@ export class CoreUserProfilePage implements OnInit, OnDestroy { * @returns Promise resolved when done. */ async refreshUser(event?: HTMLIonRefresherElement): Promise { - await CoreUtils.ignoreErrors(Promise.all([ + await CorePromiseUtils.ignoreErrors(Promise.all([ CoreUser.invalidateUserCache(this.userId), CoreCourses.invalidateUserNavigationOptions(), CoreCourses.invalidateUserAdministrationOptions(), diff --git a/src/core/features/user/services/user-delegate.ts b/src/core/features/user/services/user-delegate.ts index 60bd7f31c..9e0e9ac25 100644 --- a/src/core/features/user/services/user-delegate.ts +++ b/src/core/features/user/services/user-delegate.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { Subject, BehaviorSubject } from 'rxjs'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreEvents } from '@singletons/events'; import { CoreUserProfile, USER_PROFILE_REFRESHED } from './user'; import { makeSingleton } from '@singletons'; @@ -334,7 +334,7 @@ export class CoreUserDelegateService extends CoreDelegate { + await CorePromiseUtils.allPromises(Object.keys(this.enabledHandlers).map(async (name) => { // Checks if the handler is enabled for the user. const handler = this.handlers[name]; diff --git a/src/core/features/user/services/user-offline.ts b/src/core/features/user/services/user-offline.ts index 09d060685..e308b8ccf 100644 --- a/src/core/features/user/services/user-offline.ts +++ b/src/core/features/user/services/user-offline.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { PREFERENCES_TABLE_NAME, CoreUserPreferenceDBRecord } from './database/user'; @@ -73,7 +73,7 @@ export class CoreUserOfflineProvider { if (onlineValue === undefined) { // Keep online value already stored (if any). - const entry = await CoreUtils.ignoreErrors( + const entry = await CorePromiseUtils.ignoreErrors( site.getDb().getRecord(PREFERENCES_TABLE_NAME, { name }), null, ); diff --git a/src/core/features/user/services/user-sync.ts b/src/core/features/user/services/user-sync.ts index 968aa1e42..4b2a76b3a 100644 --- a/src/core/features/user/services/user-sync.ts +++ b/src/core/features/user/services/user-sync.ts @@ -21,6 +21,7 @@ import { CoreSyncBaseProvider } from '@classes/base-sync'; import { makeSingleton } from '@singletons'; import { CoreUserOffline } from './user-offline'; import { CoreUser } from './user'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Service to sync user preferences. @@ -77,7 +78,7 @@ export class CoreUserSyncProvider extends CoreSyncBaseProvider { const preferences = await CoreUserOffline.getChangedPreferences(siteId); - await CoreUtils.allPromises(preferences.map(async (preference) => { + await CorePromiseUtils.allPromises(preferences.map(async (preference) => { const onlineValue = await CoreUser.getUserPreferenceOnline(preference.name, siteId); if (onlineValue !== null && preference.onlinevalue != onlineValue) { diff --git a/src/core/features/user/services/user.ts b/src/core/features/user/services/user.ts index 788d5c169..efa6c4eee 100644 --- a/src/core/features/user/services/user.ts +++ b/src/core/features/user/services/user.ts @@ -29,6 +29,7 @@ import { USERS_TABLE_NAME, CoreUserDBRecord } from './database/user'; import { CoreUrl } from '@singletons/url'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { CoreCacheUpdateFrequency, CoreConstants } from '@/core/constants'; +import { CorePromiseUtils } from '@singletons/promise-utils'; const ROOT_CACHE_KEY = 'mmUser:'; @@ -291,7 +292,7 @@ export class CoreUserProvider { * @returns Starting week day. */ async getStartingWeekDay(): Promise { - const preference = await CoreUtils.ignoreErrors(this.getUserPreference('calendar_startwday')); + const preference = await CorePromiseUtils.ignoreErrors(this.getUserPreference('calendar_startwday')); if (preference && !isNaN(Number(preference))) { return Number(preference); @@ -415,7 +416,7 @@ export class CoreUserProvider { async getUserPreference(name: string, siteId?: string): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); - const preference = await CoreUtils.ignoreErrors(CoreUserOffline.getPreference(name, siteId)); + const preference = await CorePromiseUtils.ignoreErrors(CoreUserOffline.getPreference(name, siteId)); if (preference && !CoreNetwork.isOnline()) { // Offline, return stored value. @@ -547,7 +548,7 @@ export class CoreUserProvider { } // Retrieving one participant will fail if browsing users is disabled by capabilities. - return CoreUtils.promiseWorks(this.getParticipants(courseId, 0, 1, siteId)); + return CorePromiseUtils.promiseWorks(this.getParticipants(courseId, 0, 1, siteId)); } /** @@ -791,7 +792,7 @@ export class CoreUserProvider { // Update preference and invalidate data. await Promise.all([ CoreUserOffline.setPreference(name, value, value), - CoreUtils.ignoreErrors(this.invalidateUserPreference(name)), + CorePromiseUtils.ignoreErrors(this.invalidateUserPreference(name)), ]); } catch (error) { // Preference not saved online. Update the offline one. diff --git a/src/core/features/xapi/services/offline.ts b/src/core/features/xapi/services/offline.ts index 732fdffd6..cf109d70f 100644 --- a/src/core/features/xapi/services/offline.ts +++ b/src/core/features/xapi/services/offline.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreSites } from '@services/sites'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { makeSingleton } from '@singletons'; import { CoreXAPIStateDBRecord, CoreXAPIStatementDBRecord, STATEMENTS_TABLE_NAME, STATES_TABLE_NAME } from './database/xapi'; import { CoreXAPIStateOptions } from './xapi'; @@ -234,7 +234,7 @@ export class CoreXAPIOfflineProvider { ): Promise { const db = await CoreSites.getSiteDb(options?.siteId); - const storedState = await CoreUtils.ignoreErrors(this.getState(component, itemId, stateId, options)); + const storedState = await CorePromiseUtils.ignoreErrors(this.getState(component, itemId, stateId, options)); if (storedState) { const newData: Partial = { diff --git a/src/core/features/xapi/services/xapi.ts b/src/core/features/xapi/services/xapi.ts index 48e617c32..553b5b803 100644 --- a/src/core/features/xapi/services/xapi.ts +++ b/src/core/features/xapi/services/xapi.ts @@ -25,6 +25,7 @@ import { CoreXAPIIRI } from '../classes/iri'; import { CoreError } from '@classes/errors/error'; import { CoreLogger } from '@singletons/logger'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; +import { CorePromiseUtils } from '@singletons/promise-utils'; export const XAPI_STATE_DELETED = 'STATE_DELETED'; @@ -110,7 +111,7 @@ export class CoreXAPIProvider { if (!isNaN(itemId)) { // Delete offline state if it exists. - await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(component, { + await CorePromiseUtils.ignoreErrors(CoreXAPIOffline.deleteStates(component, { itemId, stateId, registration: options.registration, diff --git a/src/core/guards/can-leave.ts b/src/core/guards/can-leave.ts index 527e70270..62728850e 100644 --- a/src/core/guards/can-leave.ts +++ b/src/core/guards/can-leave.ts @@ -13,7 +13,7 @@ // limitations under the License. import { CanDeactivateFn } from '@angular/router'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Check if a component implements the canLeave interface. @@ -34,7 +34,7 @@ export const canLeaveGuard: CanDeactivateFn = async (component: unknown return true; } - return CoreUtils.ignoreErrors(component.canLeave(), false); + return CorePromiseUtils.ignoreErrors(component.canLeave(), false); }; export interface CanLeave { diff --git a/src/core/services/cron.ts b/src/core/services/cron.ts index b8f393ab6..1940b1950 100644 --- a/src/core/services/cron.ts +++ b/src/core/services/cron.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { CoreAppDB } from '@services/app-db'; import { CoreNetwork } from '@services/network'; import { CoreConfig } from '@services/config'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreConstants } from '@/core/constants'; import { CoreError } from '@classes/errors/error'; @@ -109,13 +109,13 @@ export class CoreCronDelegateService { } // Add the execution to the queue. - this.queuePromise = CoreUtils.ignoreErrors(this.queuePromise).then(async () => { + this.queuePromise = CorePromiseUtils.ignoreErrors(this.queuePromise).then(async () => { try { await this.executeHandler(name, force, siteId); this.logger.debug(`Cron job '${name}' was successfully executed.`); - await CoreUtils.ignoreErrors(this.setHandlerLastExecutionTime(name, Date.now())); + await CorePromiseUtils.ignoreErrors(this.setHandlerLastExecutionTime(name, Date.now())); this.scheduleNextExecution(name); @@ -147,7 +147,7 @@ export class CoreCronDelegateService { // Wrap the call in Promise.resolve to make sure it's a promise. const promise = Promise.resolve(this.handlers[name].execute?.(siteId, force)); - await CoreUtils.timeoutPromise(promise, CoreCronDelegateService.MAX_TIME_PROCESS); + await CorePromiseUtils.timeoutPromise(promise, CoreCronDelegateService.MAX_TIME_PROCESS); } catch (error) { if (error.timeout) { // The handler took too long. Resolve because we don't want to retry soon. @@ -177,7 +177,7 @@ export class CoreCronDelegateService { } } - await CoreUtils.allPromises(promises); + await CorePromiseUtils.allPromises(promises); } /** @@ -373,7 +373,7 @@ export class CoreCronDelegateService { this.handlers[name].timeout = window.setTimeout(() => { delete this.handlers[name].timeout; - CoreUtils.ignoreErrors(this.checkAndExecuteHandler(name)); + CorePromiseUtils.ignoreErrors(this.checkAndExecuteHandler(name)); }, timeToNextExecution); } diff --git a/src/core/services/file.ts b/src/core/services/file.ts index 07c11679e..9cc8bc66a 100644 --- a/src/core/services/file.ts +++ b/src/core/services/file.ts @@ -29,6 +29,7 @@ import { CorePlatform } from '@services/platform'; import { CorePath } from '@singletons/path'; import { Zip } from '@features/native/plugins'; import { CoreUrl } from '@singletons/url'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Progress event used when writing a file data into a file. @@ -947,7 +948,7 @@ export class CoreFileProvider { if (destFolder && recreateDir) { // Make sure the dest dir doesn't exist already. - await CoreUtils.ignoreErrors(this.removeDir(destFolder)); + await CorePromiseUtils.ignoreErrors(this.removeDir(destFolder)); // Now create the dir, otherwise if any of the ancestor dirs doesn't exist the unzip would fail. await this.createDir(destFolder); @@ -1138,7 +1139,7 @@ export class CoreFileProvider { */ async clearTmpFolder(): Promise { // Ignore errors because the folder might not exist. - await CoreUtils.ignoreErrors(this.removeDir(CoreFileProvider.TMPFOLDER)); + await CorePromiseUtils.ignoreErrors(this.removeDir(CoreFileProvider.TMPFOLDER)); } /** @@ -1162,7 +1163,7 @@ export class CoreFileProvider { if (file.isDirectory) { if (!existingSiteNames.includes(file.name)) { // Site does not exist... delete it. - await CoreUtils.ignoreErrors(this.removeDir(this.getSiteFolder(file.name))); + await CorePromiseUtils.ignoreErrors(this.removeDir(this.getSiteFolder(file.name))); } } }); diff --git a/src/core/services/filepool.ts b/src/core/services/filepool.ts index 0d88ba9f0..5b040f843 100644 --- a/src/core/services/filepool.ts +++ b/src/core/services/filepool.ts @@ -59,6 +59,7 @@ import { CorePath } from '@singletons/path'; import { CorePromisedValue } from '@classes/promised-value'; import { CoreAnalytics, CoreAnalyticsEventType } from './analytics'; import { convertTextToHTMLElement } from '../utils/create-html-element'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /* * Factory for handling downloading files and retrieve downloaded files. @@ -573,7 +574,7 @@ export class CoreFilepoolProvider { if (timemodified > 0 && !entry.timemodified) { // Entry is not outdated but it doesn't have timemodified. Update it. - await CoreUtils.ignoreErrors(this.filesTables[siteId].update({ timemodified }, { fileId: entry.fileId })); + await CorePromiseUtils.ignoreErrors(this.filesTables[siteId].update({ timemodified }, { fileId: entry.fileId })); entry.timemodified = timemodified; } @@ -883,7 +884,7 @@ export class CoreFilepoolProvider { } }); - return CoreUtils.allPromises(promises); + return CorePromiseUtils.allPromises(promises); } /** @@ -1088,7 +1089,7 @@ export class CoreFilepoolProvider { const finishSuccessfulDownload = (url: string): string => { if (component !== undefined) { - CoreUtils.ignoreErrors(this.addFileLink(siteId, fileId, component, componentId)); + CorePromiseUtils.ignoreErrors(this.addFileLink(siteId, fileId, component, componentId)); } if (!alreadyDownloaded) { @@ -1628,7 +1629,7 @@ export class CoreFilepoolProvider { ): Promise { const addToQueue = (fileUrl: string): void => { // Add the file to queue if needed and ignore errors. - CoreUtils.ignoreErrors(this.addToQueueIfNeeded( + CorePromiseUtils.ignoreErrors(this.addToQueueIfNeeded( siteId, fileUrl, component, @@ -2266,7 +2267,7 @@ export class CoreFilepoolProvider { await Promise.all([ this.filesTables[siteId].update({ fileId: newFileId }, { fileId: buggedFileId }), - CoreUtils.ignoreErrors(this.linksTables[siteId].update({ fileId: newFileId }, { fileId: buggedFileId })), + CorePromiseUtils.ignoreErrors(this.linksTables[siteId].update({ fileId: newFileId }, { fileId: buggedFileId })), ]); fileEntry.fileId = newFileId; @@ -2714,11 +2715,11 @@ export class CoreFilepoolProvider { await this.downloadForPoolByUrl(siteId, fileUrl, options, filePath, onProgress, entry); // Success, we add links and remove from queue. - CoreUtils.ignoreErrors(this.addFileLinks(siteId, fileId, links)); + CorePromiseUtils.ignoreErrors(this.addFileLinks(siteId, fileId, links)); // Wait for the item to be removed from queue before resolving the promise. // If the item could not be removed from queue we still resolve the promise. - await CoreUtils.ignoreErrors(this.removeFromQueue(siteId, fileId)); + await CorePromiseUtils.ignoreErrors(this.removeFromQueue(siteId, fileId)); this.treatQueueDeferred(siteId, fileId, true); this.notifyFileDownloaded(siteId, fileId, links); @@ -2761,7 +2762,7 @@ export class CoreFilepoolProvider { if (dropFromQueue) { this.logger.debug('Item dropped from queue due to error: ' + fileUrl, errorObject); - await CoreUtils.ignoreErrors(this.removeFromQueue(siteId, fileId)); + await CorePromiseUtils.ignoreErrors(this.removeFromQueue(siteId, fileId)); this.treatQueueDeferred(siteId, fileId, false, errorMessage); this.notifyFileDownloadError(siteId, fileId, links); @@ -2840,7 +2841,7 @@ export class CoreFilepoolProvider { this.notifyFileDeleted(siteId, fileId, links); if (fileUrl) { - await CoreUtils.ignoreErrors(CorePluginFileDelegate.fileDeleted(fileUrl, path, siteId)); + await CorePromiseUtils.ignoreErrors(CorePluginFileDelegate.fileDeleted(fileUrl, path, siteId)); } } diff --git a/src/core/services/geolocation.ts b/src/core/services/geolocation.ts index 29f2600d0..5d861be5c 100644 --- a/src/core/services/geolocation.ts +++ b/src/core/services/geolocation.ts @@ -18,7 +18,7 @@ import { Coordinates } from '@awesome-cordova-plugins/geolocation'; import { CoreApp } from '@services/app'; import { CoreAnyError, CoreError } from '@classes/errors/error'; import { Geolocation, makeSingleton } from '@singletons'; -import { CoreUtils } from './utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CorePlatform } from './platform'; import { CoreSilentError } from '@classes/errors/silenterror'; import { CoreSubscriptions } from '@singletons/subscriptions'; @@ -169,7 +169,7 @@ export class CoreGeolocationProvider { const diagnostic = CoreNative.plugin('diagnostic'); if (diagnostic) { - return CoreUtils.promiseWorks(diagnostic.getLocationAuthorizationStatus()); + return CorePromiseUtils.promiseWorks(diagnostic.getLocationAuthorizationStatus()); } return false; diff --git a/src/core/services/navigator.ts b/src/core/services/navigator.ts index caf6e3642..f953b1785 100644 --- a/src/core/services/navigator.ts +++ b/src/core/services/navigator.ts @@ -33,6 +33,7 @@ import { filter } from 'rxjs/operators'; import { CorePromisedValue } from '@classes/promised-value'; import { BehaviorSubject } from 'rxjs'; import { CoreLoadings } from './loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Redirect payload. @@ -549,7 +550,7 @@ export class CoreNavigatorService { const currentMainMenuTab = this.getCurrentMainMenuTab(); const isMainMenuTab = pathRoot === currentMainMenuTab || (!currentMainMenuTab && path === this.getLandingTabPage()) || - await CoreUtils.ignoreErrors(CoreMainMenu.isMainMenuTab(pathRoot), false); + await CorePromiseUtils.ignoreErrors(CoreMainMenu.isMainMenuTab(pathRoot), false); if (!options.preferCurrentTab && isMainMenuTab) { return this.navigate(`/main/${path}`, options); diff --git a/src/core/services/sites.ts b/src/core/services/sites.ts index 2914cebc1..5de4d1b70 100644 --- a/src/core/services/sites.ts +++ b/src/core/services/sites.ts @@ -70,6 +70,7 @@ import { CoreErrorHelper } from './error-helper'; import { CoreQueueRunner } from '@classes/queue-runner'; import { CoreAppDB } from './app-db'; import { CoreRedirects } from '@singletons/redirects'; +import { CorePromiseUtils } from '@singletons/promise-utils'; export const CORE_SITE_SCHEMAS = new InjectionToken('CORE_SITE_SCHEMAS'); export const CORE_SITE_CURRENT_SITE_ID_CONFIG = 'current_site_id'; @@ -615,7 +616,7 @@ export class CoreSitesProvider { const siteId = this.createSiteID(info.siteurl, info.username); // Check if the site already exists. - const storedSite = await CoreUtils.ignoreErrors(this.getSite(siteId)); + const storedSite = await CorePromiseUtils.ignoreErrors(this.getSite(siteId)); let site: CoreSite; if (storedSite) { @@ -1130,12 +1131,12 @@ export class CoreSitesProvider { delete this.sites[siteId]; // DB remove shouldn't fail, but we'll go ahead even if it does. - await CoreUtils.ignoreErrors(this.sitesTable.deleteByPrimaryKey({ id: siteId })); + await CorePromiseUtils.ignoreErrors(this.sitesTable.deleteByPrimaryKey({ id: siteId })); // Site deleted from sites list, now delete the folder. await site.deleteFolder(); - await CoreUtils.ignoreErrors(CoreNative.plugin('secureStorage')?.deleteCollection(siteId)); + await CorePromiseUtils.ignoreErrors(CoreNative.plugin('secureStorage')?.deleteCollection(siteId)); CoreEvents.trigger(CoreEvents.SITE_DELETED, site, siteId); } @@ -1475,7 +1476,7 @@ export class CoreSitesProvider { promises.push(this.removeStoredCurrentSite()); - await CoreUtils.ignoreErrors(Promise.all(promises)); + await CorePromiseUtils.ignoreErrors(Promise.all(promises)); if (options.removeAccount) { await CoreSites.deleteSite(siteId); @@ -1534,7 +1535,7 @@ export class CoreSitesProvider { * Handle auto logout by checking autologout type and time if its required. */ async handleAutoLogout(): Promise { - await CoreUtils.ignoreErrors(( async () => { + await CorePromiseUtils.ignoreErrors(( async () => { const siteId = await this.getStoredCurrentSiteId(); const site = await this.getSite(siteId); const autoLogoutType = Number(site.getStoredConfig('tool_mobile_autologout')); diff --git a/src/core/services/update-manager.ts b/src/core/services/update-manager.ts index e14472526..bfa186140 100644 --- a/src/core/services/update-manager.ts +++ b/src/core/services/update-manager.ts @@ -21,7 +21,7 @@ import { makeSingleton } from '@singletons'; import { CoreH5P } from '@features/h5p/services/h5p'; import { CoreLoginHelper } from '@features/login/services/login-helper'; import { CoreSites } from './sites'; -import { CoreUtils } from './utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; import { CoreRedirects } from '@singletons/redirects'; import { CoreZoomLevel } from '@features/settings/services/settings-helper'; import { CorePromisedValue } from '@classes/promised-value'; @@ -69,7 +69,7 @@ export class CoreUpdateManagerProvider { const [versionApplied, previousAppFolder, currentAppFolder] = await Promise.all([ CoreConfig.get(CoreUpdateManagerProvider.VERSION_APPLIED, 0), CoreConfig.get(CoreUpdateManagerProvider.PREVIOUS_APP_FOLDER, ''), - CorePlatform.isMobile() ? CoreUtils.ignoreErrors(CoreFile.getBasePath(), '') : '', + CorePlatform.isMobile() ? CorePromiseUtils.ignoreErrors(CoreFile.getBasePath(), '') : '', ]); if (versionCode > versionApplied) { @@ -119,12 +119,12 @@ export class CoreUpdateManagerProvider { return; } - const currentSiteId = await CoreUtils.ignoreErrors(CoreSites.getStoredCurrentSiteId()); + const currentSiteId = await CorePromiseUtils.ignoreErrors(CoreSites.getStoredCurrentSiteId()); if (!currentSiteId) { return; } - const site = await CoreUtils.ignoreErrors(CoreSites.getSite(currentSiteId)); + const site = await CorePromiseUtils.ignoreErrors(CoreSites.getSite(currentSiteId)); if (!site) { return; } diff --git a/src/core/services/utils/iframe.ts b/src/core/services/utils/iframe.ts index 3c8f3d841..082bbec19 100644 --- a/src/core/services/utils/iframe.ts +++ b/src/core/services/utils/iframe.ts @@ -37,6 +37,7 @@ import { CoreFilepool } from '@services/filepool'; import { CoreSite } from '@classes/sites/site'; import { CoreNative } from '@features/native/services/native'; import { CoreLoadings } from '@services/loadings'; +import { CorePromiseUtils } from '@singletons/promise-utils'; type CoreFrameElement = FrameElement & { window?: Window; @@ -681,7 +682,7 @@ export class CoreIframeUtilsProvider { if (!CoreNetwork.isOnline()) { // User is offline, try to open a local copy of the file if present. const localUrl = options.site ? - await CoreUtils.ignoreErrors(CoreFilepool.getInternalUrlByUrl(options.site.getId(), url)) : + await CorePromiseUtils.ignoreErrors(CoreFilepool.getInternalUrlByUrl(options.site.getId(), url)) : undefined; if (localUrl) { @@ -693,7 +694,7 @@ export class CoreIframeUtilsProvider { return; } - const mimetype = await CoreUtils.ignoreErrors(CoreUtils.getMimeTypeFromUrl(url)); + const mimetype = await CorePromiseUtils.ignoreErrors(CoreUtils.getMimeTypeFromUrl(url)); if (!mimetype || mimetype === 'text/html' || mimetype === 'text/plain') { // It's probably a web page, open in browser. diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index 80bd52df8..ddf5aa58f 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -37,6 +37,7 @@ import { CoreWait, CoreWaitOptions } from '@singletons/wait'; import { CoreQRScan } from '@services/qrscan'; import { CoreErrorHelper } from '@services/error-helper'; import { CoreInAppBrowser, CoreInAppBrowserOpenOptions } from '@singletons/iab'; +import { CorePromiseUtils, OrderedPromiseData } from '@singletons/promise-utils'; export type TreeNode = T & { children: TreeNode[] }; @@ -77,37 +78,20 @@ export class CoreUtilsProvider { * Similar to Promise.all, but if a promise fails this function's promise won't be rejected until ALL promises have finished. * * @param promises Promises. - * @returns Promise resolved if all promises are resolved and rejected if at least 1 promise fails. + * @deprecated since 5.0. Use CorePromiseUtils.allPromises instead. */ - async allPromises(promises: unknown[]): Promise { - if (!promises || !promises.length) { - return; - } - - const getPromiseError = async (promise: unknown): Promise => { - try { - await promise; - } catch (error) { - return error; - } - }; - - const errors = await Promise.all(promises.map(getPromiseError)); - const error = errors.find(error => !!error); - - if (error) { - throw error; - } + async allPromises(promises: Promise[]): Promise { + await CorePromiseUtils.allPromises(promises); } /** * Combination of allPromises and ignoreErrors functions. * * @param promises Promises. - * @returns Promise resolved if all promises are resolved and rejected if at least 1 promise fails. + * @deprecated since 5.0. Use CorePromiseUtils.allPromisesIgnoringErrors instead. */ async allPromisesIgnoringErrors(promises: Promise[]): Promise { - await CoreUtils.ignoreErrors(this.allPromises(promises)); + await CorePromiseUtils.allPromisesIgnoringErrors(promises); } /** @@ -251,7 +235,7 @@ export class CoreUtilsProvider { } try { - const response = await this.timeoutPromise(window.fetch(url, initOptions), CoreWS.getRequestTimeout()); + const response = await CorePromiseUtils.timeoutPromise(window.fetch(url, initOptions), CoreWS.getRequestTimeout()); return response.redirected; } catch (error) { @@ -398,35 +382,10 @@ export class CoreUtilsProvider { * Execute promises one depending on the previous. * * @param orderedPromisesData Data to be executed. - * @returns Promise resolved when all promises are resolved. + * @deprecated since 5.0 Use CorePromiseUtils.executeOrderedPromises instead. */ - executeOrderedPromises(orderedPromisesData: OrderedPromiseData[]): Promise { - const promises: Promise[] = []; - let dependency = Promise.resolve(); - - // Execute all the processes in order. - for (const i in orderedPromisesData) { - const data = orderedPromisesData[i]; - // Add the process to the dependency stack. - const promise = dependency.finally(() => { - try { - return data.function(); - } catch (e) { - this.logger.error(e.message); - - return; - } - }); - promises.push(promise); - - // If the new process is blocking, we set it as the dependency. - if (data.blocking) { - dependency = promise; - } - } - - // Return when all promises are done. - return this.allPromises(promises); + async executeOrderedPromises(orderedPromisesData: OrderedPromiseData[]): Promise { + await CorePromiseUtils.executeOrderedPromises(orderedPromisesData); } /** @@ -508,7 +467,7 @@ export class CoreUtilsProvider { } } - await CoreUtils.ignoreErrors(this.allPromises(promises)); + await CorePromiseUtils.allPromisesIgnoringErrors(promises); if (!checkAll) { // Checking 1 was enough, so it will either return all the sites or none. @@ -972,7 +931,7 @@ export class CoreUtilsProvider { return; } else if (extension === 'apk' && CorePlatform.isAndroid()) { - const url = await CoreUtils.ignoreErrors( + const url = await CorePromiseUtils.ignoreErrors( CoreFilepool.getFileUrlByPath(CoreSites.getCurrentSiteId(), CoreFile.removeBasePath(path)), ); @@ -1092,7 +1051,7 @@ export class CoreUtilsProvider { async openOnlineFile(url: string): Promise { if (CorePlatform.isAndroid()) { // In Android we need the mimetype to open it. - const mimetype = await this.ignoreErrors(this.getMimeTypeFromUrl(url)); + const mimetype = await CorePromiseUtils.ignoreErrors(this.getMimeTypeFromUrl(url)); if (!mimetype) { // Couldn't retrieve mimetype. Return error. @@ -1298,15 +1257,10 @@ export class CoreUtilsProvider { * * @param promise Promise to check * @returns Promise resolved with boolean: true if the promise is rejected or false if it's resolved. + * @deprecated since 5.0. Use CorePromiseUtils.promiseFails instead. */ async promiseFails(promise: Promise): Promise { - try { - await promise; - - return false; - } catch { - return true; - } + return CorePromiseUtils.promiseFails(promise); } /** @@ -1314,15 +1268,10 @@ export class CoreUtilsProvider { * * @param promise Promise to check * @returns Promise resolved with boolean: true if the promise it's resolved or false if it's rejected. + * @deprecated since 5.0. Use CorePromiseUtils.promiseWorks instead. */ async promiseWorks(promise: Promise): Promise { - try { - await promise; - - return true; - } catch { - return false; - } + return CorePromiseUtils.promiseWorks(promise); } /** @@ -1408,29 +1357,10 @@ export class CoreUtilsProvider { * @param promise The promise to timeout. * @param time Number of milliseconds of the timeout. * @returns Promise with the timeout. + * @deprecated since 5.0. Use CorePromiseUtils.timeoutPromise instead. */ timeoutPromise(promise: Promise, time: number): Promise { - return new Promise((resolve, reject): void => { - let timedOut = false; - const resolveBeforeTimeout = (value: T) => { - if (timedOut) { - return; - } - resolve(value); - }; - const timeout = setTimeout( - () => { - reject({ timeout: true }); - timedOut = true; - }, - time, - ); - - promise - .then(resolveBeforeTimeout) - .catch(reject) - .finally(() => clearTimeout(timeout)); - }); + return CorePromiseUtils.timeoutPromise(promise, time); } /** @@ -1584,18 +1514,16 @@ export class CoreUtilsProvider { * @param promise Promise to ignore errors. * @param fallback Value to return if the promise is rejected. * @returns Promise with ignored errors, resolving to the fallback result if provided. + * @deprecated since 5.0. Use CorePromiseUtils.ignoreErrors instead. */ async ignoreErrors(promise?: Promise): Promise; async ignoreErrors(promise: Promise, fallback: Fallback): Promise; async ignoreErrors(promise?: Promise, fallback?: Fallback): Promise { - try { - const result = await promise; - - return result; - } catch { - // Ignore errors. - return fallback; + if(promise) { + return CorePromiseUtils.ignoreErrors(promise, fallback); } + + return CorePromiseUtils.ignoreErrors(promise); } /** @@ -1659,21 +1587,6 @@ export class CoreUtilsProvider { export const CoreUtils = makeSingleton(CoreUtilsProvider); -/** - * Data for each entry of executeOrderedPromises. - */ -export type OrderedPromiseData = { - /** - * Function to execute. - */ - function: () => Promise; - - /** - * Whether the promise should block the following one. - */ - blocking?: boolean; -}; - /** * Data about a country. */ diff --git a/src/core/singletons/iab.ts b/src/core/singletons/iab.ts index 5c9aac8a8..97e5543fb 100644 --- a/src/core/singletons/iab.ts +++ b/src/core/singletons/iab.ts @@ -59,7 +59,7 @@ export class CoreInAppBrowser { /** * Open a URL using InAppBrowser. - * Do not use for files, refer to {@link CoreUtilsProvider.openFile}. + * Do not use for files, refer to CoreUtils.openFile. * * @param url The URL to open. * @param options Override default options passed to InAppBrowser. diff --git a/src/core/singletons/promise-utils.ts b/src/core/singletons/promise-utils.ts new file mode 100644 index 000000000..244da8bc8 --- /dev/null +++ b/src/core/singletons/promise-utils.ts @@ -0,0 +1,199 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { CoreLogger } from './logger'; + +/** + * Singleton with helper functions for promises. + */ +export class CorePromiseUtils { + + protected static logger = CoreLogger.getInstance('CorePromiseUtils'); + + // Avoid creating singleton instances. + private constructor() { + // Nothing to do. + } + + /** + * Similar to Promise.all, but if a promise fails this function's promise won't be rejected until ALL promises have finished. + * + * @param promises Promises. + */ + static async allPromises(promises: Promise[]): Promise { + if (!promises || !promises.length) { + return; + } + + const getPromiseError = async (promise: unknown): Promise => { + try { + await promise; + } catch (error) { + return error; + } + }; + + const errors = await Promise.all(promises.map(getPromiseError)); + const error = errors.find(error => !!error); + + if (error) { + throw error; + } + } + + /** + * Combination of allPromises and ignoreErrors functions. + * + * @param promises Promises. + */ + static async allPromisesIgnoringErrors(promises: Promise[]): Promise { + await CorePromiseUtils.ignoreErrors(CorePromiseUtils.allPromises(promises)); + } + + /** + * Execute promises one depending on the previous. + * + * @param orderedPromisesData Data to be executed. + * @returns Promise resolved when all promises are resolved. + */ + static async executeOrderedPromises(orderedPromisesData: OrderedPromiseData[]): Promise { + const promises: Promise[] = []; + let dependency = Promise.resolve(); + + // Execute all the processes in order. + for (const i in orderedPromisesData) { + const data = orderedPromisesData[i]; + // Add the process to the dependency stack. + const promise = dependency.finally(() => { + try { + return data.function(); + } catch (e) { + CorePromiseUtils.logger.error(e.message); + + return; + } + }); + promises.push(promise); + + // If the new process is blocking, we set it as the dependency. + if (data.blocking) { + dependency = promise; + } + } + + // Return when all promises are done. + await CorePromiseUtils.allPromises(promises); + } + + /** + * Ignore errors from a promise. + * + * @param promise Promise to ignore errors. + * @param fallback Value to return if the promise is rejected. + * @returns Promise with ignored errors, resolving to the fallback result if provided. + */ + static async ignoreErrors(promise?: Promise): Promise; + static async ignoreErrors(promise: Promise, fallback: Fallback): Promise; + static async ignoreErrors(promise?: Promise, fallback?: Fallback): + Promise { + try { + const result = await promise; + + return result; + } catch { + // Ignore errors. + return fallback; + } + } + + /** + * Given a promise, returns true if it's rejected or false if it's resolved. + * + * @param promise Promise to check + * @returns Promise resolved with boolean: true if the promise is rejected or false if it's resolved. + */ + static async promiseFails(promise: Promise): Promise { + try { + await promise; + + return false; + } catch { + return true; + } + } + + /** + * Given a promise, returns true if it's resolved or false if it's rejected. + * + * @param promise Promise to check + * @returns Promise resolved with boolean: true if the promise it's resolved or false if it's rejected. + */ + static async promiseWorks(promise: Promise): Promise { + try { + await promise; + + return true; + } catch { + return false; + } + } + + /** + * Set a timeout to a Promise. If the time passes before the Promise is resolved or rejected, it will be automatically + * rejected. + * + * @param promise The promise to timeout. + * @param time Number of milliseconds of the timeout. + * @returns Promise with the timeout. + */ + static timeoutPromise(promise: Promise, time: number): Promise { + return new Promise((resolve, reject): void => { + let timedOut = false; + const resolveBeforeTimeout = (value: T) => { + if (timedOut) { + return; + } + resolve(value); + }; + const timeout = setTimeout( + () => { + reject({ timeout: true }); + timedOut = true; + }, + time, + ); + + promise + .then(resolveBeforeTimeout) + .catch(reject) + .finally(() => clearTimeout(timeout)); + }); + } + +} + +/** + * Data for each entry of executeOrderedPromises. + */ +export type OrderedPromiseData = { + /** + * Function to execute. + */ + function: () => Promise; + + /** + * Whether the promise should block the following one. + */ + blocking?: boolean; +}; diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index 65371cf45..f6c7d7ed0 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -33,7 +33,7 @@ import { Swiper } from 'swiper'; import { LocalNotificationsMock } from '@features/emulator/services/local-notifications'; import { GetClosureArgs } from '@/core/utils/types'; import { CoreIframeComponent } from '@components/iframe/iframe'; -import { CoreUtils } from '@services/utils/utils'; +import { CorePromiseUtils } from '@singletons/promise-utils'; /** * Behat runtime servive with public API. @@ -888,7 +888,7 @@ export class TestingBehatRuntimeService { * @returns Promise resolved when toast has been dismissed. */ async waitToastDismiss(): Promise { - await CoreUtils.ignoreErrors(ToastController.dismiss()); + await CorePromiseUtils.ignoreErrors(ToastController.dismiss()); } }