Skip to content

Commit

Permalink
CorePromiseUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Nov 10, 2024
1 parent 4c16592 commit 3dd1b05
Show file tree
Hide file tree
Showing 263 changed files with 1,082 additions and 859 deletions.
4 changes: 2 additions & 2 deletions src/addons/badges/pages/badge-class/badge-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -81,7 +81,7 @@ export class AddonBadgesBadgeClassPage implements OnInit {
* @param refresher Refresher.
*/
async refreshBadgeClass(refresher?: HTMLIonRefresherElement): Promise<void> {
await CoreUtils.ignoreErrors(AddonBadges.invalidateBadgeClass(this.badgeId));
await CorePromiseUtils.ignoreErrors(AddonBadges.invalidateBadgeClass(this.badgeId));

await this.fetchBadgeClass();

Expand Down
6 changes: 3 additions & 3 deletions src/addons/badges/pages/issued-badge/issued-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -151,12 +151,12 @@ export class AddonBadgesIssuedBadgePage implements OnInit, OnDestroy {
* @param refresher Refresher.
*/
async refreshBadges(refresher?: HTMLIonRefresherElement): Promise<void> {
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(),
]));

Expand Down
6 changes: 3 additions & 3 deletions src/addons/badges/pages/user-badges/user-badges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -90,13 +90,13 @@ export class AddonBadgesUserBadgesPage implements AfterViewInit, OnDestroy {
* @param refresher Refresher.
*/
async refreshBadges(refresher?: HTMLIonRefresherElement): Promise<void> {
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();
}
Expand Down
3 changes: 2 additions & 1 deletion src/addons/badges/services/handlers/push-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -130,7 +131,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
promises.push(CoreCourses.invalidateCoursesByField('ids', courseIds.join(',')));
}

await CoreUtils.allPromises(promises);
await CorePromiseUtils.allPromises(promises);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/addons/block/timeline/components/timeline/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -122,7 +122,7 @@ export class AddonBlockTimelineComponent implements OnInit, ICoreBlockComponent
* @inheritdoc
*/
async invalidateContent(): Promise<void> {
await CoreUtils.allPromises([
await CorePromiseUtils.allPromises([
AddonBlockTimeline.invalidateActionEventsByTimesort(),
AddonBlockTimeline.invalidateActionEventsByCourses(),
CoreCourses.invalidateUserCourses(),
Expand Down
3 changes: 2 additions & 1 deletion src/addons/blog/pages/edit-entry/edit-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/addons/blog/pages/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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);
});

Expand All @@ -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);
});

Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/addons/blog/services/blog-offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -108,7 +108,7 @@ export class AddonBlogOfflineService {
*/
async getOfflineEntry(filter: { id?: number; created?: number }, siteId?: string): Promise<AddonBlogOfflineEntry | undefined> {
const site = await CoreSites.getSite(siteId);
const record = await CoreUtils.ignoreErrors(
const record = await CorePromiseUtils.ignoreErrors(
site.getDb().getRecord<AddonBlogOfflineEntry>(OFFLINE_BLOG_ENTRIES_TABLE_NAME, filter),
);

Expand Down
7 changes: 4 additions & 3 deletions src/addons/blog/services/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:';

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/addons/calendar/pages/edit-event/edit-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { CorePopovers } from '@services/popovers';
import { CoreLoadings } from '@services/loadings';
import { AddonCalendarEventTypeOption } from '@addons/calendar/types';
import { REMINDERS_DISABLED, CoreRemindersUnits } from '@features/reminders/constants';
import { CorePromiseUtils } from '@singletons/promise-utils';

/**
* Page that displays a form to create/edit an event.
Expand Down Expand Up @@ -165,7 +166,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,
Expand Down
4 changes: 2 additions & 2 deletions src/addons/calendar/pages/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -481,7 +481,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
}
promises.push(AddonCalendar.invalidateTimeFormat());

await CoreUtils.allPromisesIgnoringErrors(promises);
await CorePromiseUtils.allPromisesIgnoringErrors(promises);

await this.fetchEvent(sync, showErrors);
}
Expand Down
7 changes: 4 additions & 3 deletions src/addons/calendar/services/calendar-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
} from '../types';
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.
Expand Down Expand Up @@ -643,7 +644,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;
Expand All @@ -664,7 +665,7 @@ export class AddonCalendarHelperProvider {
}));

try {
await CoreUtils.allPromisesIgnoringErrors(promises);
await CorePromiseUtils.allPromisesIgnoringErrors(promises);
} finally {
const treatedMonths = {};
const treatedDays = {};
Expand Down Expand Up @@ -732,7 +733,7 @@ export class AddonCalendarHelperProvider {
}
});

await CoreUtils.allPromisesIgnoringErrors(finalPromises);
await CorePromiseUtils.allPromisesIgnoringErrors(finalPromises);
}
}

Expand Down
Loading

0 comments on commit 3dd1b05

Please sign in to comment.